1
0
mirror of https://github.com/pocketbase/pocketbase.git synced 2025-01-09 10:07:17 +02:00

[#385] added username to the OAuth2 AuthUser model

This commit is contained in:
Gani Georgiev 2022-09-05 16:15:27 +03:00
parent b717896232
commit b79a7982bf
5 changed files with 9 additions and 1 deletions

View File

@ -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"`
}

View File

@ -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,
}

View File

@ -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,
}

View File

@ -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,
}

View File

@ -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,
}