Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deezer authentication #542

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion providers/deezer/deezer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

const (
authURL string = "https://connect.deezer.com/oauth/auth.php"
tokenURL string = "https://connect.deezer.com/oauth/access_token.php"
tokenURL string = "https://connect.deezer.com/oauth/access_token.php?output=json"
endpointProfile string = "https://api.deezer.com/user/me"
)

Expand Down
12 changes: 9 additions & 3 deletions providers/deezer/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"time"

"github.com/markbates/goth"
"golang.org/x/oauth2"
)

// Session stores data during the auth process with Deezer.
Expand All @@ -28,7 +27,9 @@ func (s Session) GetAuthURL() (string, error) {
// Authorize the session with Deezer and return the access token to be stored for future use.
func (s *Session) Authorize(provider goth.Provider, params goth.Params) (string, error) {
p := provider.(*Provider)
token, err := p.config.Exchange(oauth2.NoContext, params.Get("code"))

ctx := goth.ContextForClient(p.Client())
token, err := p.config.Exchange(ctx, params.Get("code"))
if err != nil {
return "", err
}
Expand All @@ -37,8 +38,13 @@ func (s *Session) Authorize(provider goth.Provider, params goth.Params) (string,
return "", errors.New("Invalid token received from provider")
}

expires, ok := token.Extra("expires").(float64)
if ok != true {
return "", errors.New("Invalid token received from provider")
}

s.AccessToken = token.AccessToken
s.ExpiresAt = token.Expiry
s.ExpiresAt = time.Now().Add(time.Second * time.Duration(expires))
return token.AccessToken, err
}

Expand Down