-
-
Notifications
You must be signed in to change notification settings - Fork 91
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
Create auth token links for email #70
Comments
It seems like from the implementation that I have, there are two methods that could be helpful to have build in.
It is easy enough that it doesn't need to be built in, but just an idea. |
I added this method to the user model to generate tokens easily: def create_auth_token!
Passwordless::Session.create(
remote_addr: 'generated_by_rails',
user_agent: 'generated_by_rails',
authenticatable: self
).token
end |
I like this idea and have wanted to do something similar, however I think we should take the other way around and make the urls like |
Yeah I think that is smart actually, then It would be nice if the def passwordless_token!
@passwordless_token ||= Passwordless::Session.create(
remote_addr: 'generated_by_rails',
user_agent: 'generated_by_rails',
authenticatable: self
).token
end
def passwordless_url!(destination_path: nil)
url_helper = Passwordless::Mailer.new.send(Passwordless.mounted_as)
url = url_helper.token_sign_in_url(passwordless_token!)
return url unless destination_path
"#{url}?destination_path=#{destination_path}"
end |
I usually just put Having a few helpers like you suggest would be nice. I'm not sure about the API. Will let it stew a bit in my mind and see what I can do 😊 |
I need this! The code presented here no longer works with the latest version, but I managed to do something similar in my controller: def passwordless_url_to(authenticatable, destination_path = '')
session = create_passwordless_session!(authenticatable)
link = Passwordless.context.url_for(
session,
action: "confirm",
id: session.to_param,
token: session.token
)
return "#{link}?destination_path=#{destination_path}"
end It would be nice to have something like this in I don't understand the purpose of |
I'm not sure if there is a preferred way of doing this or not. But what I want to be able to do is send an email to a user that wasn't user initiated that automatically signs them in. For example I want to email the user to prompt them to update a post and I want that link to be authenticated so if they aren't signed in they don't have to go through the sign in flow and make multiple trips to their email.
My idea was to use an
auth_token
in the url that is also checked incurrent_user
.Example:
1. Initiate Email Link
2. Link send via email
3. Lookup via session or auth token
What I like about this is you can auth in with an auth token in any action that uses
require_user!
and once rails signs them in with the auth token then they will be signed in and future requests will short circuit to theauthenticate_by_session
like normal.This may be the preferred way of doing this, Im just not sure if there was a better way or a way it could be built into the project going forward. Open to suggestions and feedback, thanks for building a great package, really enjoying it! 😃
The text was updated successfully, but these errors were encountered: