Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"net/http"
"net/url"
"os"

"golang.org/x/oauth2"
Expand Down Expand Up @@ -152,11 +153,11 @@ func (a Authenticator) AuthURL(state string, opts ...oauth2.AuthCodeOption) stri
return a.config.AuthCodeURL(state, opts...)
}

// Token pulls an authorization code from an HTTP request and attempts to exchange
// Token pulls an authorization code from a redirected URL and attempts to exchange
// it for an access token. The standard use case is to call Token from the handler
// that handles requests to your application's redirect URL.
func (a Authenticator) Token(ctx context.Context, state string, r *http.Request, opts ...oauth2.AuthCodeOption) (*oauth2.Token, error) {
values := r.URL.Query()
func (a Authenticator) Token(ctx context.Context, state string, redirect *url.URL, opts ...oauth2.AuthCodeOption) (*oauth2.Token, error) {
values := redirect.Query()
if e := values.Get("error"); e != "" {
return nil, errors.New("spotify: auth failed - " + e)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/authenticate/authcode/authenticate.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func main() {
}

func completeAuth(w http.ResponseWriter, r *http.Request) {
tok, err := auth.Token(r.Context(), state, r)
tok, err := auth.Token(r.Context(), state, r.URL)
if err != nil {
http.Error(w, "Couldn't get token", http.StatusForbidden)
log.Fatal(err)
Expand Down
2 changes: 1 addition & 1 deletion examples/authenticate/pkce/pkce.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func main() {
}

func completeAuth(w http.ResponseWriter, r *http.Request) {
tok, err := auth.Token(r.Context(), state, r,
tok, err := auth.Token(r.Context(), state, r.URL,
oauth2.SetAuthURLParam("code_verifier", codeVerifier))
if err != nil {
http.Error(w, "Couldn't get token", http.StatusForbidden)
Expand Down
2 changes: 1 addition & 1 deletion examples/player/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func main() {
}

func completeAuth(w http.ResponseWriter, r *http.Request) {
tok, err := auth.Token(r.Context(), state, r)
tok, err := auth.Token(r.Context(), state, r.URL)
if err != nil {
http.Error(w, "Couldn't get token", http.StatusForbidden)
log.Fatal(err)
Expand Down