Created
October 27, 2016 15:03
-
-
Save EmilGeorgiev/94908db265110d9d32acf2adfbc3d380 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Oauth2Config is wrapper of oauth2.Config struct. | |
| type Oauth2Config interface { | |
| // AuthCodeURL returns a URL to OAuth 2.0 provider's consent page that asks for permissions | |
| AuthCodeURL(state string) string | |
| // Exchange converts an authorization code into a token. | |
| Exchange(ctx context.Context, code string) (*oauth2.Token, error) | |
| // RefreshToken refresh expired access token. It return new oauth2.Token or an error | |
| RefreshToken(ctx context.Context, t *oauth2.Token) (*oauth2.Token, error) | |
| } | |
| type backendOauth2Config struct { | |
| config *oauth2.Config | |
| } | |
| // NewOauth2Config return and initialize Oauth2Config | |
| func NewOauth2Config(config *oauth2.Config) Oauth2Config { | |
| return &backendOauth2Config{config} | |
| } | |
| func (c *backendOauth2Config) AuthCodeURL(state string) string { | |
| return c.config.AuthCodeURL(state) | |
| } | |
| func (c *backendOauth2Config) Exchange(ctx context.Context, code string) (*oauth2.Token, error) { | |
| return c.config.Exchange(ctx, code) | |
| } | |
| func (c *backendOauth2Config) RefreshToken(ctx context.Context, t *oauth2.Token) (*oauth2.Token, error) { | |
| ts := c.config.TokenSource(ctx, t) | |
| return ts.Token() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment