rodauth 1.23.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +132 -0
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +207 -79
  5. data/doc/account_expiration.rdoc +12 -26
  6. data/doc/active_sessions.rdoc +49 -0
  7. data/doc/audit_logging.rdoc +44 -0
  8. data/doc/base.rdoc +74 -128
  9. data/doc/change_login.rdoc +7 -14
  10. data/doc/change_password.rdoc +9 -13
  11. data/doc/change_password_notify.rdoc +2 -2
  12. data/doc/close_account.rdoc +9 -16
  13. data/doc/confirm_password.rdoc +12 -5
  14. data/doc/create_account.rdoc +11 -22
  15. data/doc/disallow_password_reuse.rdoc +6 -13
  16. data/doc/email_auth.rdoc +15 -14
  17. data/doc/email_base.rdoc +5 -15
  18. data/doc/http_basic_auth.rdoc +10 -1
  19. data/doc/jwt.rdoc +22 -22
  20. data/doc/jwt_cors.rdoc +2 -3
  21. data/doc/jwt_refresh.rdoc +12 -8
  22. data/doc/lockout.rdoc +17 -15
  23. data/doc/login.rdoc +10 -2
  24. data/doc/login_password_requirements_base.rdoc +15 -37
  25. data/doc/logout.rdoc +2 -2
  26. data/doc/otp.rdoc +24 -19
  27. data/doc/password_complexity.rdoc +10 -26
  28. data/doc/password_expiration.rdoc +11 -25
  29. data/doc/password_grace_period.rdoc +16 -2
  30. data/doc/recovery_codes.rdoc +18 -12
  31. data/doc/release_notes/2.0.0.txt +361 -0
  32. data/doc/remember.rdoc +40 -64
  33. data/doc/reset_password.rdoc +12 -9
  34. data/doc/session_expiration.rdoc +1 -0
  35. data/doc/single_session.rdoc +16 -25
  36. data/doc/sms_codes.rdoc +24 -14
  37. data/doc/two_factor_base.rdoc +60 -22
  38. data/doc/verify_account.rdoc +14 -12
  39. data/doc/verify_account_grace_period.rdoc +6 -2
  40. data/doc/verify_login_change.rdoc +9 -8
  41. data/doc/webauthn.rdoc +115 -0
  42. data/doc/webauthn_login.rdoc +15 -0
  43. data/doc/webauthn_verify_account.rdoc +9 -0
  44. data/javascript/webauthn_auth.js +45 -0
  45. data/javascript/webauthn_setup.js +35 -0
  46. data/lib/roda/plugins/rodauth.rb +1 -1
  47. data/lib/rodauth.rb +29 -24
  48. data/lib/rodauth/features/account_expiration.rb +5 -5
  49. data/lib/rodauth/features/active_sessions.rb +160 -0
  50. data/lib/rodauth/features/audit_logging.rb +96 -0
  51. data/lib/rodauth/features/base.rb +131 -47
  52. data/lib/rodauth/features/change_password_notify.rb +1 -1
  53. data/lib/rodauth/features/confirm_password.rb +40 -2
  54. data/lib/rodauth/features/create_account.rb +7 -13
  55. data/lib/rodauth/features/disallow_common_passwords.rb +1 -1
  56. data/lib/rodauth/features/disallow_password_reuse.rb +1 -1
  57. data/lib/rodauth/features/email_auth.rb +29 -27
  58. data/lib/rodauth/features/email_base.rb +3 -3
  59. data/lib/rodauth/features/http_basic_auth.rb +44 -37
  60. data/lib/rodauth/features/jwt.rb +51 -8
  61. data/lib/rodauth/features/jwt_refresh.rb +3 -3
  62. data/lib/rodauth/features/lockout.rb +11 -13
  63. data/lib/rodauth/features/login.rb +48 -8
  64. data/lib/rodauth/features/login_password_requirements_base.rb +4 -4
  65. data/lib/rodauth/features/otp.rb +71 -81
  66. data/lib/rodauth/features/password_complexity.rb +4 -11
  67. data/lib/rodauth/features/password_expiration.rb +1 -1
  68. data/lib/rodauth/features/password_grace_period.rb +17 -10
  69. data/lib/rodauth/features/recovery_codes.rb +47 -51
  70. data/lib/rodauth/features/remember.rb +11 -27
  71. data/lib/rodauth/features/reset_password.rb +25 -25
  72. data/lib/rodauth/features/session_expiration.rb +6 -4
  73. data/lib/rodauth/features/single_session.rb +7 -5
  74. data/lib/rodauth/features/sms_codes.rb +58 -67
  75. data/lib/rodauth/features/two_factor_base.rb +132 -28
  76. data/lib/rodauth/features/verify_account.rb +23 -20
  77. data/lib/rodauth/features/verify_account_grace_period.rb +19 -8
  78. data/lib/rodauth/features/verify_login_change.rb +11 -10
  79. data/lib/rodauth/features/webauthn.rb +507 -0
  80. data/lib/rodauth/features/webauthn_login.rb +70 -0
  81. data/lib/rodauth/features/webauthn_verify_account.rb +46 -0
  82. data/lib/rodauth/version.rb +2 -2
  83. data/templates/button.str +1 -3
  84. data/templates/change-login.str +1 -2
  85. data/templates/change-password.str +3 -5
  86. data/templates/close-account.str +2 -2
  87. data/templates/confirm-password.str +1 -1
  88. data/templates/create-account.str +1 -1
  89. data/templates/email-auth-request-form.str +1 -2
  90. data/templates/email-auth.str +1 -1
  91. data/templates/global-logout-field.str +6 -0
  92. data/templates/login-confirm-field.str +2 -4
  93. data/templates/login-display.str +3 -2
  94. data/templates/login-field.str +2 -4
  95. data/templates/login-form-footer.str +6 -0
  96. data/templates/login-form.str +7 -0
  97. data/templates/login.str +1 -9
  98. data/templates/logout.str +1 -1
  99. data/templates/multi-phase-login.str +3 -0
  100. data/templates/otp-auth-code-field.str +5 -3
  101. data/templates/otp-auth.str +1 -1
  102. data/templates/otp-disable.str +1 -1
  103. data/templates/otp-setup.str +3 -3
  104. data/templates/password-confirm-field.str +2 -4
  105. data/templates/password-field.str +2 -4
  106. data/templates/recovery-auth.str +3 -6
  107. data/templates/recovery-codes.str +1 -1
  108. data/templates/remember.str +15 -20
  109. data/templates/reset-password-request.str +2 -2
  110. data/templates/reset-password.str +1 -2
  111. data/templates/sms-auth.str +1 -1
  112. data/templates/sms-code-field.str +5 -3
  113. data/templates/sms-confirm.str +1 -2
  114. data/templates/sms-disable.str +1 -2
  115. data/templates/sms-request.str +1 -1
  116. data/templates/sms-setup.str +6 -4
  117. data/templates/two-factor-auth.str +5 -0
  118. data/templates/two-factor-disable.str +6 -0
  119. data/templates/two-factor-manage.str +16 -0
  120. data/templates/unlock-account-request.str +2 -2
  121. data/templates/unlock-account.str +1 -1
  122. data/templates/verify-account-resend.str +1 -1
  123. data/templates/verify-account.str +1 -2
  124. data/templates/verify-login-change.str +1 -1
  125. data/templates/webauthn-auth.str +11 -0
  126. data/templates/webauthn-remove.str +14 -0
  127. data/templates/webauthn-setup.str +12 -0
  128. metadata +64 -11
  129. data/doc/verify_change_login.rdoc +0 -11
  130. data/lib/rodauth/features/verify_change_login.rb +0 -20
@@ -10,30 +10,32 @@ after verifying the account. Depends on the login and create account features.
10
10
  attempt_to_create_unverified_account_error_flash :: The flash error message to show when attempting to create an account awaiting verification.
11
11
  attempt_to_login_to_unverified_account_error_flash :: The flash error message to show when attempting to login to an account awaiting verification.
12
12
  no_matching_verify_account_key_error_flash :: The flash error message to show when an invalid verify account key is used.
13
+ resend_verify_account_page_title :: The page title to use on page requesting resending the verify account email.
13
14
  verify_account_additional_form_tags :: HTML fragment containing additional form tags to use on the verify account form.
14
15
  verify_account_autologin? :: Whether to autologin the user after successful account verification, true by default.
15
16
  verify_account_button :: The text to use for the verify account button.
17
+ verify_account_email_last_sent_column :: The email last sent column in the +verify_account_table+. Set to nil to always send a verify account email when requested.
16
18
  verify_account_email_recently_sent_error_flash :: The flash error to show if not sending verify account email because one has been sent recently.
17
19
  verify_account_email_recently_sent_redirect :: Where to redirect if not sending verify account email because one has been sent recently.
18
- verify_account_email_subject :: The subject to use for the verify account email.
19
- verify_account_email_sent_redirect :: Where to redirect after sending the verify account email.
20
20
  verify_account_email_sent_notice_flash :: The flash notice to set after sending the verify account email.
21
- verify_account_email_last_sent_column :: The email last sent column in the verify account keys table. nil by default, so a verify account email is always sent when requested by default.
21
+ verify_account_email_sent_redirect :: Where to redirect after sending the verify account email.
22
+ verify_account_email_subject :: The subject to use for the verify account email.
22
23
  verify_account_error_flash :: The flash error to show if no matching key is submitted when verifying an account.
23
- verify_account_id_column :: The id column in the verify account keys table, should be a foreign key referencing the accounts table.
24
- verify_account_key_column :: The verify account key/token column in the verify account keys table.
24
+ verify_account_id_column :: The id column in the +verify_account_table+, should be a foreign key referencing the accounts table.
25
+ verify_account_key_column :: The verify account key/token column in the +verify_account_table+.
25
26
  verify_account_key_param :: The parameter name to use for the verify account key.
26
27
  verify_account_notice_flash :: The flash notice to show after verifying the account.
28
+ verify_account_page_title :: The page title to use on the verify account form.
29
+ verify_account_redirect :: Where to redirect after verifying the account.
27
30
  verify_account_resend_additional_form_tags :: HTML fragment containing additional form tags to use on the page requesting resending the verify account email.
28
31
  verify_account_resend_button :: The text to use for the verify account resend button.
29
- verify_account_redirect :: Where to redirect after verifying the account.
30
32
  verify_account_resend_error_flash :: The flash error to show if unable to resend a verify account email.
31
33
  verify_account_resend_explanatory_text :: The text to display above the button to resend the verify account email.
32
- verify_account_resend_link :: The HTML to use for a link to the page to request the account verification email be resent.
34
+ verify_account_resend_link_text :: The text to use for a link to the page to request the account verification email be resent.
33
35
  verify_account_resend_route :: The route to the verify account resend action. Defaults to +verify-account-resend+.
34
36
  verify_account_route :: The route to the verify account action. Defaults to +verify-account+.
35
37
  verify_account_session_key :: The key in the session to hold the verify account key temporarily.
36
- verify_account_set_password? :: Whether to ask for a password to be set on the verify account form. Defaults to false. If set to true, will automatically stop asking for passwords to be set on the create account form.
38
+ verify_account_set_password? :: Whether to ask for a password to be set on the verify account form. True by default. If set to false, will ask for password when creating the account instead of when verifying.
37
39
  verify_account_skip_resend_email_within :: The number of seconds before sending another verify account email, if +verify_account_email_last_sent_column+ is set.
38
40
  verify_account_table :: The name of the verify account keys table.
39
41
 
@@ -41,14 +43,14 @@ verify_account_table :: The name of the verify account keys table.
41
43
 
42
44
  account_from_verify_account_key(key) :: Retrieve the account using the given verify account key, or return nil if no account matches.
43
45
  after_verify_account :: Run arbitrary code after verifying the account.
44
- after_verify_account_resend :: Run arbitrary code after resending a verify account email.
46
+ after_verify_account_email_resend :: Run arbitrary code after resending a verify account email.
45
47
  allow_resending_verify_account_email? :: Whether to allow sending the verify account email for the account, true by default only if the account has not been verified.
46
48
  before_verify_account :: Run arbitrary code before verifying the account.
47
- before_verify_account_resend :: Run arbitrary code before resending a verify account email.
49
+ before_verify_account_email_resend :: Run arbitrary code before resending a verify account email.
48
50
  before_verify_account_resend_route :: Run arbitrary code before handling a verify account resend route.
49
51
  before_verify_account_route :: Run arbitrary code before handling a verify account route.
50
- create_verify_account_key :: Add the verify account key data to the database.
51
52
  create_verify_account_email :: A Mail::Message for the verify account email.
53
+ create_verify_account_key :: Add the verify account key data to the database.
52
54
  get_verify_account_email_last_sent :: Get the last time a verify account email is sent, or nil if there is no last sent time.
53
55
  get_verify_account_key(id) :: Get the verify account key for the given account id from the database.
54
56
  remove_verify_account_key :: Remove the verify account key for the current account, run after successful account verification.
@@ -58,6 +60,6 @@ set_verify_account_email_last_sent :: Set the last time a verify account email i
58
60
  verify_account :: Verify the account by changing the status from unverified to open.
59
61
  verify_account_email_body :: The body to use for the verify account email.
60
62
  verify_account_email_link :: The link to the verify account form in the verify account email.
61
- verify_account_key_insert_hash :: The hash to insert into the verify account keys table.
63
+ verify_account_key_insert_hash :: The hash to insert into the +verify_account_table+.
62
64
  verify_account_key_value :: The value of the verify account key.
63
65
  verify_account_view :: The HTML to use for the verify account form.
@@ -2,12 +2,16 @@
2
2
 
3
3
  The verify account grace period feature allows users to login for
4
4
  a given period of time (1 day by default) before their account is
5
- verified. Depends on the verify account feature.
5
+ verified. Depends on the verify account feature. This switches
6
+ the +verify_account_set_password?+ to false so that user can login
7
+ with a password during the grace period.
6
8
 
7
9
  == Auth Value Methods
8
10
 
9
- verification_requested_at_column :: The column in the +verify_account_table+ table that holds the verification requested timestamp.
10
11
  unverified_account_session_key :: The session key set if the logged in account has not been unverified.
12
+ unverified_change_login_error_flash :: The flash error to show when an unverified accounts accesses a change login route.
13
+ unverified_change_login_redirect :: Where to redirect when an unverified accounts accesses a change login route.
14
+ verification_requested_at_column :: The column in the +verify_account_table+ table that holds the verification requested timestamp.
11
15
  verify_account_grace_period :: The amount of seconds after an account creation that a user will be able to login without verifying (86400 by default).
12
16
 
13
17
  == Auth Methods
@@ -1,11 +1,11 @@
1
1
  = Documentation for Verify Login Change Feature
2
2
 
3
- The verify login change feature implements login verification after
4
- a login change. With this feature, login changes do not take effect
3
+ The verify login change feature implements verification of login
4
+ changes. With this feature, login changes do not take effect
5
5
  until after the user has verified the new login. Until the new
6
6
  login has been verified, the old login continues to work.
7
7
 
8
- Any time you use the verify login change and change login features together,
8
+ Any time you use the verify account and change login features together,
9
9
  you should probably use this, otherwise it is trivial for users to work
10
10
  around account verification by creating an account with an email address
11
11
  they control, and the changing the login to an email address they don't
@@ -17,17 +17,18 @@ no_matching_verify_login_change_key_error_flash :: The flash error message to sh
17
17
  verify_login_change_additional_form_tags :: HTML fragment containing additional form tags to use on the verify login change form.
18
18
  verify_login_change_autologin? :: Whether to autologin the user after successful login change verification, false by default.
19
19
  verify_login_change_button :: The text to use for the verify login change button.
20
- verify_login_change_deadline_column :: The column name in the verify login change keys table storing the deadline after which the token will be ignored.
20
+ verify_login_change_deadline_column :: The column name in the +verify_login_change_table+ storing the deadline after which the token will be ignored.
21
21
  verify_login_change_deadline_interval :: The amount of time for which to allow users to verify login changes, 1 day by default.
22
22
  verify_login_change_duplicate_account_error_flash :: The flash error message to show when attempting to verify a login change when the login is already taken.
23
23
  verify_login_change_duplicate_account_redirect :: Where to redirect if not changing a login during verification because the new login is already taken.
24
24
  verify_login_change_email_subject :: The subject to use for the verify login change email.
25
25
  verify_login_change_error_flash :: The flash error to show if no matching key is submitted when verifying login change.
26
- verify_login_change_id_column :: The id column in the verify login change keys table, should be a foreign key referencing the accounts table.
27
- verify_login_change_key_column :: The verify login change key/token column in the verify login change keys table.
26
+ verify_login_change_id_column :: The id column in the +verify_login_change_table+, should be a foreign key referencing the accounts table.
27
+ verify_login_change_key_column :: The verify login change key/token column in the +verify_login_change_table+.
28
28
  verify_login_change_key_param :: The parameter name to use for the verify login change key.
29
- verify_login_change_login_column :: The login column in the verify login change keys table, containing the new login.
29
+ verify_login_change_login_column :: The login column in the +verify_login_change_table+, containing the new login.
30
30
  verify_login_change_notice_flash :: The flash notice to show after verifying the login change.
31
+ verify_login_change_page_title :: The page title to use on the verify login change form.
31
32
  verify_login_change_redirect :: Where to redirect after verifying the login change.
32
33
  verify_login_change_route :: The route to the verify login change action. Defaults to +verify-login-change+.
33
34
  verify_login_change_session_key :: The key in the session to hold the verify login change key temporarily.
@@ -49,7 +50,7 @@ send_verify_login_change_email(login) :: Send the verify login change email.
49
50
  verify_login_change :: Change the login for the given account to the new login.
50
51
  verify_login_change_email_body :: The body to use for the verify login change email.
51
52
  verify_login_change_email_link :: The link to the verify login change form in the verify login change email.
52
- verify_login_change_key_insert_hash(login) :: The hash to insert into the verify login change keys table.
53
+ verify_login_change_key_insert_hash(login) :: The hash to insert into the +verify_login_change_table+.
53
54
  verify_login_change_key_value :: The value of the verify login change key.
54
55
  verify_login_change_new_login :: The new login to use when the login change is verified.
55
56
  verify_login_change_old_login :: The old login to display in the verify login change email.
@@ -0,0 +1,115 @@
1
+ = Documentation for WebAuthn Feature
2
+
3
+ The webauthn feature implements multifactor authentication via WebAuthn.
4
+ It supports registering WebAuthn authenticators, using them for
5
+ multifactor authentication, and removing WebAuthn authenticators.
6
+ This feature supports multiple WebAuthn authenticators per user,
7
+ and users are encouraged to have multiple WebAuthn authenticators
8
+ so that they have a backup if one is not available.
9
+
10
+ WebAuthn authentication requires javascript to work in
11
+ browsers, for the browser to communicate with the authenticator.
12
+ This feature offers routes that return the appropriate javascript.
13
+ However, the javascript works by setting a hidden form field and
14
+ using normal form submission. This allows testing the feature
15
+ without using javascript. See Rodauth's tests for how testing
16
+ without javascript works.
17
+
18
+ The webauthn feature requires the webauthn gem.
19
+
20
+ == Auth Value Methods
21
+
22
+ authenticated_webauthn_id_session_key :: The session key used for storing which WebAuthn ID was used during authentication.
23
+ webauthn_attestation :: The value of the WebAuthn attestation option when registering a new WebAuthn authenticator.
24
+ webauthn_auth_additional_form_tags :: HTML fragment containing additional form tags when authenticating via WebAuthn.
25
+ webauthn_auth_button :: Text to use for button on the form to authenticate via WebAuthn.
26
+ webauthn_auth_challenge_hmac_param :: The parameter name for the HMAC of the WebAuthn challenge during authentication.
27
+ webauthn_auth_challenge_param :: The parameter name for the WebAuthn challenge during authentication.
28
+ webauthn_auth_error_flash :: The flash error to show if unable to authenticate via WebAuthn.
29
+ webauthn_auth_js :: The javascript code to execute on the page to authenticate via WebAuthn.
30
+ webauthn_auth_js_route :: The route to the webauthn auth javascript file.
31
+ webauthn_auth_link_text :: The text to use for the link from the multifactor auth page.
32
+ webauthn_auth_page_title :: The page title to use on the page for authenticating via WebAuthn.
33
+ webauthn_auth_param :: The parameter name for the WebAuthn authentication data.
34
+ webauthn_auth_route :: The route to the webauthn auth action.
35
+ webauthn_auth_timeout :: The number of milliseconds to wait when authenticating using a WebAuthn authenticator.
36
+ webauthn_authenticator_selection :: The value of the WebAuthn authenticatorSelection option when registering a new WebAuthn authenticator.
37
+ webauthn_duplicate_webauthn_id_message :: The error message to when there is an attempt to insert a duplicate WebAuthn authenticator.
38
+ webauthn_extensions :: The value of the WebAuthn extensions option when registering a new WebAuthn authenticator or authenticating via WebAuthn.
39
+ webauthn_invalid_auth_param_message :: The error message to show when invalid or missing WebAuthn authentication data is provided.
40
+ webauthn_invalid_remove_param_message :: The error message to show when invalid WebAuthn ID is provided when removing a WebAuthn authenticator.
41
+ webauthn_invalid_setup_param_message :: The error message to show when invalid or missing WebAuthn registration data is provided.
42
+ webauthn_invalid_sign_count_message :: The error message to when there is an attempt to authenticate with WebAuthn authenticator with an invalid sign count.
43
+ webauthn_js_host :: The protocol and domain if using a separate host for the WebAuthn setup and auth javascript files.
44
+ webauthn_keys_account_id_column :: The column in the +webauthn_keys_table+ containing the account id.
45
+ webauthn_keys_last_use_column :: The column in the +webauthn_keys_table+ containing the last time the WebAuthn credential was used.
46
+ webauthn_keys_public_key_column :: The column in the +webauthn_keys_table+ containing the public key for the WebAuthn credential.
47
+ webauthn_keys_sign_count_column :: The column in the +webauthn_keys_table+ containing the sign count for the WebAuthn credential.
48
+ webauthn_keys_table :: The table name containing the WebAuthn public keys.
49
+ webauthn_keys_webauthn_id_column :: The column in the +webauthn_keys_table+ containing the WebAuthn ID for the WebAuthn credential.
50
+ webauthn_not_setup_error_flash :: The flash error to show if going to the WebAuthn authentication page without having registered a WebAuthn authenticator.
51
+ webauthn_not_setup_error_status :: The status code to use if going to the WebAuthn authentication page without having registered a WebAuthn authenticator.
52
+ webauthn_origin :: The origin to use when verifying a WebAuthn authenticator.
53
+ webauthn_remove_additional_form_tags :: HTML fragment containing additional form tags when removing an existing WebAuthn authenticator.
54
+ webauthn_remove_button :: Text to use for button on the form to remove an existing WebAuthn authenticator.
55
+ webauthn_remove_error_flash :: The flash error to show if unable to remove an existing WebAuthn authenticator.
56
+ webauthn_remove_link_text :: The text to use for the remove link from the multifactor manage page.
57
+ webauthn_remove_notice_flash :: The flash notice to show after removing an existing WebAuthn authenticator.
58
+ webauthn_remove_page_title :: The page title to use on the page for removing an existing WebAuthn authenticator.
59
+ webauthn_remove_param :: The parameter name for the WebAuthn ID to remove.
60
+ webauthn_remove_redirect :: Where to redirect after successfully removing an existing WebAuthn authenticator.
61
+ webauthn_remove_route :: The route to the webauthn remove action.
62
+ webauthn_rp_id :: The relying party ID to use when registering a WebAuthn authenticator or authenticating via WebAuthn.
63
+ webauthn_rp_name :: The relying party name to use when registering a WebAuthn authenticator.
64
+ webauthn_setup_additional_form_tags :: HTML fragment containing additional form tags when registering a new WebAuthn authenticator.
65
+ webauthn_setup_button :: Text to use for button on the form to register a new WebAuthn authenticator.
66
+ webauthn_setup_challenge_hmac_param :: The parameter name for the HMAC of the WebAuthn challenge during registration.
67
+ webauthn_setup_challenge_param :: The parameter name for the WebAuthn challenge during registration.
68
+ webauthn_setup_error_flash :: The flash error to show if unable to register a new WebAuthn authenticator.
69
+ webauthn_setup_js :: The javascript code to execute on the page to register a new WebAuthn credential.
70
+ webauthn_setup_js_route :: The route to the webauthn setup javascript file.
71
+ webauthn_setup_link_text :: The text to use for the setup link from the multifactor manage page.
72
+ webauthn_setup_notice_flash :: The flash notice to show after registering a new WebAuthn authenticator.
73
+ webauthn_setup_page_title :: The page title to use on the page for registering a new WebAuthn authenticator.
74
+ webauthn_setup_param :: The parameter name for the WebAuthn registration data.
75
+ webauthn_setup_redirect :: Where to redirect after successfully registering a new WebAuthn authenticator.
76
+ webauthn_setup_timeout :: The number of milliseconds to wait when registering a new WebAuthn authenticator.
77
+ webauthn_setup_route :: The route to the webauthn setup action.
78
+ webauthn_user_ids_account_id_column :: The column in the +webauthn_user_ids_table+ containing the account id.
79
+ webauthn_user_ids_table :: The table name containing the WebAuthn user IDs.
80
+ webauthn_user_ids_webauthn_id_column :: The column in the +webauthn_user_ids_table+ containing the accounts WebAuthn user ID.
81
+ webauthn_user_verification :: The value of the WebAuthn userVerification option when registering a new WebAuthn authenticator.
82
+
83
+ == Auth Methods
84
+
85
+ account_webauthn_ids :: An array of WebAuthn IDs for registered WebAuthn credentials for the current account.
86
+ account_webauthn_usage :: A hash mapping WebAuthn IDs to the time of their last use for registered WebAuthn credentials for the current account.
87
+ account_webauthn_user_id :: The WebAuthn User ID for the current account.
88
+ add_webauthn_credential(webauthn_credential) :: Register the given WebAuthn credential to current account.
89
+ after_webauthn_auth_failure :: Any actions to take after a WebAuthn authentication failure.
90
+ after_webauthn_remove :: Any actions to take after removing an existing WebAuthn authenticator.
91
+ after_webauthn_setup :: Any actions to take after registering a new WebAuthn authenticator.
92
+ authenticated_webauthn_id :: The WebAuthn ID for the credential used to authenticate via WebAuthn for the current session.
93
+ before_webauthn_auth :: Any actions to take before authenticating via WebAuthn.
94
+ before_webauthn_auth_js_route :: Run arbitrary code before handling a webauthn auth javascript route.
95
+ before_webauthn_auth_route :: Run arbitrary code before handling a webauthn auth route.
96
+ before_webauthn_remove :: Any actions to take before removing an existing WebAuthn authenticator.
97
+ before_webauthn_remove_route :: Run arbitrary code before handling a webauthn remove route.
98
+ before_webauthn_setup :: Any actions to take before registering a new WebAuthn authenticator.
99
+ before_webauthn_setup_js_route :: Run arbitrary code before handling a webauthn setup javascript route.
100
+ before_webauthn_setup_route :: Run arbitrary code before handling a webauthn setup route.
101
+ handle_webauthn_sign_count_verification_error :: What actions to take if there is an invalid sign count when authenticating. The default results in an error, but overriding without calling super will result in successful WebAuthn authentication.
102
+ new_webauthn_credential :: WebAuthn credential options to provide to the client during WebAuthn registration.
103
+ remove_all_webauthn_keys_and_user_ids :: Remove all WebAuthn credentials and the WebAuthn user ID from the current account.
104
+ remove_webauthn_key(webauthn_id) :: Remove the WebAuthn credential with the given WebAuthn ID from the current account.
105
+ valid_new_webauthn_credential?(webauthn_credential) :: Check wheck the WebAuthn credential provided by the client during registration is valid.
106
+ valid_webauthn_credential_auth?(webauthn_credential) :: Check wheck the WebAuthn credential provided by the client during authentication is valid.
107
+ webauth_credential_options_for_get :: WebAuthn credential options to provide to the client during WebAuthn authentication.
108
+ webauthn_auth_js_path :: The path to the WebAuthn authentication javascript.
109
+ webauthn_auth_view :: The HTML to use for the page for authenticating via WebAuthn.
110
+ webauthn_remove_authenticated_session :: Remove the authenticated WebAuthn ID, used when removing the WebAuthn credential with the ID after authenticating with it.
111
+ webauthn_remove_view :: The HTML to use for the page for removing an existing WebAuthn authenticator.
112
+ webauthn_setup_js_path :: The path to the WebAuthn registration javascript.
113
+ webauthn_setup_view :: The HTML to use for the page for registering a new WebAuthn authenticator.
114
+ webauthn_update_session(webauthn_id) :: Set the authenticated WebAuthn ID after authenticating via WebAuthn.
115
+ webauthn_user_name :: The user name to use when registering a new WebAuthn credential, the user's email by default.
@@ -0,0 +1,15 @@
1
+ = Documentation for WebAuthn Login Feature
2
+
3
+ The webauthn feature implements passwordless authentication via
4
+ WebAuthn. It depends on the login and webauthn features.
5
+
6
+ == Auth Value Methods
7
+
8
+ webauthn_login_error_flash :: The flash error to show if there is a failure during passwordless login via WebAuthn.
9
+ webauthn_login_failure_redirect :: Whether to redirect if there is a failure during passwordless login via WebAuthn.
10
+ webauthn_login_route :: The route to the webauthn login action.
11
+
12
+ == Auth Methods
13
+
14
+ before_webauthn_login :: Any actions to take before passwordless login via WebAuthn.
15
+ before_webauthn_login_route :: Run arbitrary code before handling a webauthn login route.
@@ -0,0 +1,9 @@
1
+ = Documentation for WebAuthn Verify Account Feature
2
+
3
+ The webauthn feature implements setting up an WebAuthn authenticator
4
+ during the account verification process, and making such setup
5
+ a requirement for account verification. By default, it disables
6
+ asking for a password during account creation and verification,
7
+ allowing for completely passwordless designs, where the only
8
+ authentication option is WebAuthn. It depends on the verify_account
9
+ and webauthn features.
@@ -0,0 +1,45 @@
1
+ (function() {
2
+ var element = document.getElementById('webauthn-auth-form');
3
+ var f = function(e) {
4
+ //console.log(e);
5
+ e.preventDefault();
6
+ if (navigator.credentials) {
7
+ var opts = JSON.parse(element.getAttribute("data-credential-options"));
8
+ opts.challenge = Uint8Array.from(atob(opts.challenge.replace(/-/g, '+').replace(/_/g, '/')), c => c.charCodeAt(0));
9
+ opts.allowCredentials.forEach(function(cred) {
10
+ cred.id = Uint8Array.from(atob(cred.id.replace(/-/g, '+').replace(/_/g, '/')), c => c.charCodeAt(0));
11
+ });
12
+ //console.log(opts);
13
+ navigator.credentials.get({publicKey: opts}).
14
+ then(function(cred){
15
+ //console.log(cred);
16
+ //window.cred = cred
17
+
18
+ var rawId = btoa(String.fromCharCode.apply(null, new Uint8Array(cred.rawId))).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
19
+ var authValue = {
20
+ type: cred.type,
21
+ id: rawId,
22
+ rawId: rawId,
23
+ response: {
24
+ authenticatorData: btoa(String.fromCharCode.apply(null, new Uint8Array(cred.response.authenticatorData))).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, ''),
25
+ clientDataJSON: btoa(String.fromCharCode.apply(null, new Uint8Array(cred.response.clientDataJSON))).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, ''),
26
+ signature: btoa(String.fromCharCode.apply(null, new Uint8Array(cred.response.signature))).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '')
27
+ }
28
+ };
29
+
30
+ if (cred.response.userHandle) {
31
+ authValue.response.userHandle = btoa(String.fromCharCode.apply(null, new Uint8Array(cred.response.userHandle))).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
32
+ }
33
+
34
+ document.getElementById('webauthn-auth').value = JSON.stringify(authValue);
35
+ element.removeEventListener("submit", f);
36
+ element.submit();
37
+ }).
38
+ catch(function(e){document.getElementById('webauthn-auth-button').innerHTML = "Error authenticating using WebAuthn: " + e});
39
+ } else {
40
+ document.getElementById('webauthn-auth-button').innerHTML = "WebAuthn not supported by browser, or browser has disabled it on this page";
41
+ }
42
+ };
43
+ element.addEventListener("submit", f);
44
+ })();
45
+
@@ -0,0 +1,35 @@
1
+ (function() {
2
+ var element = document.getElementById('webauthn-setup-form');
3
+ var f = function(e) {
4
+ //console.log(e);
5
+ e.preventDefault();
6
+ if (navigator.credentials) {
7
+ var opts = JSON.parse(element.getAttribute("data-credential-options"));
8
+ opts.challenge = Uint8Array.from(atob(opts.challenge.replace(/-/g, '+').replace(/_/g, '/')), c => c.charCodeAt(0));
9
+ opts.user.id = Uint8Array.from(atob(opts.user.id.replace(/-/g, '+').replace(/_/g, '/')), c => c.charCodeAt(0));
10
+ //console.log(opts);
11
+ navigator.credentials.create({publicKey: opts}).
12
+ then(function(cred){
13
+ //console.log(cred);
14
+ //window.cred = cred
15
+
16
+ var rawId = btoa(String.fromCharCode.apply(null, new Uint8Array(cred.rawId))).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
17
+ document.getElementById('webauthn-setup').value = JSON.stringify({
18
+ type: cred.type,
19
+ id: rawId,
20
+ rawId: rawId,
21
+ response: {
22
+ attestationObject: btoa(String.fromCharCode.apply(null, new Uint8Array(cred.response.attestationObject))).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, ''),
23
+ clientDataJSON: btoa(String.fromCharCode.apply(null, new Uint8Array(cred.response.clientDataJSON))).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '')
24
+ }
25
+ });
26
+ element.removeEventListener("submit", f);
27
+ element.submit();
28
+ }).
29
+ catch(function(e){document.getElementById('webauthn-setup-button').innerHTML = "Error creating public key in authenticator: " + e});
30
+ } else {
31
+ document.getElementById('webauthn-setup-button').innerHTML = "WebAuthn not supported by browser, or browser has disabled it on this page";
32
+ }
33
+ };
34
+ element.addEventListener("submit", f);
35
+ })();
@@ -1,5 +1,5 @@
1
1
  # frozen-string-literal: true
2
2
 
3
- require 'rodauth'
3
+ require_relative '../../rodauth'
4
4
 
5
5
  Roda::RodaPlugins.register_plugin(:rodauth, Rodauth)
@@ -14,15 +14,15 @@ module Rodauth
14
14
  require 'tilt/string'
15
15
  app.plugin :render
16
16
 
17
- case opts.fetch(:csrf, app.opts[:rodauth_route_csrf])
17
+ case opts.fetch(:csrf, app.opts[:rodauth_csrf])
18
18
  when false
19
19
  # nothing
20
- when :route_csrf
21
- app.plugin :route_csrf
22
- else
20
+ when :rack_csrf
23
21
  # :nocov:
24
22
  app.plugin :csrf
25
23
  # :nocov:
24
+ else
25
+ app.plugin :route_csrf
26
26
  end
27
27
 
28
28
  app.plugin :flash unless opts[:flash] == false
@@ -31,8 +31,14 @@ module Rodauth
31
31
  end
32
32
 
33
33
  def self.configure(app, opts={}, &block)
34
- app.opts[:rodauth_json] = opts.fetch(:json, app.opts[:rodauth_json])
35
- app.opts[:rodauth_csrf] = opts.fetch(:csrf, app.opts[:rodauth_route_csrf])
34
+ json_opt = app.opts[:rodauth_json] = opts.fetch(:json, app.opts[:rodauth_json])
35
+ csrf = app.opts[:rodauth_csrf] = opts.fetch(:csrf, app.opts[:rodauth_csrf])
36
+ app.opts[:rodauth_route_csrf] = case csrf
37
+ when false, :rack_csrf
38
+ false
39
+ else
40
+ json_opt != :only
41
+ end
36
42
  auth_class = (app.opts[:rodauths] ||= {})[opts[:name]] ||= Class.new(Auth)
37
43
  if !auth_class.roda_class
38
44
  auth_class.roda_class = app
@@ -72,8 +78,7 @@ module Rodauth
72
78
  end
73
79
 
74
80
  def def_auth_value_method(meth, priv)
75
- define_method(meth) do |*v, &block|
76
- v = v.first
81
+ define_method(meth) do |v=nil, &block|
77
82
  block ||= proc{v}
78
83
  @auth.send(:define_method, meth, &block)
79
84
  @auth.send(:private, meth) if priv
@@ -104,23 +109,17 @@ module Rodauth
104
109
  route_meth = :"#{name}_route"
105
110
  auth_value_method route_meth, default
106
111
 
107
- define_method(:"#{name}_path") { route_path(send(route_meth)) }
108
- define_method(:"#{name}_url") { route_url(send(route_meth)) }
112
+ define_method(:"#{name}_path"){|opts={}| route_path(send(route_meth), opts)}
113
+ define_method(:"#{name}_url"){|opts={}| route_url(send(route_meth), opts)}
109
114
 
110
115
  handle_meth = :"handle_#{name}"
111
116
  internal_handle_meth = :"_#{handle_meth}"
112
117
  before route_meth
113
-
114
- unless block.arity == 1
115
- # :nocov:
116
- b = block
117
- block = lambda{|r| instance_exec(r, &b)}
118
- # :nocov:
119
- end
120
118
  define_method(internal_handle_meth, &block)
121
119
 
122
120
  define_method(handle_meth) do
123
121
  request.is send(route_meth) do
122
+ scope.check_csrf!(check_csrf_opts, &check_csrf_block) if check_csrf?
124
123
  before_rodauth
125
124
  send(internal_handle_meth, request)
126
125
  end
@@ -180,8 +179,10 @@ module Rodauth
180
179
 
181
180
  def view(page, title, name=feature_name)
182
181
  meth = :"#{name}_view"
182
+ title_meth = :"#{name}_page_title"
183
+ translatable_method(title_meth, title)
183
184
  define_method(meth) do
184
- view(page, title)
185
+ view(page, send(title_meth))
185
186
  end
186
187
  auth_methods meth
187
188
  end
@@ -190,6 +191,7 @@ module Rodauth
190
191
  define_method(:loaded_templates) do
191
192
  super().concat(v)
192
193
  end
194
+ private :loaded_templates
193
195
  end
194
196
 
195
197
  def depends(*deps)
@@ -197,10 +199,9 @@ module Rodauth
197
199
  end
198
200
 
199
201
  %w'after before'.each do |hook|
200
- define_method(hook) do |*args|
201
- name = args[0] || feature_name
202
+ define_method(hook) do |name=feature_name|
202
203
  meth = "#{hook}_#{name}"
203
- class_eval("def #{meth}; super if defined?(super); _#{meth} end", __FILE__, __LINE__)
204
+ class_eval("def #{meth}; super if defined?(super); _#{meth}; hook_action(:#{hook}, :#{name}); nil end", __FILE__, __LINE__)
204
205
  class_eval("def _#{meth}; nil end", __FILE__, __LINE__)
205
206
  private meth, :"_#{meth}"
206
207
  auth_private_methods(meth)
@@ -221,6 +222,11 @@ module Rodauth
221
222
  auth_value_methods(meth)
222
223
  end
223
224
 
225
+ def translatable_method(meth, value)
226
+ define_method(meth){translate(meth, value)}
227
+ auth_value_methods(meth)
228
+ end
229
+
224
230
  def auth_cached_method(meth, iv=:"@#{meth}")
225
231
  umeth = :"_#{meth}"
226
232
  define_method(meth) do
@@ -234,9 +240,8 @@ module Rodauth
234
240
  end
235
241
 
236
242
  [:notice_flash, :error_flash, :button].each do |meth|
237
- define_method(meth) do |v, *args|
238
- name = args.shift || feature_name
239
- auth_value_method(:"#{name}_#{meth}", v)
243
+ define_method(meth) do |v, name=feature_name|
244
+ translatable_method(:"#{name}_#{meth}", v)
240
245
  end
241
246
  end
242
247
  end