Search code examples
asp.net-coreionic3openiddict

How to implement Facebook native app login in Ionic 3 with a .net Core API


I have a .Net Core Auth API with OpenIddict and a .Net Core Api 'client'. Now I'm building an Ionic 3 native app and I want to implement Facebook login where people can login via the native Facebook app. So far I only found examples where the Facebook web login is used.

So far I have:

  • a working .Net Core Auth API that returns Jwt tokens
  • a working .Net Core Client API that accepts these JWT tokens
  • a working Ionic 3 app that can login with username + password, get a token and use it.
  • a working Ionic 3 app with a Facebook login that logs in via the native Facebook app (via Cordova plugin)

It feels like the Code flow is the correct way to go, but all examples redirects to the Facebook login web page so the user probably still has to log in on Facebook while his native Facebook app is already logged in.

My question is: after a user is logged in via Facebook in my Ionic app, how can I get a JWT Token from the OpenIddict Auth Api so I can use my client API? Or should I change the flow somehow while the native Facebook app is used to log in?

update: In Ionic I do get Facebook UserId which is equal to the AspNetUserLogins.ProviderKey. Is that secure enough to login to your Api?


Solution

  • If using the code flow or opening the system browser to complete the authentication process interactively (including the FB authentication step) is definitely not an option for you, consider using a custom grant to allow your mobile app to redeem a FB access token (or authorization code) with an access token issued by OpenIddict.

    For more information, see this other SO thread: Rich Twitter Digits/Google Auth with OpenIdDictServer