Our app requires sign-in by either mobile number or Google. We are planning to Twitter Digits for mobile number authentication.
The flow of registration and authentication as I understand is as below:
Mobile app does rich authentication with Twitter Digits or Google Sign In (it’s better user experience for the user to do rich auth instead of opening a web browser tab). Twitter Digits / Google Sign In returns Identity Token.
Mobile app calls AuthServer to SignIn and presents Identity Token.
Identity server validates the presented Identity Token with Digits service or Google Auth Service.
Once verified, AuthServer would try to find the user, if not present it will create one.
AuthServer returns Access Token to the mobile app.
Now, I am looking for options to implement step #3-4.
Currently, what I have done is to modify token end-point code that takes in username as phone number or email address and password sent as Google/Twitter Digits ID token. Now, since auth server needs to know that the password sent is actually a token that needs to be verified with a third party service, I worked around it by sending service name “Digits” or “Google” in TokenHint.
This works very well, but I am wondering what is the cleanest way to support what I am trying to achieve.
I'd personally go with a custom grant type:
Note that you'll also have to enable it in the OpenIddict options:
When sending a token request, make sure to use the right
grant_type
and to send your id_token as theassertion
parameter, and it should work.Here's an example using Facebook access tokens:
Be extremely careful when implementing the token validation routine, as this step is particularly error-prone. It's really important to validate everything, including the audience (otherwise, your server would be vulnerable to confused deputy attacks).