| 34 | const offlineAccessScope = "offline_access" |
| 35 | |
| 36 | func (a OAuthAuthenticator) Auth(ctx AuthenticatorContext) AuthenticatorResult { |
| 37 | if !a.enabled(ctx) { |
| 38 | return *AuthenticatorSuccess(nil) |
| 39 | } |
| 40 | config, err := a.getConfig(ctx) |
| 41 | if err != nil { |
| 42 | return *AuthenticatorError(fmt.Errorf("Invalid oauth authenticator configuration: %w", err)) |
| 43 | } |
| 44 | token, err := a.retrieveToken(*config, ctx) |
| 45 | if err != nil { |
| 46 | return *AuthenticatorError(fmt.Errorf("Error retrieving access token: %w", err)) |
| 47 | } |
| 48 | return *AuthenticatorSuccess(NewBearerToken(token)) |
| 49 | } |
| 50 | |
| 51 | func (a OAuthAuthenticator) retrieveToken(config oauthAuthenticatorConfig, ctx AuthenticatorContext) (string, error) { |
| 52 | tokenResponse := a.getAccessTokenFromCache(config) |