0

I´m using a OAuth2.0 authentication service with Proof Key for Code Exchange (PKCE) to access Spotify token. I registered my App in Spotify with my BundleID und Redirect URI.

The problem is that after i enter my email and password for Spotify signin i get redirected to the RedirectUri with the code in the URL and nothing happens.

Here my Code:

Code for Auth User

This open correctly my Safari but then I'm redirected to the URI with the code to access the token in the URL and nothing happened.

After the Spotify signin

Im currently working on iOS 14 and this is how I setup my URL Types URL Type. This is my first time working with oAuth and I dont know what I´m doing wrong.

So my question is how i get back to my app after authorize the user?

1
  • Please post the code directly into your question, not a link to an image. This will help other users to better understand and answer your question. meta.stackoverflow.com/a/285557 Apr 11, 2021 at 9:59

2 Answers 2

1

In order to have the OAuth workflow trigger the app, the callback URL has to be the URL you configured in the app under the "URL Types" on the "Info" tab.

That would look something like this: enter image description here

Then configure the callback URL using this URL scheme for the website you are using with OAuth. This URL may look something like this:

myapp://oauth-callback/spotify

Once this configured; this is the URL that you will specify as the value of the withCallbackURL parameter when calling the authorize(...) method.

Depending on the action taken by the user, the OAuth mechanism will trigger this callback URL and if you are on the device, you will be prompted to "Open" the app; and upon tapping on "Open" you will be taken to the app. The app will receive the deep link will contain the state of the authorization and all needed information, as query string parameters, (following the above example, showing the error case):

myapp://oauth-callback/spotify?error:access_denied&state=...

Developer documentation for defining URL Scheme for your app.

0

Is that site a real site? When user is redirected to your URL callback endpoint, you are supposed to take the code from the URL query parameters and in your servers exchange it with an Access Token. Then you should store that access token somewhere and pass both "client-id": yourClientId "Authorization": userAccessToken as headers to your requests that you are making to Spotify servers, everytime.

3
  • thank you for your answer. This site is not real. How i return the url and close the safari view? should not the Oauth libary dismiss the view and return the code?
    – Vadim K
    Apr 10, 2021 at 12:19
  • You need a backend little-server to use the code to get an access token for you, You can do it in your app, but that risks all your credentials (most important of them, your client secret) to be exposed. You can dig into the matter more yourself, about why you need a backend and you shouldn't do it in the app, but the word client secret itself should be enough for you. No-one should know your secrets!
    – Mahdi BM
    Apr 10, 2021 at 12:49
  • For more clarification, No, it should not close safari and return the code. After you url callback endpoint is called, you need to acquire the access token on you servers and then either let the user close safari or do it yourself from your Web API (which is a little bit more complicated)
    – Mahdi BM
    Apr 10, 2021 at 12:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.