Skip to content

Commit

Permalink
fix(oidc): parse right claims for GitHub authentication
Browse files Browse the repository at this point in the history
Before this change the authentication via GitHub always errored out within getProfileNameFromEmail because the rune list had a zero length, after my investigation I have been able to pin it down to a lacking email address fetched from the GitHub provider.

Since there are various claims like the username, email and fullname which aren't part of the generated claims I have added a switch to properly read all relevant information from the right claims within the GitHub provider.

This commit is still lacking proper error display on the login page, but this should be added on another commit in general.
  • Loading branch information
tboerger committed Jan 31, 2024
1 parent f23cab1 commit c4aaf29
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions api/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,13 +475,38 @@ func oidcRedirect(w http.ResponseWriter, r *http.Request) {
userInfo, err = _oidc.UserInfo(ctx, oauth2.StaticTokenSource(oauth2Token))

if err == nil {
claims.email = userInfo.Email
claims.username = getRandomUsername()

if userInfo.Profile != "" {
claims.name = userInfo.Profile
} else {
claims.name = getRandomProfileName()
switch pid {
case "github":
type githubClaims struct {
Login string `json:"login"`
Email string `json:"email"`
Name string `json:"name"`
}

var rawClaims githubClaims

if err := userInfo.Claims(&rawClaims); err != nil {
log.Error(err.Error())
http.Redirect(w, r, "/auth/login", http.StatusTemporaryRedirect)
return
}

claims.email = rawClaims.Email
claims.username = rawClaims.Login
claims.name = rawClaims.Name

if claims.email == "" {
claims.email = fmt.Sprintf("%[email protected]", rawClaims.Login)
}
default:
claims.email = userInfo.Email
claims.username = getRandomUsername()

if userInfo.Profile != "" {
claims.name = userInfo.Profile
} else {
claims.name = getRandomProfileName()
}
}
}
}
Expand Down

0 comments on commit c4aaf29

Please sign in to comment.