How can I securely identify a user linking their account via OAuth?
Asked by
~election district 6
I'm working on an OAuth flow to link user accounts and could use some advice. When a user logs in or registers for the first time, I can use the identifier given back from the provider to identify them without any issues. However, when an existing user tries to link their account with a provider (like Google), I need a reliable way to determine which user is initiating this process. Right now, I'm using the OAuth state parameter to store user information as a JWT that includes a random string, user ID, and redirect URI. Is this a safe approach, or could there be potential issues with it?
Answers
I get your concerns. Just keep in mind that if your frontend doesn't manage the OAuth callback, the access token could be tricky to handle. You might want to look into storing it in a more secure way, like a cookie. Also, remember that different email addresses can complicate things if users don't match them up.
Reply to this answer
You might want to check if the unique identifier given by the OpenID Connect (OIDC) is sufficient for your case. The issuer and subject should uniquely identify a user, right?
Reply to this answer
If the user is already logged in, you should have their ID available in the session or within a JWT token. You could also consider asking the identity provider for the user's email and matching it that way.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions