Home > database >  How to handle multiple IDP with opaque access tokens
How to handle multiple IDP with opaque access tokens

Time:10-05

I am currently writing a social media backend server, which should handle a lot of users. As authentication mechanism, we want to use Google's & Apple's OIDC Authentication (Sign in with Apple).

Now, as we get a opaque access token, I cant really imagine a performant way to authorize the opaque access token, as we can not decode the token (not jwt token) and we do not know the issuer.

What I thought:

  1. Authorize the access token sequentially one by one. Meaning:
  • Fetch Google/userinfo from Google
  • If 401, Fetch Apple/userinfo

This is unperformant, as the processing time is getting bigger, when we add more IDP's

  1. Save the issuer in the DB and fetch the user's issuer always in the authentication step, before fetching the /userinfo endpoint

This is more performant, but it does not feel right, as the webserver has to make a DB call HTTP call to authorize a request from the client.

Am I missing a method to get this in a performant way?

BTW: The webserver is a node.js application using express.js

Thank you very much in advice!

CodePudding user response:

The key point here is that foreign access tokens are not designed for authorization in your own back end. Instead you need to issue your own tokens when sign in completes.

AUTHORIZATION SERVER (AS)

The most standard solution is for your apps to talk to an AS that you own, and for it to manage the social logins for you. The AS will then issue tokens that you can fully customize.

This will enable you to fully control the scopes and claims your back end uses for authorization, as well as the session times in UIs. Your back end will only ever work with access tokens issued by the AS, regardless of the login method a user selects.

When you need to add a new login method you just change the AS configuration and will not need to change any code in your apps. A good AS will support integrating with many systems, as demonstrated in this summary page.

  • Related