Documentation
¶
Index ¶
- func BuildAuthURL(port int, state, codeChallenge, dpopJKT string) string
- func ExchangeCode(client *http.Client, code, codeVerifier string, port int, dpopKey *DPoPKey) (*config.TokenData, error)
- func ExtractCodeFromURL(rawURL, expectedState string) (string, error)
- func GenerateCodeChallenge(verifier string) string
- func GenerateCodeVerifier() (string, error)
- func GenerateState() (string, error)
- func OpenBrowser(url string) error
- func RefreshAccessToken(client *http.Client, refreshToken string, dpopKey *DPoPKey) (*config.TokenData, error)
- func StartCallbackServer(port int, expectedState string) (*http.Server, <-chan CallbackResult, error)
- type CallbackResult
- type DPoPKey
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildAuthURL ¶
BuildAuthURL constructs the Spotify authorization URL with PKCE params. dpopJKT is the JWK SHA-256 thumbprint that binds the authorization code to the DPoP key.
func ExchangeCode ¶
func ExchangeCode(client *http.Client, code, codeVerifier string, port int, dpopKey *DPoPKey) (*config.TokenData, error)
ExchangeCode exchanges an authorization code for tokens using PKCE. If dpopKey is non-nil, a DPoP proof is included in the token request.
func ExtractCodeFromURL ¶
ExtractCodeFromURL parses an authorization code from a pasted redirect URL and validates the state parameter for CSRF protection.
func GenerateCodeChallenge ¶
GenerateCodeChallenge derives the S256 code challenge from a verifier.
func GenerateCodeVerifier ¶
GenerateCodeVerifier creates a cryptographically random PKCE code verifier. Length is between 43-128 characters per RFC 7636.
func GenerateState ¶
GenerateState creates a random state parameter for CSRF protection.
func OpenBrowser ¶
OpenBrowser attempts to open a URL in the default browser. Returns an error if it can't (e.g., headless server).
func RefreshAccessToken ¶
func RefreshAccessToken(client *http.Client, refreshToken string, dpopKey *DPoPKey) (*config.TokenData, error)
RefreshAccessToken uses a refresh token to get a new access token. If dpopKey is non-nil, a DPoP proof is included in the token request.
func StartCallbackServer ¶
func StartCallbackServer(port int, expectedState string) (*http.Server, <-chan CallbackResult, error)
StartCallbackServer starts a temporary HTTP server to receive the OAuth callback. It returns the server, a channel that receives the callback result, and any error.
Types ¶
type CallbackResult ¶
CallbackResult is sent through the channel from the local HTTP callback handler.
func WaitForCallback ¶
func WaitForCallback(srv *http.Server, resultCh <-chan CallbackResult, timeout time.Duration) (*CallbackResult, error)
WaitForCallback waits for the callback result with a timeout.
type DPoPKey ¶
type DPoPKey struct {
PrivateKey *ecdsa.PrivateKey
}
DPoPKey holds an ECDSA P-256 key pair for DPoP proof-of-possession (RFC 9449).
func GenerateDPoPKey ¶
GenerateDPoPKey creates a new ECDSA P-256 key pair for DPoP.
func UnmarshalDPoPKey ¶
UnmarshalDPoPKey deserializes a DPoP key pair from its JSON representation.
func (*DPoPKey) CreateProof ¶
CreateProof generates a DPoP proof JWT for the given HTTP method and URL. nonce is included when non-empty (for server-provided DPoP-Nonce).
func (*DPoPKey) MarshalJSON ¶
MarshalJSON serializes the full key pair (including private key) for persistence.
func (*DPoPKey) Thumbprint ¶
Thumbprint returns the base64url-encoded SHA-256 JWK Thumbprint (RFC 7638).