-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from kobaltz/passkey-login-no-password
Passkey Login without email/password
- Loading branch information
Showing
10 changed files
with
84 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,6 +102,7 @@ ActionAuth.configure do |config| | |
config.allow_user_deletion = true | ||
config.default_from_email = "[email protected]" | ||
config.magic_link_enabled = true | ||
config.passkey_only = true # Allows sign in with only a passkey | ||
config.verify_email_on_sign_in = true | ||
config.webauthn_enabled = true | ||
config.webauthn_origin = "http://localhost:3000" # or "https://example.com" | ||
|
@@ -127,6 +128,8 @@ These are the planned features for ActionAuth. The ones that are checked off are | |
✅ - Passkeys/Hardware Security Keys | ||
✅ - Passkeys sign in without email/password | ||
✅ - Magic Links | ||
⏳ - OAuth with Google, Facebook, Github, Twitter, etc. | ||
|
@@ -141,8 +144,6 @@ These are the planned features for ActionAuth. The ones that are checked off are | |
⏳ - Account Impersonation | ||
## Usage | ||
### Routes | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
app/controllers/action_auth/sessions/passkeys_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module ActionAuth | ||
module Sessions | ||
class PasskeysController < ApplicationController | ||
def new | ||
get_options = WebAuthn::Credential.options_for_get | ||
session[:current_challenge] = get_options.challenge | ||
@options = get_options | ||
end | ||
|
||
def create | ||
webauthn_credential = WebAuthn::Credential.from_get(params) | ||
credential = WebauthnCredential.find_by(external_id: webauthn_credential.id) | ||
user = User.find_by(id: credential&.user_id) | ||
if credential && user | ||
session = user.sessions.create | ||
cookies.signed.permanent[:session_token] = { value: session.id, httponly: true } | ||
redirect_to main_app.root_path(format: :html), notice: "Signed in successfully" | ||
else | ||
redirect_to sign_in_path(format: :html), alert: "That passkey is incorrect" and return | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<h2 class="action-auth--text-center">Use a passkey to sign in</h2> | ||
<%= tag :meta, name: :passkey_auth_url, content: action_auth.sessions_passkeys_url %> | ||
<%= content_tag :div, | ||
id: "webauthn_credential_form", | ||
data: { | ||
controller: "credential-authenticator", | ||
"credential-authenticator-options-value": @options | ||
}, | ||
class: "action-auth--text-center" do %> | ||
|
||
<div class="mb-3 action-auth--text-center"> | ||
Insert a USB key, if necessary, and tap it. | ||
An account with a matching passkey is required. | ||
</div> | ||
<% end %> | ||
<%= content_for :cancel_path do %> | ||
<%= link_to "Cancel", action_auth.sign_in_path %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ def initialize | |
@allow_user_deletion = true | ||
@default_from_email = "[email protected]" | ||
@magic_link_enabled = true | ||
@passkey_only = true | ||
@pwned_enabled = defined?(Pwned) | ||
@verify_email_on_sign_in = true | ||
@webauthn_enabled = defined?(WebAuthn) | ||
|
@@ -29,6 +30,10 @@ def magic_link_enabled? | |
@magic_link_enabled == true | ||
end | ||
|
||
def passkey_only? | ||
webauthn_enabled? && @passkey_only == true | ||
end | ||
|
||
def webauthn_enabled? | ||
@webauthn_enabled.respond_to?(:call) ? @webauthn_enabled.call : @webauthn_enabled | ||
end | ||
|