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

Function NewIdentityProvider

backend/plugin/idp/oauth2/oauth2.go:30–53  ·  view source on GitHub ↗

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

(config *storepb.OAuth2IdentityProviderConfig)

Source from the content-addressed store, hash-verified

28
29// NewIdentityProvider initializes a new OAuth2 Identity Provider with the given configuration.
30func 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.
56func (p *IdentityProvider) ExchangeToken(ctx context.Context, redirectURL, code string) (string, error) {

Calls 1

ErrorfMethod · 0.80

Tested by 4

TestNewIdentityProviderFunction · 0.56
TestIdentityProviderFunction · 0.56