Xamarin Forms Xamarin.Essentials: Web Authenticator with ASP.NET Web API Social Login

Viewed 383

I'm using Xamarin Forms mobile app with backend api using ASP.NET Web API project. The Web API is able to login with Facebook using Ajax and Web API methods such as (api/account/externallogins, api/account/registerexternal).

From Xamarin Forms mobile app, I'm trying to use web authenticator for Facebook login. I was able to launch Facebook authentication page.

After I log in successfully, the code returns to the app, but it could not get the access token needed.

Could anyone advice on how to connect Xamarin Forms and ASP.NET Web API for social login?

Reference URLs:

https://docs.microsoft.com/en-us/xamarin/essentials/web-authenticator?tabs=android

https://github.com/xamarin/Essentials/blob/main/Samples/Samples/ViewModel/WebAuthenticatorViewModel.cs

I've added the sample backend web api using for social login. By adding Facebook credentials and launch https://localhost:port/login.html, you could able to proceed for facebook login.

https://github.com/SuMingYuan-MM/WebApiTest

authenticationUrl = https://api.example.com/api/Account/ExternalLogin?provider=Facebook&response_type=token&client_id=self&redirect_uri=https%3A%2F%2Fapi.example.com%2F&state=maDXXfsWrKW8wN_F6KO2tQ5ErZyky2-FiRZPQhQ1Xbs1

In browser, I could get the following url after successful login to Facebook.

https://api.example.com/#access_token={access_token}&token_type=bearer&expires_in=1209600&state=Jp_aHFbZE4WI0jYqeiy1B1UvW7unVGblVHBt5EZNj1o1

WebAuthenticator.AuthenticateAsync

Facebook Login

No Access Token

0 Answers
Related