Skip to content

Commit

Permalink
Merge pull request #179 from StalkR/unbreak-proxy-support
Browse files Browse the repository at this point in the history
auth: remove contextwithHTTPClient
  • Loading branch information
strideynet authored Dec 27, 2021
2 parents 40fdc53 + 6d24f9f commit 1543b59
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package spotifyauth

import (
"context"
"crypto/tls"
"errors"
"net/http"
"os"
Expand Down Expand Up @@ -140,17 +139,6 @@ func New(opts ...AuthenticatorOption) *Authenticator {
return a
}

// contextWithHTTPClient returns a context with a value set to override the oauth2 http client as Spotify does not
// support HTTP/2
//
// see: https://github.com/zmb3/spotify/issues/20
func contextWithHTTPClient(ctx context.Context) context.Context {
tr := &http.Transport{
TLSNextProto: map[string]func(authority string, c *tls.Conn) http.RoundTripper{},
}
return context.WithValue(ctx, oauth2.HTTPClient, &http.Client{Transport: tr})
}

// ShowDialog forces the user to approve the app, even if they have already done so.
// Without this, users who have already approved the app are immediately redirected to the redirect uri.
var ShowDialog = oauth2.SetAuthURLParam("show_dialog", "true")
Expand Down Expand Up @@ -180,17 +168,17 @@ func (a Authenticator) Token(ctx context.Context, state string, r *http.Request,
if actualState != state {
return nil, errors.New("spotify: redirect state parameter doesn't match")
}
return a.config.Exchange(contextWithHTTPClient(ctx), code, opts...)
return a.config.Exchange(ctx, code, opts...)
}

// Exchange is like Token, except it allows you to manually specify the access
// code instead of pulling it out of an HTTP request.
func (a Authenticator) Exchange(ctx context.Context, code string, opts ...oauth2.AuthCodeOption) (*oauth2.Token, error) {
return a.config.Exchange(contextWithHTTPClient(ctx), code, opts...)
return a.config.Exchange(ctx, code, opts...)
}

// Client creates a *http.Client that will use the specified access token for its API requests.
// Combine this with spotify.HTTPClientOpt.
func (a Authenticator) Client(ctx context.Context, token *oauth2.Token) *http.Client {
return a.config.Client(contextWithHTTPClient(ctx), token)
return a.config.Client(ctx, token)
}

0 comments on commit 1543b59

Please sign in to comment.