Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve token #10

Open
sqlninja opened this issue Mar 4, 2021 · 3 comments
Open

Retrieve token #10

sqlninja opened this issue Mar 4, 2021 · 3 comments

Comments

@sqlninja
Copy link

sqlninja commented Mar 4, 2021

If I already have a user, say from an oauth login, is it possible to retrieve the token for that user?

I tried @token = login_and_issue_token(@user.email, @user.crypted_password)
but that just returns nil.

@hayfever
Copy link
Owner

hayfever commented Mar 4, 2021

It seems like in the code you gave you're using the encrypted password, I actually haven't used sorcery in a while but I believe you do @token = login_and_issue_token(@user.email, @user.password) for the unencrypted password and you should get a token back.

@sqlninja
Copy link
Author

sqlninja commented Mar 4, 2021

Yeah under a normal login flow that is accurate, we would receive the email/pw from the user. But with oAuth the user has logged on using a 3rd party (Twitter in my case), to which the twitter oauth callback just passes me the email (and other twitter related data) on the authenticated user.
I then use that email to look up if we have a user in our system matching what twitter sent us.

When the user is found I know have the activerecord instance of this user, but I need to pass back a response that includes the JWT token, so the apps/web can make subsequent authenticated calls.

This may not be possible with this gem, since it seems to be only generating a token based on a payload that includes both the email & pw...

Also, it appears there are discussions going on in Sorcery about including JWT tokenization natively, so this may be a moot point and not worth the effort here. Just though I'd asking if there was a way to get the token on a "known" user...

@joshbuker
Copy link

JWT support will indeed be added to Sorcery v1, see Sorcery/sorcery-rework#9 for further discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants