Merge pull request #230 from authorizerdev/fix/github-oauth-scopes

fix: scope for github auth
This commit is contained in:
Lakhan Samani 2022-09-14 11:46:46 +05:30 committed by GitHub
commit 21b70e4b26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 7 deletions

View File

@ -287,9 +287,9 @@ func processGithubUserInfo(code string) (models.User, error) {
log.Debug("Failed to create github user info request: ", err) log.Debug("Failed to create github user info request: ", err)
return user, fmt.Errorf("error creating github user info request: %s", err.Error()) return user, fmt.Errorf("error creating github user info request: %s", err.Error())
} }
req.Header = http.Header{ req.Header.Set(
"Authorization": []string{fmt.Sprintf("token %s", oauth2Token.AccessToken)}, "Authorization", fmt.Sprintf("token %s", oauth2Token.AccessToken),
} )
response, err := client.Do(req) response, err := client.Do(req)
if err != nil { if err != nil {
@ -331,14 +331,14 @@ func processGithubUserInfo(code string) (models.User, error) {
} }
// fetch using /users/email endpoint // fetch using /users/email endpoint
req, err := http.NewRequest("GET", constants.GithubUserEmails, nil) req, err := http.NewRequest(http.MethodGet, constants.GithubUserEmails, nil)
if err != nil { if err != nil {
log.Debug("Failed to create github emails request: ", err) log.Debug("Failed to create github emails request: ", err)
return user, fmt.Errorf("error creating github user info request: %s", err.Error()) return user, fmt.Errorf("error creating github user info request: %s", err.Error())
} }
req.Header = http.Header{ req.Header.Set(
"Authorization": []string{fmt.Sprintf("token %s", oauth2Token.AccessToken)}, "Authorization", fmt.Sprintf("token %s", oauth2Token.AccessToken),
} )
response, err := client.Do(req) response, err := client.Do(req)
if err != nil { if err != nil {

View File

@ -75,6 +75,7 @@ func InitOAuth() error {
ClientSecret: githubClientSecret, ClientSecret: githubClientSecret,
RedirectURL: "/oauth_callback/github", RedirectURL: "/oauth_callback/github",
Endpoint: githubOAuth2.Endpoint, Endpoint: githubOAuth2.Endpoint,
Scopes: []string{"read:user", "user:email"},
} }
} }