standard_id 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +10 -3
- data/app/models/standard_id/client_application.rb +2 -1
- data/lib/generators/standard_id/install/templates/standard_id.rb +5 -0
- data/lib/standard_id/config/schema.rb +1 -0
- data/lib/standard_id/oauth/client_credentials_flow.rb +1 -5
- data/lib/standard_id/oauth/implicit_authorization_flow.rb +1 -1
- data/lib/standard_id/oauth/password_flow.rb +0 -4
- data/lib/standard_id/oauth/passwordless_otp_flow.rb +0 -4
- data/lib/standard_id/oauth/token_grant_flow.rb +6 -2
- data/lib/standard_id/oauth/token_lifetime_resolver.rb +50 -0
- data/lib/standard_id/version.rb +1 -1
- data/lib/standard_id.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d8da5350b060ff2f0494489d5cc6718cc08b2dbca835a9c28927e228b712e39d
|
|
4
|
+
data.tar.gz: 96ac14f364fd07b8d6750d31bd015b7bc2717d692206a203b3fe8161a6a1008f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 195c91598a768df91279b0c6bda4d8b312f73a94d4c52c68b2864fd75453f2c474059c4f7d740e0d8c0b4086471ea193c9ded4bb7b492f3c098c950f941f6140
|
|
7
|
+
data.tar.gz: 80d64202a7b69456e241952b79f0a65ea9a88ed8b242ff31015e11854d141bd32ccbeaccc2f60ccddf78d188dbbec74e48f839c9181a2b4cdce01917001e4125
|
data/README.md
CHANGED
|
@@ -87,12 +87,12 @@ end
|
|
|
87
87
|
```ruby
|
|
88
88
|
# For web controllers
|
|
89
89
|
class ApplicationController < ActionController::Base
|
|
90
|
-
include StandardId::
|
|
90
|
+
include StandardId::WebAuthentication
|
|
91
91
|
end
|
|
92
92
|
|
|
93
93
|
# For API controllers
|
|
94
94
|
class ApiController < ActionController::API
|
|
95
|
-
include StandardId::
|
|
95
|
+
include StandardId::ApiAuthentication
|
|
96
96
|
end
|
|
97
97
|
```
|
|
98
98
|
|
|
@@ -123,9 +123,16 @@ StandardId.configure do |config|
|
|
|
123
123
|
# config.password.require_special_chars = true
|
|
124
124
|
# config.passwordless.code_ttl = 600
|
|
125
125
|
# config.oauth.default_token_lifetime = 3600
|
|
126
|
+
# config.oauth.refresh_token_lifetime = 2_592_000
|
|
127
|
+
# config.oauth.token_lifetimes = {
|
|
128
|
+
# password: 8.hours.to_i,
|
|
129
|
+
# implicit: 15.minutes.to_i
|
|
130
|
+
# }
|
|
126
131
|
end
|
|
127
132
|
```
|
|
128
133
|
|
|
134
|
+
`default_token_lifetime` is applied to every OAuth grant unless you override it in `oauth.token_lifetimes`. Keys map to OAuth grant types (for example `:password`, `:client_credentials`, `:refresh_token`) and should return durations in seconds. Non-token endpoint flows such as the implicit flow can be customized with their symbol key (e.g. `:implicit`). Refresh tokens can be tuned separately through `oauth.refresh_token_lifetime`.
|
|
135
|
+
|
|
129
136
|
### Social Login Setup
|
|
130
137
|
|
|
131
138
|
```ruby
|
|
@@ -274,7 +281,7 @@ StandardId creates the following tables:
|
|
|
274
281
|
|
|
275
282
|
```ruby
|
|
276
283
|
# Create OAuth client
|
|
277
|
-
client = StandardId::
|
|
284
|
+
client = StandardId::ClientApplication.create!(
|
|
278
285
|
owner: current_account,
|
|
279
286
|
name: "My Application",
|
|
280
287
|
redirect_uris: "https://app.com/callback",
|
|
@@ -16,6 +16,11 @@ StandardId.configure do |c|
|
|
|
16
16
|
# c.password.minimum_length = 8
|
|
17
17
|
# c.password.require_special_chars = true
|
|
18
18
|
# c.oauth.default_token_lifetime = 3600 # 1 hour
|
|
19
|
+
# c.oauth.refresh_token_lifetime = 2_592_000 # 30 days
|
|
20
|
+
# c.oauth.token_lifetimes = {
|
|
21
|
+
# password: 8.hours,
|
|
22
|
+
# client_credentials: 24.hours
|
|
23
|
+
# }
|
|
19
24
|
|
|
20
25
|
# Social login credentials (if enabled in your app)
|
|
21
26
|
# c.social.google_client_id = ENV["GOOGLE_CLIENT_ID"]
|
|
@@ -32,6 +32,7 @@ StandardConfig.schema.draw do
|
|
|
32
32
|
scope :oauth do
|
|
33
33
|
field :default_token_lifetime, type: :integer, default: 3600 # 1 hour in seconds
|
|
34
34
|
field :refresh_token_lifetime, type: :integer, default: 2592000 # 30 days in seconds
|
|
35
|
+
field :token_lifetimes, type: :hash, default: -> { {} }
|
|
35
36
|
field :client_id, type: :string, default: nil
|
|
36
37
|
field :client_secret, type: :string, default: nil
|
|
37
38
|
end
|
|
@@ -11,7 +11,7 @@ module StandardId
|
|
|
11
11
|
private
|
|
12
12
|
|
|
13
13
|
def subject_id
|
|
14
|
-
@credential.
|
|
14
|
+
@credential.client_id
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def client_id
|
|
@@ -29,10 +29,6 @@ module StandardId
|
|
|
29
29
|
def audience
|
|
30
30
|
params[:audience]
|
|
31
31
|
end
|
|
32
|
-
|
|
33
|
-
def token_expiry
|
|
34
|
-
1.hour
|
|
35
|
-
end
|
|
36
32
|
end
|
|
37
33
|
end
|
|
38
34
|
end
|
|
@@ -62,7 +62,7 @@ module StandardId
|
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
def token_expiry
|
|
65
|
-
|
|
65
|
+
TokenLifetimeResolver.access_token_for(token_lifetime_key)
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
def supports_refresh_token?
|
|
@@ -80,7 +80,11 @@ module StandardId
|
|
|
80
80
|
end
|
|
81
81
|
|
|
82
82
|
def refresh_token_expiry
|
|
83
|
-
|
|
83
|
+
TokenLifetimeResolver.refresh_token_lifetime
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def token_lifetime_key
|
|
87
|
+
grant_type&.to_sym
|
|
84
88
|
end
|
|
85
89
|
|
|
86
90
|
def subject_id
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
module StandardId
|
|
2
|
+
module Oauth
|
|
3
|
+
class TokenLifetimeResolver
|
|
4
|
+
class << self
|
|
5
|
+
DEFAULT_ACCESS_TOKEN_LIFETIME = 1.hour.to_i
|
|
6
|
+
DEFAULT_REFRESH_TOKEN_LIFETIME = 30.days.to_i
|
|
7
|
+
|
|
8
|
+
def access_token_for(flow_key)
|
|
9
|
+
configured = lookup_token_lifetime(flow_key)
|
|
10
|
+
positive_seconds(configured, default_access_token_lifetime)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def refresh_token_lifetime
|
|
14
|
+
positive_seconds(oauth_config.refresh_token_lifetime, DEFAULT_REFRESH_TOKEN_LIFETIME)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
def default_access_token_lifetime
|
|
20
|
+
positive_seconds(oauth_config.default_token_lifetime, DEFAULT_ACCESS_TOKEN_LIFETIME)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def lookup_token_lifetime(flow_key)
|
|
24
|
+
config = oauth_config
|
|
25
|
+
return nil unless config.respond_to?(:token_lifetimes)
|
|
26
|
+
|
|
27
|
+
lifetimes = config.token_lifetimes || {}
|
|
28
|
+
lifetimes[flow_key.to_sym] || lifetimes[flow_key.to_s] if flow_key
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def positive_seconds(value, fallback_value)
|
|
32
|
+
normalized_value = case value
|
|
33
|
+
when ActiveSupport::Duration
|
|
34
|
+
value.to_i
|
|
35
|
+
when Numeric, String
|
|
36
|
+
value.to_i
|
|
37
|
+
else
|
|
38
|
+
0
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
(normalized_value.positive? ? normalized_value : fallback_value).seconds
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def oauth_config
|
|
45
|
+
StandardId.config.oauth
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
data/lib/standard_id/version.rb
CHANGED
data/lib/standard_id.rb
CHANGED
|
@@ -12,6 +12,7 @@ require "standard_id/api/session_manager"
|
|
|
12
12
|
require "standard_id/api/token_manager"
|
|
13
13
|
require "standard_id/api/authentication_guard"
|
|
14
14
|
require "standard_id/oauth/base_request_flow"
|
|
15
|
+
require "standard_id/oauth/token_lifetime_resolver"
|
|
15
16
|
require "standard_id/oauth/token_grant_flow"
|
|
16
17
|
require "standard_id/oauth/client_credentials_flow"
|
|
17
18
|
require "standard_id/oauth/authorization_code_flow"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: standard_id
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jaryl Sim
|
|
@@ -160,6 +160,7 @@ files:
|
|
|
160
160
|
- lib/standard_id/oauth/subflows/social_login_grant.rb
|
|
161
161
|
- lib/standard_id/oauth/subflows/traditional_code_grant.rb
|
|
162
162
|
- lib/standard_id/oauth/token_grant_flow.rb
|
|
163
|
+
- lib/standard_id/oauth/token_lifetime_resolver.rb
|
|
163
164
|
- lib/standard_id/passwordless/base_strategy.rb
|
|
164
165
|
- lib/standard_id/passwordless/email_strategy.rb
|
|
165
166
|
- lib/standard_id/passwordless/sms_strategy.rb
|