From b79a7982bf29c274036f3d0d226a45dd4e62cca1 Mon Sep 17 00:00:00 2001 From: Gani Georgiev Date: Mon, 5 Sep 2022 16:15:27 +0300 Subject: [PATCH] [#385] added username to the OAuth2 AuthUser model --- tools/auth/auth.go | 1 + tools/auth/discord.go | 1 + tools/auth/github.go | 2 ++ tools/auth/gitlab.go | 2 ++ tools/auth/twitter.go | 4 +++- 5 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/auth/auth.go b/tools/auth/auth.go index 2b6b1b0c..469db7a2 100644 --- a/tools/auth/auth.go +++ b/tools/auth/auth.go @@ -11,6 +11,7 @@ import ( type AuthUser struct { Id string `json:"id"` Name string `json:"name"` + Username string `json:"username"` Email string `json:"email"` AvatarUrl string `json:"avatarUrl"` } diff --git a/tools/auth/discord.go b/tools/auth/discord.go index 7b4988fb..be52d7f3 100644 --- a/tools/auth/discord.go +++ b/tools/auth/discord.go @@ -53,6 +53,7 @@ func (p *Discord) FetchAuthUser(token *oauth2.Token) (*AuthUser, error) { user := &AuthUser{ Id: rawData.Id, Name: username, + Username: rawData.Username, Email: rawData.Email, AvatarUrl: avatarUrl, } diff --git a/tools/auth/github.go b/tools/auth/github.go index 52bc965d..9ec55c19 100644 --- a/tools/auth/github.go +++ b/tools/auth/github.go @@ -32,6 +32,7 @@ func NewGithubProvider() *Github { func (p *Github) FetchAuthUser(token *oauth2.Token) (*AuthUser, error) { // https://docs.github.com/en/rest/reference/users#get-the-authenticated-user rawData := struct { + Login string `json:"login"` Id int `json:"id"` Name string `json:"name"` Email string `json:"email"` @@ -45,6 +46,7 @@ func (p *Github) FetchAuthUser(token *oauth2.Token) (*AuthUser, error) { user := &AuthUser{ Id: strconv.Itoa(rawData.Id), Name: rawData.Name, + Username: rawData.Login, Email: rawData.Email, AvatarUrl: rawData.AvatarUrl, } diff --git a/tools/auth/gitlab.go b/tools/auth/gitlab.go index 080bb8e9..4700a78d 100644 --- a/tools/auth/gitlab.go +++ b/tools/auth/gitlab.go @@ -32,6 +32,7 @@ func (p *Gitlab) FetchAuthUser(token *oauth2.Token) (*AuthUser, error) { rawData := struct { Id int `json:"id"` Name string `json:"name"` + Username string `json:"username"` Email string `json:"email"` AvatarUrl string `json:"avatar_url"` }{} @@ -43,6 +44,7 @@ func (p *Gitlab) FetchAuthUser(token *oauth2.Token) (*AuthUser, error) { user := &AuthUser{ Id: strconv.Itoa(rawData.Id), Name: rawData.Name, + Username: rawData.Username, Email: rawData.Email, AvatarUrl: rawData.AvatarUrl, } diff --git a/tools/auth/twitter.go b/tools/auth/twitter.go index d3d88cd0..c1128aff 100644 --- a/tools/auth/twitter.go +++ b/tools/auth/twitter.go @@ -26,7 +26,7 @@ func NewTwitterProvider() *Twitter { }, authUrl: "https://twitter.com/i/oauth2/authorize", tokenUrl: "https://api.twitter.com/2/oauth2/token", - userApiUrl: "https://api.twitter.com/2/users/me?user.fields=id,name,profile_image_url", + userApiUrl: "https://api.twitter.com/2/users/me?user.fields=id,name,username,profile_image_url", }} } @@ -37,6 +37,7 @@ func (p *Twitter) FetchAuthUser(token *oauth2.Token) (*AuthUser, error) { Data struct { Id string `json:"id"` Name string `json:"name"` + Username string `json:"username"` ProfileImageUrl string `json:"profile_image_url"` // NB! At the time of writing, Twitter OAuth2 doesn't support returning the user email address @@ -52,6 +53,7 @@ func (p *Twitter) FetchAuthUser(token *oauth2.Token) (*AuthUser, error) { user := &AuthUser{ Id: rawData.Data.Id, Name: rawData.Data.Name, + Username: rawData.Data.Username, Email: rawData.Data.Email, AvatarUrl: rawData.Data.ProfileImageUrl, }