NewIdentityProvider initializes a new OIDC Identity Provider with the given configuration.
(ctx context.Context, config *storepb.OIDCIdentityProviderConfig)
| 31 | // NewIdentityProvider initializes a new OIDC Identity Provider with the given |
| 32 | // configuration. |
| 33 | func NewIdentityProvider(ctx context.Context, config *storepb.OIDCIdentityProviderConfig) (*IdentityProvider, error) { |
| 34 | for v, field := range map[string]string{ |
| 35 | config.Issuer: "issuer", |
| 36 | config.ClientId: "clientId", |
| 37 | config.ClientSecret: "clientSecret", |
| 38 | config.FieldMapping.Identifier: "fieldMapping.identifier", |
| 39 | } { |
| 40 | if v == "" { |
| 41 | return nil, errors.Errorf("the field %q is empty but required", field) |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | client := &http.Client{ |
| 46 | Transport: &http.Transport{ |
| 47 | TLSClientConfig: &tls.Config{ |
| 48 | InsecureSkipVerify: config.SkipTlsVerify, |
| 49 | }, |
| 50 | }, |
| 51 | } |
| 52 | ctx = context.WithValue(ctx, oauth2.HTTPClient, client) |
| 53 | p, err := oidc.NewProvider(ctx, config.Issuer) |
| 54 | if err != nil { |
| 55 | return nil, errors.Wrap(err, "create new provider") |
| 56 | } |
| 57 | return &IdentityProvider{ |
| 58 | client: client, |
| 59 | provider: p, |
| 60 | config: config, |
| 61 | }, nil |
| 62 | } |
| 63 | |
| 64 | // ExchangeToken returns the exchanged OAuth2 token using the given redirect |
| 65 | // URL and authorization code. |