NewGithubProvider creates a Github account provider.
(ext conf.OAuthProviderConfiguration)
| 35 | |
| 36 | // NewGithubProvider creates a Github account provider. |
| 37 | func NewGithubProvider(ext conf.OAuthProviderConfiguration) (OAuthProvider, error) { |
| 38 | if err := ext.Validate(); err != nil { |
| 39 | return nil, err |
| 40 | } |
| 41 | |
| 42 | authHost := chooseHost(ext.URL, defaultGitHubAuthBase) |
| 43 | apiHost := chooseHost(ext.URL, defaultGitHubApiBase) |
| 44 | if !strings.HasSuffix(apiHost, defaultGitHubApiBase) { |
| 45 | apiHost += "/api/v3" |
| 46 | } |
| 47 | |
| 48 | return &githubProvider{ |
| 49 | Config: &oauth2.Config{ |
| 50 | ClientID: ext.ClientID, |
| 51 | ClientSecret: ext.Secret, |
| 52 | Endpoint: oauth2.Endpoint{ |
| 53 | AuthURL: authHost + "/login/oauth/authorize", |
| 54 | TokenURL: authHost + "/login/oauth/access_token", |
| 55 | }, |
| 56 | RedirectURL: ext.RedirectURI, |
| 57 | Scopes: []string{"user:email"}, |
| 58 | }, |
| 59 | APIHost: apiHost, |
| 60 | }, nil |
| 61 | } |
| 62 | |
| 63 | func (g githubProvider) GetOAuthToken(code string) (*oauth2.Token, error) { |
| 64 | return g.Exchange(oauth2.NoContext, code) |
searching dependent graphs…