MCPcopy Create free account
hub / github.com/supabase/auth / NewGithubProvider

Function NewGithubProvider

internal/api/provider/github.go:39–71  ·  view source on GitHub ↗

NewGithubProvider creates a Github account provider.

(ext conf.OAuthProviderConfiguration, scopes string)

Source from the content-addressed store, hash-verified

37
38// NewGithubProvider creates a Github account provider.
39func NewGithubProvider(ext conf.OAuthProviderConfiguration, scopes string) (OAuthProvider, error) {
40 if err := ext.ValidateOAuth(); err != nil {
41 return nil, err
42 }
43
44 authHost := chooseHost(ext.URL, defaultGitHubAuthBase)
45 apiHost := chooseHost(ext.URL, defaultGitHubAPIBase)
46 if !strings.HasSuffix(apiHost, defaultGitHubAPIBase) {
47 apiHost += "/api/v3"
48 }
49
50 oauthScopes := []string{
51 "user:email",
52 }
53
54 if scopes != "" {
55 oauthScopes = append(oauthScopes, strings.Split(scopes, ",")...)
56 }
57
58 return &githubProvider{
59 Config: &oauth2.Config{
60 ClientID: ext.ClientID[0],
61 ClientSecret: ext.Secret,
62 Endpoint: oauth2.Endpoint{
63 AuthURL: authHost + "/login/oauth/authorize",
64 TokenURL: authHost + "/login/oauth/access_token",
65 },
66 RedirectURL: ext.RedirectURI,
67 Scopes: oauthScopes,
68 },
69 APIHost: apiHost,
70 }, nil
71}
72
73func (g githubProvider) GetOAuthToken(ctx context.Context, code string, opts ...oauth2.AuthCodeOption) (*oauth2.Token, error) {
74 return g.Exchange(ctx, code, opts...)

Callers 1

ProviderMethod · 0.92

Calls 2

chooseHostFunction · 0.85
ValidateOAuthMethod · 0.80

Tested by

no test coverage detected