Skip to content

Commit

Permalink
Fix deezer authentication (#542)
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonymq committed Mar 11, 2024
1 parent 172172b commit 1a48a9a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion providers/deezer/deezer.go
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
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

0 comments on commit 1a48a9a

Please sign in to comment.