Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.11.17 breaks PKCE auth #419

Closed
jacobmichels opened this issue May 30, 2023 · 1 comment
Closed

0.11.17 breaks PKCE auth #419

jacobmichels opened this issue May 30, 2023 · 1 comment
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@jacobmichels
Copy link
Contributor

Describe the bug
prompt_for_token panics after inputting the redirect url from the browser. The logs reveals that the http client sent a request to /api/token but received a 400 response. The response body states that the code_verifier was not correct. This issue is not present in 0.11.6 or 0.11.5.

To Reproduce
Steps to reproduce the behavior:

  1. Checkout rspotify v0.11.7
  2. Run the auth_code_pkce example.
  3. Observe a panic after pasting in the redirect url

Expected behavior
prompt_for_token correctly formulates the request for the access token as it does before v0.11.7

Log/Output data

$ RSPOTIFY_CLIENT_ID=... RSPOTIFY_CLIENT_SECRET=... RSPOTIFY_REDIRECT_URI='http://localhost:8000/callback' cargo run --features="env-file cli client-reqwest" --example auth_code_pkce
     Finished dev [unoptimized + debuginfo] target(s) in 0.08s
     Running `target/debug/examples/auth_code_pkce`
Opened https://accounts.spotify.com/authorize?client_id=...&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2Fcallback&code_challenge_method=S256&code_challenge=lwVEozlFwPIHbPZtH8ohjISa%2BlW%2BU%2BTER9nt1o5SYBU%3D&state=7XmghTMdx6xQZXW7&scope=user-read-playback-state in your browser.
Please enter the URL you were redirected to: 
http://localhost:8000/callback?code=AQCJPjYPRU6_A3fnQkI5osldxE9En9uDaweca8LpXc_oOr0P_8bd0ADz3cANdohdkLmcMebzGk9qx8WbVPvExmHNfJe3tkNCdM7CCeuQdg6D0kqMCrqHgEzNNSuNfWB4r5O6PDdst8MbSP2vffKmriJLZtCgt-5-wDyddmq0ozMushoM_2T0Z1NRSz2V38iNnMS1BY6uVYuTcvR3zPJA3uF3Iqv3z81iWUuIM8lIFIKyhXliTNIDw56pBbRZOT9JnZWlfuxUhAXq2xxIpzvKgQ&state=7XmghTMdx6xQZXW7
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Http(StatusCode(Response { url: Url { scheme: "https", cannot_be_a_base: false, username: "", password: None, host: Some(Domain("accounts.spotify.com")), port: None, path: "/api/token", query: None, fragment: None }, status: 400, headers: {"date": "Tue, 30 May 2023 18:39:43 GMT", "content-type": "application/json", "content-length": "75", "set-cookie": "__Host-device_id=AQDm2oUnpI2bQJsUx5B9NcaiiXOON6Ff23pTiixPq2Gx9j_-OxxVmG6nnG29qnOXfjSUH7Qr02IWgRUUYbyt2l3FaV3gy9Unklk;Version=1;Path=/;Max-Age=2147483647;Secure;HttpOnly;SameSite=Lax", "set-cookie": "sp_tr=false;Version=1;Domain=accounts.spotify.com;Path=/;Secure;SameSite=Lax", "sp-trace-id": "b305149cf06b8b8e", "x-envoy-upstream-service-time": "18", "server": "envoy", "strict-transport-security": "max-age=31536000", "x-content-type-options": "nosniff", "vary": "Accept-Encoding", "via": "HTTP/2 edgeproxy, 1.1 google", "alt-svc": "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000"} }))', examples/auth_code_pkce.rs:38:42
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace```
@jacobmichels jacobmichels added bug Something isn't working help wanted Extra attention is needed labels May 30, 2023
@jacobmichels
Copy link
Contributor Author

jacobmichels commented May 30, 2023

I think I found the issue. In auth_code_pkre.rs

let challenge = base64::encode(challenge);

The challenge code is being encoded as plain base64 when it should be encoded as base64url safe. I believe this bug was introduced when the base64 dependency had its version bumped from 0.13 to 0.20 in this commit. I'll open a PR to fix this

@jacobmichels jacobmichels mentioned this issue May 30, 2023
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant