Example #1
0
func NewJWTAccessFromKey(jsonKey []byte, audience string) (credentials.Credentials, error) {
	ts, err := google.JWTAccessTokenSourceFromJSON(jsonKey, audience)
	if err != nil {
		return nil, err
	}
	return jwtAccess{ts: ts}, nil
}
Example #2
0
func (j jwtAccess) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
	ts, err := google.JWTAccessTokenSourceFromJSON(j.jsonKey, uri[0])
	if err != nil {
		return nil, err
	}
	token, err := ts.Token()
	if err != nil {
		return nil, err
	}
	return map[string]string{
		"authorization": token.TokenType + " " + token.AccessToken,
	}, nil
}