mirror of https://github.com/grpc/grpc-go.git
rename audience
This commit is contained in:
parent
ca129f5e97
commit
cf890d694e
|
|
@ -60,11 +60,12 @@ type Credentials interface {
|
||||||
// GetRequestMetadata gets the current request metadata, refreshing
|
// GetRequestMetadata gets the current request metadata, refreshing
|
||||||
// tokens if required. This should be called by the transport layer on
|
// tokens if required. This should be called by the transport layer on
|
||||||
// each request, and the data should be populated in headers or other
|
// each request, and the data should be populated in headers or other
|
||||||
// context. When supported by the underlying implementation, ctx can
|
// context. uri is the URI of the entry point for the request. When
|
||||||
// be used for timeout and cancellation.
|
// supported by the underlying implementation, ctx can be used for
|
||||||
|
// timeout and cancellation.
|
||||||
// TODO(zhaoq): Define the set of the qualified keys instead of leaving
|
// TODO(zhaoq): Define the set of the qualified keys instead of leaving
|
||||||
// it as an arbitrary string.
|
// it as an arbitrary string.
|
||||||
GetRequestMetadata(ctx context.Context, audience ...string) (map[string]string, error)
|
GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error)
|
||||||
// RequireTransportSecurity indicates whether the credentails requires
|
// RequireTransportSecurity indicates whether the credentails requires
|
||||||
// transport security.
|
// transport security.
|
||||||
RequireTransportSecurity() bool
|
RequireTransportSecurity() bool
|
||||||
|
|
@ -140,7 +141,7 @@ func (c tlsCreds) Info() ProtocolInfo {
|
||||||
|
|
||||||
// GetRequestMetadata returns nil, nil since TLS credentials does not have
|
// GetRequestMetadata returns nil, nil since TLS credentials does not have
|
||||||
// metadata.
|
// metadata.
|
||||||
func (c *tlsCreds) GetRequestMetadata(ctx context.Context, audience ...string) (map[string]string, error) {
|
func (c *tlsCreds) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ type TokenSource struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRequestMetadata gets the request metadata as a map from a TokenSource.
|
// GetRequestMetadata gets the request metadata as a map from a TokenSource.
|
||||||
func (ts TokenSource) GetRequestMetadata(ctx context.Context, audience ...string) (map[string]string, error) {
|
func (ts TokenSource) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
|
||||||
token, err := ts.Token()
|
token, err := ts.Token()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -81,8 +81,8 @@ func NewJWTAccessFromKey(jsonKey []byte) (credentials.Credentials, error) {
|
||||||
return jwtAccess{jsonKey}, nil
|
return jwtAccess{jsonKey}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j jwtAccess) GetRequestMetadata(ctx context.Context, audience ...string) (map[string]string, error) {
|
func (j jwtAccess) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
|
||||||
ts, err := google.JWTAccessTokenSourceFromJSON(j.jsonKey, audience[0])
|
ts, err := google.JWTAccessTokenSourceFromJSON(j.jsonKey, uri[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -109,7 +109,7 @@ func NewOauthAccess(token *oauth2.Token) credentials.Credentials {
|
||||||
return oauthAccess{token: *token}
|
return oauthAccess{token: *token}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (oa oauthAccess) GetRequestMetadata(ctx context.Context, audience ...string) (map[string]string, error) {
|
func (oa oauthAccess) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
|
||||||
return map[string]string{
|
return map[string]string{
|
||||||
"authorization": oa.token.TokenType + " " + oa.token.AccessToken,
|
"authorization": oa.token.TokenType + " " + oa.token.AccessToken,
|
||||||
}, nil
|
}, nil
|
||||||
|
|
@ -132,7 +132,7 @@ type serviceAccount struct {
|
||||||
config *jwt.Config
|
config *jwt.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s serviceAccount) GetRequestMetadata(ctx context.Context, audience ...string) (map[string]string, error) {
|
func (s serviceAccount) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
|
||||||
token, err := s.config.TokenSource(ctx).Token()
|
token, err := s.config.TokenSource(ctx).Token()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue