This is a secure login application that uses OpenID Connect / OAuth2 authentication, developed based on IdentityModel.OidcClient2. It enables secure login through the system's built-in browser to any third-party or self-hosted IdentityServer that follows the OpenID Connect / OAuth2 standard for single sign-on (SSO). The application has three built-in browsers redirect method for different scenarios:
- Android , it uses Chrome Custom Tabs
- iOS , it uses SFSafariViewController
- UnityEditor , for development mode, it uses the default browser of Windows / MacOS
This repository contains a sample Unity2022 Android/iOS/UnityEditor application that demonstrates how to implement this. It uses a demo instance of IdentityServer (demo.duendesoftware.com).
You can login with alice/alice
or bob/bob
- Ensure your Unity project's .NET version is set to 4.x in player settings.
- Add link.xml and mcs.rsp files to your Assets folder.
- It's important to note that the iOS and Android specific browser handling uses Unity's UnitySendMessage() function to notify the C# code of auth replies:
UnitySendMessage("SignInCanvas", "OnAuthReply", queryString);
So it's expected that your sign-in scene has a GameObject called SignInCanvas that has a script attached with function OnAuthReply, as demonstrated in the example scene in this repo.
- Use with Unity 2022 or newer
Two critical blog posts that enabled me to work out how to achieve this:
- Open SFSafariViewController / Chrome Custom Tabs from Unity (use Google Translate)
- Create An Android Plugin For Unity Using Android Studio
Code samples using IdentityModel.OidcClient2 for other platforms here.