You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+8-8Lines changed: 8 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -80,28 +80,28 @@ This will add the `config/initializers/passkeys_rails.rb` configuration file, pa
80
80
<aid="rails-Integration-standard"></a>
81
81
## Rails Integration <p><small>Adding to a standard rails project</small></p>
82
82
83
-
1. Add `before_action :authenticate_passkey!`
83
+
-###Add `before_action :authenticate_passkey!`
84
84
85
-
To prevent access to controller actions, add `before_action :authenticate_passkey!`. If an action is attempted without an authenticated entity, an error will be rendered in JSON with an :unauthorized result code.
85
+
To prevent access to controller actions, add `before_action :authenticate_passkey!`. If an action is attempted without an authenticated entity, an error will be rendered in JSON with an :unauthorized result code.
86
86
87
-
1. Use `current_agent` and `current_agent.authenticatable`
87
+
-###Use `current_agent` and `current_agent.authenticatable`
88
88
89
-
To access the currently authenticated entity, use `current_agent`. If you associated the registration of the agent with one of your own models, use `current_agent.authenticatable`. For example, if you associated the `User` class with the registration, `current_agent.authenticatable` will be a User object.
89
+
To access the currently authenticated entity, use `current_agent`. If you associated the registration of the agent with one of your own models, use `current_agent.authenticatable`. For example, if you associated the `User` class with the registration, `current_agent.authenticatable` will be a User object.
90
90
91
-
1. Add `include PasskeysRails::Authenticatable` to model class(es)
91
+
-###Add `include PasskeysRails::Authenticatable` to model class(es)
92
92
93
93
If you have one or more classes that you want to use with authentication - e.g. a User class and an AdminUser class - add `include PasskeysRails::Authenticatable` to each of those classes. That adds a `registered?` method that you can call on your model to determine if they are registerd with your service, and a `registering_with(params)` method that you can override to initialize attributes of your model when it is created during registration. `params` is a hash with params passed to the API when registering. When called, your object has been built, but not yet saved. Upon return, **PasskeysRails** will attempt to save your object before finishing registration. If it is not valid, the registration will fail as well, returning the error error details to the caller.
94
94
95
95
<aid="rails-Integration-grape"></a>
96
96
## Rails Integration - <p><small>Adding to a Grape API rails project</small></p>
97
97
98
-
1. Call `PasskeysRails.authenticate(request)` to authenticate the request.
98
+
-###Call `PasskeysRails.authenticate(request)` to authenticate the request.
99
99
100
100
Call `PasskeysRails.authenticate(request)` to get an object back that responds to `.success?` and `.failure?` as well as `.agent`, `.code`, and `.message`.
101
101
102
102
Alternatively, call `PasskeysRails.authenticate!(request)` from a helper in your base class. It will raise a `PasskeysRails.Error` exception if the caller isn't authenticated. You can catch the exception and render an appropriate error. The exception contains the error code and message.
103
103
104
-
1. Consider adding the following helpers to your base API class:
104
+
-###Consider adding the following helpers to your base API class:
105
105
106
106
```ruby
107
107
helpers do
@@ -130,7 +130,7 @@ This will add the `config/initializers/passkeys_rails.rb` configuration file, pa
130
130
131
131
To prevent access to various endpoints, add `before_action :authenticate_passkey!` or call `authenticate_passkey!` from any method that requires authentication. If an action is attempted without an authenticated entity, an error will be rendered in JSON with an :unauthorized result code.
132
132
133
-
1. Use `current_agent` and `current_agent.authenticatable`
133
+
-###Use `current_agent` and `current_agent.authenticatable`
134
134
135
135
To access the currently authenticated entity, use `current_agent`. If you associated the registration of the agent with one of your own models, use `current_agent.authenticatable`. For example, if you associated the `User` class with the registration, `current_agent.authenticatable` will be a User object.
0 commit comments