mirror of
https://github.com/pocketbase/pocketbase.git
synced 2025-04-24 00:30:34 +02:00
updated the oauth2 providers to use the existing oauth2 endpoints and removed the email from spotify
This commit is contained in:
parent
bac5d76725
commit
c95e50c8a5
@ -2,6 +2,7 @@ package auth
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
|
"golang.org/x/oauth2/facebook"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ Provider = (*Facebook)(nil)
|
var _ Provider = (*Facebook)(nil)
|
||||||
@ -18,8 +19,8 @@ type Facebook struct {
|
|||||||
func NewFacebookProvider() *Facebook {
|
func NewFacebookProvider() *Facebook {
|
||||||
return &Facebook{&baseProvider{
|
return &Facebook{&baseProvider{
|
||||||
scopes: []string{"email"},
|
scopes: []string{"email"},
|
||||||
authUrl: "https://www.facebook.com/dialog/oauth",
|
authUrl: facebook.Endpoint.AuthURL,
|
||||||
tokenUrl: "https://graph.facebook.com/oauth/access_token",
|
tokenUrl: facebook.Endpoint.TokenURL,
|
||||||
userApiUrl: "https://graph.facebook.com/me?fields=name,email,picture.type(large)",
|
userApiUrl: "https://graph.facebook.com/me?fields=name,email,picture.type(large)",
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
|
"golang.org/x/oauth2/github"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ Provider = (*Github)(nil)
|
var _ Provider = (*Github)(nil)
|
||||||
@ -22,8 +23,8 @@ type Github struct {
|
|||||||
func NewGithubProvider() *Github {
|
func NewGithubProvider() *Github {
|
||||||
return &Github{&baseProvider{
|
return &Github{&baseProvider{
|
||||||
scopes: []string{"read:user", "user:email"},
|
scopes: []string{"read:user", "user:email"},
|
||||||
authUrl: "https://github.com/login/oauth/authorize",
|
authUrl: github.Endpoint.AuthURL,
|
||||||
tokenUrl: "https://github.com/login/oauth/access_token",
|
tokenUrl: github.Endpoint.TokenURL,
|
||||||
userApiUrl: "https://api.github.com/user",
|
userApiUrl: "https://api.github.com/user",
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,11 @@ type Spotify struct {
|
|||||||
// NewSpotifyProvider creates a new Spotify provider instance with some defaults.
|
// NewSpotifyProvider creates a new Spotify provider instance with some defaults.
|
||||||
func NewSpotifyProvider() *Spotify {
|
func NewSpotifyProvider() *Spotify {
|
||||||
return &Spotify{&baseProvider{
|
return &Spotify{&baseProvider{
|
||||||
scopes: []string{"user-read-private", "user-read-email"},
|
scopes: []string{
|
||||||
|
"user-read-private",
|
||||||
|
// currently Spotify doesn't return information whether the email is verified or not
|
||||||
|
// "user-read-email",
|
||||||
|
},
|
||||||
authUrl: spotify.Endpoint.AuthURL,
|
authUrl: spotify.Endpoint.AuthURL,
|
||||||
tokenUrl: spotify.Endpoint.TokenURL,
|
tokenUrl: spotify.Endpoint.TokenURL,
|
||||||
userApiUrl: "https://api.spotify.com/v1/me",
|
userApiUrl: "https://api.spotify.com/v1/me",
|
||||||
@ -31,10 +35,13 @@ func (p *Spotify) FetchAuthUser(token *oauth2.Token) (*AuthUser, error) {
|
|||||||
rawData := struct {
|
rawData := struct {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
Name string `json:"display_name"`
|
Name string `json:"display_name"`
|
||||||
Email string `json:"email"`
|
|
||||||
Images []struct {
|
Images []struct {
|
||||||
Url string `json:"url"`
|
Url string `json:"url"`
|
||||||
} `json:"images"`
|
} `json:"images"`
|
||||||
|
// don't map the email because per the official docs
|
||||||
|
// the email field is "unverified" and there is no proof
|
||||||
|
// that it actually belongs to the user
|
||||||
|
// Email string `json:"email"`
|
||||||
}{}
|
}{}
|
||||||
|
|
||||||
if err := p.FetchRawUserData(token, &rawData); err != nil {
|
if err := p.FetchRawUserData(token, &rawData); err != nil {
|
||||||
@ -44,7 +51,6 @@ func (p *Spotify) FetchAuthUser(token *oauth2.Token) (*AuthUser, error) {
|
|||||||
user := &AuthUser{
|
user := &AuthUser{
|
||||||
Id: rawData.Id,
|
Id: rawData.Id,
|
||||||
Name: rawData.Name,
|
Name: rawData.Name,
|
||||||
Email: rawData.Email,
|
|
||||||
}
|
}
|
||||||
if len(rawData.Images) > 0 {
|
if len(rawData.Images) > 0 {
|
||||||
user.AvatarUrl = rawData.Images[0].Url
|
user.AvatarUrl = rawData.Images[0].Url
|
||||||
|
Loading…
x
Reference in New Issue
Block a user