Skip to main content
added 1560 characters in body
Source Link
Glorfindel
  • 6.9k
  • 3
  • 22
  • 49

You canIt is indeed possible to use custom URL schemes for authentication in an iOS app. Here are the steps I took:

  1. Choose an arbitrary domain, like stackexchange.com, for the OAuth domain in your Stack Apps

  2. (Optional) Make sure it has a Stack Apps Post if you want tokens with write access.

  3. Check the checkboxes for these options:

    • Enable Client Side OAuth Flow
    • Disable Desktop Application OAuth Redirect Uri
  4. Register the custom URL scheme for your application in the usual way, as described e.g. here.

  5. Use code like this to start the authentication flow (in Safari, not in the app itself). Substitute 54321 with the client ID from your Stack Apps listing. You may adjust the scope according to the documentation, and of course the redirect_uri, as long as the domain matches the one in the Stack Apps listing.

    let url = "https://stackoverflow.com/oauth/dialog?client_id=54321&scope=read_inbox,no_expiry,write_access,private_info&redirect_uri=example://stackexchange.com";
    UIApplication.shared.open(URL(string: url)!) { (result) in }
    
  6. Log in to Stack Overflow; your app will be opened and the URL will be something like example://stackexchange.com/#access_token=12345)) where 12345)) is the actual token.


An alternative is to use Universal Links to register ana HTTP(S) URL you own, say https://furdui.example.com with your iOS app. Then, you can use the domain furdui.example.com as OAuth domain in Stack Apps, and have the redirects automatically forwarded to your iOS app.

You can use Universal Links to register an URL you own, say https://furdui.example.com with your iOS app. Then, you can use the domain furdui.example.com as OAuth domain in Stack Apps, and have the redirects automatically forwarded to your iOS app.

It is indeed possible to use custom URL schemes for authentication in an iOS app. Here are the steps I took:

  1. Choose an arbitrary domain, like stackexchange.com, for the OAuth domain in your Stack Apps

  2. (Optional) Make sure it has a Stack Apps Post if you want tokens with write access.

  3. Check the checkboxes for these options:

    • Enable Client Side OAuth Flow
    • Disable Desktop Application OAuth Redirect Uri
  4. Register the custom URL scheme for your application in the usual way, as described e.g. here.

  5. Use code like this to start the authentication flow (in Safari, not in the app itself). Substitute 54321 with the client ID from your Stack Apps listing. You may adjust the scope according to the documentation, and of course the redirect_uri, as long as the domain matches the one in the Stack Apps listing.

    let url = "https://stackoverflow.com/oauth/dialog?client_id=54321&scope=read_inbox,no_expiry,write_access,private_info&redirect_uri=example://stackexchange.com";
    UIApplication.shared.open(URL(string: url)!) { (result) in }
    
  6. Log in to Stack Overflow; your app will be opened and the URL will be something like example://stackexchange.com/#access_token=12345)) where 12345)) is the actual token.


An alternative is to use Universal Links to register a HTTP(S) URL you own, say https://furdui.example.com with your iOS app. Then, you can use the domain furdui.example.com as OAuth domain in Stack Apps, and have the redirects automatically forwarded to your iOS app.

Source Link
Glorfindel
  • 6.9k
  • 3
  • 22
  • 49

You can use Universal Links to register an URL you own, say https://furdui.example.com with your iOS app. Then, you can use the domain furdui.example.com as OAuth domain in Stack Apps, and have the redirects automatically forwarded to your iOS app.