Skip to content

Commit 1a48a9a

Browse files
authored
Fix deezer authentication (#542)
1 parent 172172b commit 1a48a9a

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

providers/deezer/deezer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919

2020
const (
2121
authURL string = "https://connect.deezer.com/oauth/auth.php"
22-
tokenURL string = "https://connect.deezer.com/oauth/access_token.php"
22+
tokenURL string = "https://connect.deezer.com/oauth/access_token.php?output=json"
2323
endpointProfile string = "https://api.deezer.com/user/me"
2424
)
2525

providers/deezer/session.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"time"
88

99
"github.com/markbates/goth"
10-
"golang.org/x/oauth2"
1110
)
1211

1312
// Session stores data during the auth process with Deezer.
@@ -28,7 +27,9 @@ func (s Session) GetAuthURL() (string, error) {
2827
// Authorize the session with Deezer and return the access token to be stored for future use.
2928
func (s *Session) Authorize(provider goth.Provider, params goth.Params) (string, error) {
3029
p := provider.(*Provider)
31-
token, err := p.config.Exchange(oauth2.NoContext, params.Get("code"))
30+
31+
ctx := goth.ContextForClient(p.Client())
32+
token, err := p.config.Exchange(ctx, params.Get("code"))
3233
if err != nil {
3334
return "", err
3435
}
@@ -37,8 +38,13 @@ func (s *Session) Authorize(provider goth.Provider, params goth.Params) (string,
3738
return "", errors.New("Invalid token received from provider")
3839
}
3940

41+
expires, ok := token.Extra("expires").(float64)
42+
if ok != true {
43+
return "", errors.New("Invalid token received from provider")
44+
}
45+
4046
s.AccessToken = token.AccessToken
41-
s.ExpiresAt = token.Expiry
47+
s.ExpiresAt = time.Now().Add(time.Second * time.Duration(expires))
4248
return token.AccessToken, err
4349
}
4450

0 commit comments

Comments
 (0)