<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Auth attempts all return &amp;quot;code_verifier required&amp;quot; when using non-PKCE auth between iOS and Web in Spotify for Developers</title>
    <link>https://community.spotify.com/t5/Spotify-for-Developers/Auth-attempts-all-return-quot-code-verifier-required-quot-when/m-p/6084903#M13983</link>
    <description>&lt;P&gt;&lt;STRONG&gt;Plan&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Free/Premium&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Country&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;USA&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Device&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;iPhone XR&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Operating System&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;iOS 17.4.1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My Question or Issue&lt;/STRONG&gt;&lt;/P&gt;&lt;P class=""&gt;I'm trying to authenticate using non-PKCE between Spotify iOS SDK and Web API. Every time I try to exchange the auth code for tokens, I get a 400 error and the body&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;PRE&gt;{"error":"invalid_request","error_description":"code_verifier required"}&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P class=""&gt;. However, &lt;A href="https://developer.spotify.com/documentation/web-api/tutorials/code-flow" target="_self"&gt;according to the non-PKCE docs&lt;/A&gt;, no code_verifier should be included. My flow is:&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;&lt;P class=""&gt;1. Use my iOS app and Spotify iOS SDK + Spotify app installed to retrieve the authorization code.&lt;/P&gt;&lt;P class=""&gt;2. Pass that code to my service backend to exchange it for the OAuth tokens (refresh and access).&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;&lt;P class=""&gt;Swift&lt;/P&gt;&lt;P class=""&gt;```&lt;/P&gt;&lt;P class=""&gt;// Create a SPTSessionManager&lt;/P&gt;&lt;P class=""&gt;let sessionManager = …&lt;/P&gt;&lt;P class=""&gt;sessionManager?.initiateSession(with: scopes, options: .default)&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;&lt;P class=""&gt;// In my AppDelegate URL processing callback&lt;/P&gt;&lt;P class=""&gt;guard let appRemote = appRemote else { return }&lt;/P&gt;&lt;P class=""&gt;guard let parameters = appRemote.authorizationParameters(from: url) else { return }&lt;/P&gt;&lt;P class=""&gt;guard let access_code = parameters["code"] else { return }&lt;/P&gt;&lt;P class=""&gt;logger.info("Spotify Access Code: \(String(describing: access_code))")&lt;/P&gt;&lt;P class=""&gt;```&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;&lt;P class=""&gt;All this works, and I see an access code.&lt;SPAN class=""&gt;&amp;nbsp; &lt;/SPAN&gt;I then pass that code to my Node.js backend to exchange the code for tokens and store the tokens (so I can make Web API calls later). The called URL is `&lt;A href="https://accounts.spotify.com/api/token" target="_blank" rel="noopener"&gt;https://accounts.spotify.com/api/token&lt;/A&gt;`.&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;&lt;P class=""&gt;```&lt;/P&gt;&lt;P class=""&gt;logger.info('Exchanging code for tokens');&lt;/P&gt;&lt;P class=""&gt;const encodedCredentials = this.encodeClientCredentials({&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &lt;/SPAN&gt;clientId: this.clientId,&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &lt;/SPAN&gt;clientSecret: this.clientSecret,&lt;/P&gt;&lt;P class=""&gt;});&lt;/P&gt;&lt;P class=""&gt;const response = await this.fetchFunction(this.accessTokenUrl,&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &lt;/SPAN&gt;{&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;method: 'POST',&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;headers: {&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;'Content-Type': 'application/x-www-form-urlencoded',&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;Authorization: encodedCredentials,&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;},&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;body: this.generateTokensRequestBody(code),&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &lt;/SPAN&gt;});&lt;/P&gt;&lt;P class=""&gt;if (!response.ok) {&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &lt;/SPAN&gt;throw new Error(await response.text());&lt;/P&gt;&lt;P class=""&gt;}&lt;/P&gt;&lt;P class=""&gt;logger.info('Fetch function succeeded, parsing response...');&lt;/P&gt;&lt;P class=""&gt;const data = await response.json();&lt;/P&gt;&lt;P class=""&gt;const accessToken = data.access_token;&lt;/P&gt;&lt;P class=""&gt;const refreshToken = data.refresh_token;&lt;/P&gt;&lt;P class=""&gt;```&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;&lt;P class=""&gt;This is `generateTokensRequestBody()` seen above:&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;&lt;P class=""&gt;```&lt;/P&gt;&lt;P class=""&gt;return new URLSearchParams({&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &lt;/SPAN&gt;grant_type: 'authorization_code',&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &lt;/SPAN&gt;code,&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &lt;/SPAN&gt;redirect_uri: this.redirectUri,&lt;/P&gt;&lt;P class=""&gt;});&lt;/P&gt;&lt;P class=""&gt;```&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;&lt;P class=""&gt;As far as I can tell, I _cannot_ use PKCE because there's nowhere in the iOS SDK to provide the `code_verifier`. If I tried to pass the `code_verifier` when I exchange the code for the tokens, there's no previous call to reference.&lt;/P&gt;</description>
    <pubDate>Wed, 22 May 2024 14:13:02 GMT</pubDate>
    <dc:creator>StudioInit</dc:creator>
    <dc:date>2024-05-22T14:13:02Z</dc:date>
    <item>
      <title>Auth attempts all return "code_verifier required" when using non-PKCE auth between iOS and Web</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Auth-attempts-all-return-quot-code-verifier-required-quot-when/m-p/6084903#M13983</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Plan&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Free/Premium&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Country&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;USA&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Device&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;iPhone XR&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Operating System&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;iOS 17.4.1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My Question or Issue&lt;/STRONG&gt;&lt;/P&gt;&lt;P class=""&gt;I'm trying to authenticate using non-PKCE between Spotify iOS SDK and Web API. Every time I try to exchange the auth code for tokens, I get a 400 error and the body&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;PRE&gt;{"error":"invalid_request","error_description":"code_verifier required"}&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P class=""&gt;. However, &lt;A href="https://developer.spotify.com/documentation/web-api/tutorials/code-flow" target="_self"&gt;according to the non-PKCE docs&lt;/A&gt;, no code_verifier should be included. My flow is:&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;&lt;P class=""&gt;1. Use my iOS app and Spotify iOS SDK + Spotify app installed to retrieve the authorization code.&lt;/P&gt;&lt;P class=""&gt;2. Pass that code to my service backend to exchange it for the OAuth tokens (refresh and access).&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;&lt;P class=""&gt;Swift&lt;/P&gt;&lt;P class=""&gt;```&lt;/P&gt;&lt;P class=""&gt;// Create a SPTSessionManager&lt;/P&gt;&lt;P class=""&gt;let sessionManager = …&lt;/P&gt;&lt;P class=""&gt;sessionManager?.initiateSession(with: scopes, options: .default)&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;&lt;P class=""&gt;// In my AppDelegate URL processing callback&lt;/P&gt;&lt;P class=""&gt;guard let appRemote = appRemote else { return }&lt;/P&gt;&lt;P class=""&gt;guard let parameters = appRemote.authorizationParameters(from: url) else { return }&lt;/P&gt;&lt;P class=""&gt;guard let access_code = parameters["code"] else { return }&lt;/P&gt;&lt;P class=""&gt;logger.info("Spotify Access Code: \(String(describing: access_code))")&lt;/P&gt;&lt;P class=""&gt;```&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;&lt;P class=""&gt;All this works, and I see an access code.&lt;SPAN class=""&gt;&amp;nbsp; &lt;/SPAN&gt;I then pass that code to my Node.js backend to exchange the code for tokens and store the tokens (so I can make Web API calls later). The called URL is `&lt;A href="https://accounts.spotify.com/api/token" target="_blank" rel="noopener"&gt;https://accounts.spotify.com/api/token&lt;/A&gt;`.&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;&lt;P class=""&gt;```&lt;/P&gt;&lt;P class=""&gt;logger.info('Exchanging code for tokens');&lt;/P&gt;&lt;P class=""&gt;const encodedCredentials = this.encodeClientCredentials({&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &lt;/SPAN&gt;clientId: this.clientId,&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &lt;/SPAN&gt;clientSecret: this.clientSecret,&lt;/P&gt;&lt;P class=""&gt;});&lt;/P&gt;&lt;P class=""&gt;const response = await this.fetchFunction(this.accessTokenUrl,&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &lt;/SPAN&gt;{&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;method: 'POST',&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;headers: {&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;'Content-Type': 'application/x-www-form-urlencoded',&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;Authorization: encodedCredentials,&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;},&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;body: this.generateTokensRequestBody(code),&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &lt;/SPAN&gt;});&lt;/P&gt;&lt;P class=""&gt;if (!response.ok) {&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &lt;/SPAN&gt;throw new Error(await response.text());&lt;/P&gt;&lt;P class=""&gt;}&lt;/P&gt;&lt;P class=""&gt;logger.info('Fetch function succeeded, parsing response...');&lt;/P&gt;&lt;P class=""&gt;const data = await response.json();&lt;/P&gt;&lt;P class=""&gt;const accessToken = data.access_token;&lt;/P&gt;&lt;P class=""&gt;const refreshToken = data.refresh_token;&lt;/P&gt;&lt;P class=""&gt;```&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;&lt;P class=""&gt;This is `generateTokensRequestBody()` seen above:&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;&lt;P class=""&gt;```&lt;/P&gt;&lt;P class=""&gt;return new URLSearchParams({&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &lt;/SPAN&gt;grant_type: 'authorization_code',&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &lt;/SPAN&gt;code,&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &lt;/SPAN&gt;redirect_uri: this.redirectUri,&lt;/P&gt;&lt;P class=""&gt;});&lt;/P&gt;&lt;P class=""&gt;```&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;&lt;P class=""&gt;As far as I can tell, I _cannot_ use PKCE because there's nowhere in the iOS SDK to provide the `code_verifier`. If I tried to pass the `code_verifier` when I exchange the code for the tokens, there's no previous call to reference.&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2024 14:13:02 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Auth-attempts-all-return-quot-code-verifier-required-quot-when/m-p/6084903#M13983</guid>
      <dc:creator>StudioInit</dc:creator>
      <dc:date>2024-05-22T14:13:02Z</dc:date>
    </item>
    <item>
      <title>Re: Auth attempts all return "code_verifier required" when using non-PKCE auth between iOS</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Auth-attempts-all-return-quot-code-verifier-required-quot-when/m-p/6474163#M15410</link>
      <description>&lt;P&gt;I am also having this issue. Were you able to find a solution?&lt;/P&gt;</description>
      <pubDate>Thu, 31 Oct 2024 18:46:39 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Auth-attempts-all-return-quot-code-verifier-required-quot-when/m-p/6474163#M15410</guid>
      <dc:creator>jcrm1</dc:creator>
      <dc:date>2024-10-31T18:46:39Z</dc:date>
    </item>
  </channel>
</rss>

