MCPcopy Create free account
hub / github.com/bytebase/bytebase / NewIdentityProvider

Function NewIdentityProvider

backend/plugin/idp/oidc/oidc.go:33–62  ·  view source on GitHub ↗

NewIdentityProvider initializes a new OIDC Identity Provider with the given configuration.

(ctx context.Context, config *storepb.OIDCIdentityProviderConfig)

Source from the content-addressed store, hash-verified

31// NewIdentityProvider initializes a new OIDC Identity Provider with the given
32// configuration.
33func 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.

Callers 6

TestIdentityProviderMethod · 0.92
TestNewIdentityProviderFunction · 0.70
TestIdentityProviderFunction · 0.70

Calls 1

ErrorfMethod · 0.80

Tested by 4

TestNewIdentityProviderFunction · 0.56
TestIdentityProviderFunction · 0.56