Context
I've read somewhere that one should not match by email (e.g. the email given by the Google JWT token) when using SSO (e.g. OpenID Connect) but it's not clear to me why.
The recommended approach seems to be using aud
and sub
claims or other similar combinations but this has obvious drawbacks:
for example if a user logs in with Google and then after a few months, not remembering which SSO provider it used, it logs in with Facebook, with the same email, then a new account will be created; if we were matching by email address instead the two accounts would be effectively linked.
Question
Assuming access to the email should grant access to the application, what are the downsides of matching users by the email provided by a SSO provider (assuming email_verified
is true
)?
aud
is not relevant here, it should always be checked to help avoid the Confused Deputy Problem.sub
is the user id at the issuer, Google itself clears out (in its doc) thatsub
is stable, the e-mail is not. If you use the e-mail you may not match even for the same IdP. Regarding using a different IdP with the same e-mail, that's a form of federation of accounts. Allowing a match by e-mail is a security risk because you don't know if the IdP verified that e-mail or if that accounted was leaked. But can also turn out to be handy, so you may want to implement a federation processsub
but a matching e-mail you make the user verify the e-mail. This assuming it's the e-mail that proxies the identities of your users (i.e. whoever control the e-mail of account X, is account X, no matter what).