-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add webauthn_modify_email feature for emailing when a WebAuthn authen…
…ticator is added or removed
- Loading branch information
1 parent
b968e8c
commit 1275004
Showing
10 changed files
with
120 additions
and
1 deletion.
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
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,19 @@ | ||
= Documentation for WebAuthn Modify Email Feature | ||
|
||
The webauthn_modify_email feature emails users when a WebAuthn authenticator is added to or removed from their account. | ||
|
||
The webauthn_modify_email feature depends on the webauthn and email_base features. | ||
|
||
== Auth Value Methods | ||
|
||
webauthn_authenticator_added_email_body :: Body to use for the email notifying user that a WebAuthn authenticator has been added to their account. | ||
webauthn_authenticator_added_email_subject :: Subject to use for the email notifying user that a WebAuthn authenticator has been added to their account. | ||
webauthn_authenticator_removed_email_body :: Body to use for the email notifying user that a WebAuthn authenticator has been removed from their account. | ||
webauthn_authenticator_removed_email_subject :: Subject to use for the email notifying user that a WebAuthn authenticator has been removed from their account. | ||
|
||
== Auth Methods | ||
|
||
create_webauthn_authenticator_added_email :: A Mail::Message for the email notifying user that a WebAuthn authenticator has been added to their account. | ||
create_webauthn_authenticator_removed_email :: A Mail::Message for the email notifying user that a WebAuthn authenticator has been removed from their account. | ||
send_webauthn_authenticator_added_email :: Send the email notifying user that a WebAuthn authenticator has been added to their account. | ||
send_webauthn_authenticator_removed_email :: Send the email notifying user that a WebAuthn authenticator has been removed from their account. |
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,23 @@ | ||
# frozen-string-literal: true | ||
|
||
module Rodauth | ||
Feature.define(:webauthn_modify_email, :WebauthnModifyEmail) do | ||
depends :webauthn, :email_base | ||
|
||
loaded_templates %w'webauthn-authenticator-added-email webauthn-authenticator-removed-email' | ||
email :webauthn_authenticator_added, 'WebAuthn Authenticator Added', :translatable=>true | ||
email :webauthn_authenticator_removed, 'WebAuthn Authenticator Removed', :translatable=>true | ||
|
||
private | ||
|
||
def after_webauthn_setup | ||
super | ||
send_webauthn_authenticator_added_email | ||
end | ||
|
||
def after_webauthn_remove | ||
super | ||
send_webauthn_authenticator_removed_email | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
require_relative 'spec_helper' | ||
|
||
begin | ||
require 'webauthn/fake_client' | ||
rescue LoadError | ||
else | ||
describe 'Rodauth webauthn feature' do | ||
it "should email when a webauth authenticator is added or removed" do | ||
rodauth do | ||
enable :login, :logout, :webauthn_modify_email | ||
hmac_secret '123' | ||
two_factor_modifications_require_password? false | ||
webauthn_remove_redirect '/foo' | ||
end | ||
first_request = nil | ||
roda do |r| | ||
first_request ||= r | ||
r.rodauth | ||
r.get('foo'){view :content=>"WebAuthn Removed"} | ||
rodauth.require_authentication | ||
rodauth.require_two_factor_setup | ||
view :content=>"With WebAuthn" | ||
end | ||
|
||
login | ||
origin = first_request.base_url | ||
|
||
webauthn_client = WebAuthn::FakeClient.new(origin) | ||
challenge = JSON.parse(page.find('#webauthn-setup-form')['data-credential-options'])['challenge'] | ||
fill_in 'webauthn_setup', :with=>webauthn_client.create(challenge: challenge).to_json | ||
click_button 'Setup WebAuthn Authentication' | ||
page.find('#notice_flash').text.must_equal 'WebAuthn authentication is now setup' | ||
email = email_sent | ||
email.subject.must_equal "WebAuthn Authenticator Added" | ||
email.body.to_s.must_equal <<EMAIL | ||
Someone (hopefully you) has added a WebAuthn authenticator to the | ||
account associated to this email address. There are now 1 WebAuthn | ||
authenticator(s) with access to the account. | ||
|
||
logout | ||
login | ||
|
||
challenge = JSON.parse(page.find('#webauthn-auth-form')['data-credential-options'])['challenge'] | ||
fill_in 'webauthn_auth', :with=>webauthn_client.get(challenge: challenge).to_json | ||
click_button 'Authenticate Using WebAuthn' | ||
page.find('#notice_flash').text.must_equal 'You have been multifactor authenticated' | ||
page.current_path.must_equal '/' | ||
|
||
visit '/webauthn-remove' | ||
choose(/(?<=name="webauthn_remove" id=")webauthn-remove-[^"]*/.match(page.body)[0]) | ||
click_button 'Remove WebAuthn Authenticator' | ||
page.find('#notice_flash').text.must_equal "WebAuthn authenticator has been removed" | ||
email = email_sent | ||
email.subject.must_equal "WebAuthn Authenticator Removed" | ||
email.body.to_s.must_equal <<EMAIL | ||
Someone (hopefully you) has removed a WebAuthn authenticator from the | ||
account associated to this email address. There are now 0 WebAuthn | ||
authenticator(s) with access to the account. | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Someone (hopefully you) has added a WebAuthn authenticator to the | ||
account associated to this email address. There are now #{rodauth.account_webauthn_ids.length} WebAuthn | ||
authenticator(s) with access to the account. |
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,3 @@ | ||
Someone (hopefully you) has removed a WebAuthn authenticator from the | ||
account associated to this email address. There are now #{rodauth.account_webauthn_ids.length} WebAuthn | ||
authenticator(s) with access to the account. |
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