NewIdentityProvider initializes a new OAuth2 Identity Provider with the given configuration.
(config *storepb.OAuth2IdentityProviderConfig)
| 28 | |
| 29 | // NewIdentityProvider initializes a new OAuth2 Identity Provider with the given configuration. |
| 30 | func NewIdentityProvider(config *storepb.OAuth2IdentityProviderConfig) (*IdentityProvider, error) { |
| 31 | for v, field := range map[string]string{ |
| 32 | config.ClientId: "clientId", |
| 33 | config.ClientSecret: "clientSecret", |
| 34 | config.TokenUrl: "tokenUrl", |
| 35 | config.UserInfoUrl: "userInfoUrl", |
| 36 | config.FieldMapping.Identifier: "fieldMapping.identifier", |
| 37 | } { |
| 38 | if v == "" { |
| 39 | return nil, errors.Errorf(`the field "%s" is empty but required`, field) |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | return &IdentityProvider{ |
| 44 | client: &http.Client{ |
| 45 | Transport: &http.Transport{ |
| 46 | TLSClientConfig: &tls.Config{ |
| 47 | InsecureSkipVerify: config.SkipTlsVerify, |
| 48 | }, |
| 49 | }, |
| 50 | }, |
| 51 | config: config, |
| 52 | }, nil |
| 53 | } |
| 54 | |
| 55 | // ExchangeToken returns the exchanged OAuth2 token using the given authorization code. |
| 56 | func (p *IdentityProvider) ExchangeToken(ctx context.Context, redirectURL, code string) (string, error) { |