Class: PasskeysRails::PasskeysController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- PasskeysRails::PasskeysController
- Defined in:
- app/controllers/passkeys_rails/passkeys_controller.rb
Instance Method Summary collapse
- #authenticate ⇒ Object
- #challenge ⇒ Object
-
#debug_login ⇒ Object
This action exists to allow easier mobile app debugging as it may not be possible to acess Passkey functionality in mobile simulators.
-
#debug_register ⇒ Object
This action exists to allow easier mobile app debugging as it may not be possible to acess Passkey functionality in mobile simulators.
- #refresh ⇒ Object
- #register ⇒ Object
Instance Method Details
#authenticate ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/passkeys_rails/passkeys_controller.rb', line 33 def authenticate = JSON.parse(.signed["passkeys_rails"] || "{}") result = PasskeysRails::FinishAuthentication.call!(credential: authentication_params.to_h, challenge: ["challenge"]) broadcast(:did_authenticate, agent: result.agent) render json: auth_response(result) end |
#challenge ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/controllers/passkeys_rails/passkeys_controller.rb', line 6 def challenge result = PasskeysRails::BeginChallenge.call!(username: challenge_params[:username]) # Store the challenge so we can verify the future register or authentication request .signed[:passkeys_rails] = { value: result..to_json, expire: Time.now.utc + (result.response.timeout / 1000), secure: true, httponly: true, same_site: :strict } render json: result.response.as_json end |
#debug_login ⇒ Object
This action exists to allow easier mobile app debugging as it may not be possible to acess Passkey functionality in mobile simulators. It is only routable if DEBUG_LOGIN_REGEX is set in the server environment. CAUTION: It is very insecure to set DEBUG_LOGIN_REGEX in a production environment.
55 56 57 58 59 60 61 |
# File 'app/controllers/passkeys_rails/passkeys_controller.rb', line 55 def debug_login result = PasskeysRails::DebugLogin.call!(username: debug_login_params[:username]) broadcast(:did_authenticate, agent: result.agent) render json: auth_response(result) end |
#debug_register ⇒ Object
This action exists to allow easier mobile app debugging as it may not be possible to acess Passkey functionality in mobile simulators. It is only routable if DEBUG_LOGIN_REGEX is set in the server environment. CAUTION: It is very insecure to set DEBUG_LOGIN_REGEX in a production environment.
67 68 69 70 71 72 73 74 |
# File 'app/controllers/passkeys_rails/passkeys_controller.rb', line 67 def debug_register result = PasskeysRails::DebugRegister.call!(username: debug_login_params[:username], authenticatable_info: authenticatable_params&.to_h) broadcast(:did_register, agent: result.agent) render json: auth_response(result) end |
#refresh ⇒ Object
43 44 45 46 47 48 49 |
# File 'app/controllers/passkeys_rails/passkeys_controller.rb', line 43 def refresh result = PasskeysRails::RefreshToken.call!(token: refresh_params[:auth_token]) broadcast(:did_refresh, agent: result.agent) render json: auth_response(result) end |
#register ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/controllers/passkeys_rails/passkeys_controller.rb', line 21 def register = JSON.parse(.signed["passkeys_rails"] || "{}") result = PasskeysRails::FinishRegistration.call!(credential: attestation_credential_params.to_h, authenticatable_info: authenticatable_params&.to_h, username: ["username"], challenge: ["challenge"]) broadcast(:did_register, agent: result.agent) render json: auth_response(result) end |