How to implement SSO in Xamarin Forms App?

Viewed 631

I am trying to implement SSO feature in my app (Xamarin.Forms App - both of ios and android). Login flow is: when user opens login page, she/he will see a button as login with sso. And if user chooses this button, app will open a webview for sso and when sso authentication is completed (it works mdm solution such as airwatch etc.), returns a SAML token.

My problem is how can I implement this, how can I capture saml token from webview? Actually there is a way for this in xamarin because of I see a video in xamarin evolve conferance: https://www.youtube.com/watch?v=AAAQJgBDK0w&t=1163s

When AuthTpye was set as "SAML" (in video 15:51 second) and when open the app login with airwatch sso on webview (in video 16:45-17:14 seconds), user can login with sso. But I only could find this video. I couldn't find any other source for this implementation.

Furthermore I saw some Stack Overflow questions for this, and their answers say use Xamarin.Auth nuget package. But Xamarin.Auth uses oauth2.0 protocol. I need use saml protocol for sso.

How can I do this?

1 Answers

Xamarin.Essentials has a class called "WebAuthenticator" that will help you a lot.

Documentation can be found here: https://docs.microsoft.com/en-us/xamarin/essentials/web-authenticator?tabs=android

It makes the process very simple. You just send the login request:

var authResult = await WebAuthenticator.AuthenticateAsync(loginUrl, responseUrl);

The "authResult" variable would hold your token and claims.

You will also need to implement an activity or method (depending on platform) to handle the custom URL you passed in as "responseUrl" in the code above and relay the response back to the Xamarin.Essentials library. I strongly encourage you to read the docs linked above. They are very helpful.

Related