Source File
oauth.go
Belonging Package
google.golang.org/grpc/credentials/oauth
package oauth
import (
)
type TokenSource struct {
oauth2.TokenSource
}
func ( TokenSource) ( context.Context, ...string) (map[string]string, error) {
, := .Token()
if != nil {
return nil,
}
if = credentials.CheckSecurityLevel(, credentials.PrivacyAndIntegrity); != nil {
return nil, fmt.Errorf("unable to transfer TokenSource PerRPCCredentials: %v", )
}
return map[string]string{
"authorization": .Type() + " " + .AccessToken,
}, nil
}
func ( string) (credentials.PerRPCCredentials, error) {
, := ioutil.ReadFile()
if != nil {
return nil, fmt.Errorf("credentials: failed to read the service account key file: %v", )
}
return NewJWTAccessFromKey()
}
func ( []byte) (credentials.PerRPCCredentials, error) {
return jwtAccess{}, nil
}
, := google.JWTAccessTokenSourceFromJSON(.jsonKey, [0])
if != nil {
return nil,
}
, := .Token()
if != nil {
return nil,
}
if = credentials.CheckSecurityLevel(, credentials.PrivacyAndIntegrity); != nil {
return nil, fmt.Errorf("unable to transfer jwtAccess PerRPCCredentials: %v", )
}
return map[string]string{
"authorization": .Type() + " " + .AccessToken,
}, nil
}
func ( jwtAccess) () bool {
return true
}
type oauthAccess struct {
token oauth2.Token
}
func ( *oauth2.Token) credentials.PerRPCCredentials {
return oauthAccess{token: *}
}
func ( oauthAccess) ( context.Context, ...string) (map[string]string, error) {
if := credentials.CheckSecurityLevel(, credentials.PrivacyAndIntegrity); != nil {
return nil, fmt.Errorf("unable to transfer oauthAccess PerRPCCredentials: %v", )
}
return map[string]string{
"authorization": .token.Type() + " " + .token.AccessToken,
}, nil
}
func ( oauthAccess) () bool {
return true
}
func () credentials.PerRPCCredentials {
return TokenSource{google.ComputeTokenSource("")}
}
type serviceAccount struct {
mu sync.Mutex
config *jwt.Config
t *oauth2.Token
}
func ( *serviceAccount) ( context.Context, ...string) (map[string]string, error) {
.mu.Lock()
defer .mu.Unlock()
if !.t.Valid() {
var error
.t, = .config.TokenSource().Token()
if != nil {
return nil,
}
}
if := credentials.CheckSecurityLevel(, credentials.PrivacyAndIntegrity); != nil {
return nil, fmt.Errorf("unable to transfer serviceAccount PerRPCCredentials: %v", )
}
return map[string]string{
"authorization": .t.Type() + " " + .t.AccessToken,
}, nil
}
func ( *serviceAccount) () bool {
return true
}
func ( []byte, ...string) (credentials.PerRPCCredentials, error) {
, := google.JWTConfigFromJSON(, ...)
if != nil {
return nil,
}
return &serviceAccount{config: }, nil
}
func ( string, ...string) (credentials.PerRPCCredentials, error) {
, := ioutil.ReadFile()
if != nil {
return nil, fmt.Errorf("credentials: failed to read the service account key file: %v", )
}
return NewServiceAccountFromKey(, ...)
}
func ( context.Context, ...string) (credentials.PerRPCCredentials, error) {
, := google.FindDefaultCredentials(, ...)
if != nil {
return nil,
}
if .JSON == nil {
return TokenSource{.TokenSource}, nil
}
if len() != 0 {
return TokenSource{.TokenSource}, nil
}
return TokenSource{.TokenSource}, nil
}
return NewJWTAccessFromKey(.JSON)
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |