2

I am developing an mobile app in Unity3D which uses oauth to login through my organization ADFS.

My understanding of the flow is,

  1. user tries to sign in
  2. app opens browser to oauth server for user to input credential
  3. oauth server returns a authorization code and redirect user back to app
  4. app send code to oauth server to exchange for a token
  5. decode token to get user details

Is my understanding of the flow correct?

How do we do this in unity3D, especially the part where browser redirects back to the app, and how does the app get the authorization code in this process?

Update:

The deep link post in the accepted answer shows how to redirect from browser back to unity app. The iOS solution also demonstrated how to pass the redirect url data back to an iOS app, but this is missing from the android section.

I did some futher googling and found out, to receive url data back in android, it involves making a plugin for Unity by overriding the UnityPlayerActivity. I have followed this tutorial with great success.

Mak Hon Keat
  • 187
  • 5
  • 12

1 Answers1

1

You need to register a deep link for your app, and use that protocol in the oauth redirect uri so it gets sent to your app's deep link handler.

Here's a tutorial for how to do it on ios and android.

https://connect.unity.com/p/deep-linking-on-android-ios-with-unity

Deep linking is possible on windows as well, but they call it a "custom protocol handler". Here's a great stackoverflow question about it:

How do I register a custom URL protocol in Windows?

And in webGL you should be able to just redirect back to your page and get the token from the url.

Leo Bartkus
  • 1,925
  • 13
  • 17
  • Thanks Leo! Deep linking works for me. I followed the deep linking tutorial, added the intent filter in android manifest and got it to work. But it didn't show how to pass data back to the app for android. Can you point me to the right direction? – Mak Hon Keat Mar 20 '20 at 02:33
  • I have figured out how to receive the redirect url data back in app for android. It involves making an android unity plugin. Will update my question to include this solution. – Mak Hon Keat Mar 20 '20 at 13:53