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

Method ExchangeToken

backend/plugin/idp/oidc/oidc.go:66–89  ·  view source on GitHub ↗

ExchangeToken returns the exchanged OAuth2 token using the given redirect URL and authorization code.

(ctx context.Context, redirectURL, code string)

Source from the content-addressed store, hash-verified

64// ExchangeToken returns the exchanged OAuth2 token using the given redirect
65// URL and authorization code.
66func (p *IdentityProvider) ExchangeToken(ctx context.Context, redirectURL, code string) (*oauth2.Token, error) {
67 oauth2Config := oauth2.Config{
68 ClientID: p.config.ClientId,
69 ClientSecret: p.config.ClientSecret,
70 RedirectURL: redirectURL,
71
72 // Discovery returns the OAuth2 endpoints.
73 Endpoint: p.provider.Endpoint(),
74 Scopes: p.config.Scopes,
75 }
76
77 authStyle := oauth2.AuthStyleInParams
78 if p.config.AuthStyle == storepb.OAuth2AuthStyle_IN_HEADER {
79 authStyle = oauth2.AuthStyleInHeader
80 }
81 oauth2Config.Endpoint.AuthStyle = authStyle
82
83 ctx = context.WithValue(ctx, oauth2.HTTPClient, p.client)
84 token, err := oauth2Config.Exchange(ctx, code)
85 if err != nil {
86 return nil, errors.Wrap(err, "exchange token")
87 }
88 return token, nil
89}
90
91// UserInfo returns the parsed user information using the given OAuth2 token.
92// The nonce is used for request validation, which should be the same value as

Callers 5

TestIdentityProviderFunction · 0.95
TestIdentityProviderMethod · 0.95

Calls

no outgoing calls

Tested by 3

TestIdentityProviderFunction · 0.76