standard_id 0.3.2 → 0.4.0
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/app/controllers/concerns/standard_id/controller_policy.rb +99 -0
- data/app/controllers/standard_id/api/authorization_controller.rb +2 -0
- data/app/controllers/standard_id/api/base_controller.rb +1 -0
- data/app/controllers/standard_id/api/oauth/callback/providers_controller.rb +2 -0
- data/app/controllers/standard_id/api/oauth/tokens_controller.rb +2 -0
- data/app/controllers/standard_id/api/oidc/logout_controller.rb +2 -0
- data/app/controllers/standard_id/api/passwordless_controller.rb +2 -0
- data/app/controllers/standard_id/api/userinfo_controller.rb +2 -0
- data/app/controllers/standard_id/api/well_known/jwks_controller.rb +6 -0
- data/app/controllers/standard_id/web/account_controller.rb +2 -0
- data/app/controllers/standard_id/web/auth/callback/providers_controller.rb +2 -0
- data/app/controllers/standard_id/web/base_controller.rb +1 -0
- data/app/controllers/standard_id/web/login_controller.rb +2 -0
- data/app/controllers/standard_id/web/login_verify_controller.rb +12 -84
- data/app/controllers/standard_id/web/logout_controller.rb +7 -0
- data/app/controllers/standard_id/web/reset_password/confirm_controller.rb +2 -0
- data/app/controllers/standard_id/web/reset_password/start_controller.rb +2 -0
- data/app/controllers/standard_id/web/sessions_controller.rb +2 -0
- data/app/controllers/standard_id/web/signup_controller.rb +2 -0
- data/app/controllers/standard_id/web/verify_email/base_controller.rb +2 -0
- data/app/controllers/standard_id/web/verify_phone/base_controller.rb +2 -0
- data/lib/standard_id/authorization_bypass.rb +121 -0
- data/lib/standard_id/jwt_service.rb +41 -15
- data/lib/standard_id/oauth/password_flow.rb +5 -1
- data/lib/standard_id/oauth/passwordless_otp_flow.rb +10 -61
- data/lib/standard_id/passwordless/verification_service.rb +227 -0
- data/lib/standard_id/testing/authentication_helpers.rb +75 -0
- data/lib/standard_id/testing/factories/credentials.rb +24 -0
- data/lib/standard_id/testing/factories/identifiers.rb +37 -0
- data/lib/standard_id/testing/factories/oauth.rb +89 -0
- data/lib/standard_id/testing/factories/sessions.rb +112 -0
- data/lib/standard_id/testing/factory_bot.rb +7 -0
- data/lib/standard_id/testing/request_helpers.rb +60 -0
- data/lib/standard_id/testing.rb +26 -0
- data/lib/standard_id/version.rb +1 -1
- data/lib/standard_id.rb +6 -0
- metadata +40 -1
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
module StandardId
|
|
2
|
+
module Testing
|
|
3
|
+
# Integration test helpers for signing in accounts and making authenticated requests.
|
|
4
|
+
#
|
|
5
|
+
# Usage in rails_helper.rb:
|
|
6
|
+
#
|
|
7
|
+
# require "standard_id/testing"
|
|
8
|
+
#
|
|
9
|
+
# RSpec.configure do |config|
|
|
10
|
+
# config.include StandardId::Testing::RequestHelpers, type: :request
|
|
11
|
+
# end
|
|
12
|
+
#
|
|
13
|
+
module RequestHelpers
|
|
14
|
+
# Create a browser session record for integration tests.
|
|
15
|
+
#
|
|
16
|
+
# For a simpler approach, use stub_web_authentication from AuthenticationHelpers instead.
|
|
17
|
+
#
|
|
18
|
+
# @param account [Object] the account to sign in
|
|
19
|
+
# @param user_agent [String] the user agent string (default: "RSpec")
|
|
20
|
+
# @return [StandardId::BrowserSession] the created session
|
|
21
|
+
#
|
|
22
|
+
def create_browser_session(account, user_agent: "RSpec")
|
|
23
|
+
StandardId::BrowserSession.create!(
|
|
24
|
+
account: account,
|
|
25
|
+
ip_address: "127.0.0.1",
|
|
26
|
+
user_agent: user_agent,
|
|
27
|
+
expires_at: StandardId::BrowserSession.expiry
|
|
28
|
+
)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Build a JWT token for API/service authentication.
|
|
32
|
+
#
|
|
33
|
+
# @param account [Object, nil] account (uses account.id as sub claim)
|
|
34
|
+
# @param sub [String, nil] explicit subject claim (overrides account.id)
|
|
35
|
+
# @param client_id [String] OAuth client ID
|
|
36
|
+
# @param scope [String] space-separated scopes
|
|
37
|
+
# @param grant_type [String] OAuth grant type
|
|
38
|
+
# @param extra [Hash] additional JWT claims
|
|
39
|
+
# @return [String] encoded JWT token
|
|
40
|
+
#
|
|
41
|
+
def build_jwt(account: nil, sub: nil, client_id: "test-client",
|
|
42
|
+
scope: "openid", grant_type: "authorization_code", extra: {})
|
|
43
|
+
sub ||= account&.id
|
|
44
|
+
raise ArgumentError, "account or sub must be provided" if sub.nil?
|
|
45
|
+
|
|
46
|
+
claims = { sub: sub, client_id: client_id, scope: scope, grant_type: grant_type }.merge(extra)
|
|
47
|
+
StandardId::JwtService.encode(claims)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Returns an Authorization header hash for Bearer token authentication.
|
|
51
|
+
#
|
|
52
|
+
# @param token [String] the JWT token
|
|
53
|
+
# @return [Hash] header hash
|
|
54
|
+
#
|
|
55
|
+
def bearer_auth_header(token)
|
|
56
|
+
{ "Authorization" => "Bearer #{token}" }
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require "standard_id/testing/authentication_helpers"
|
|
2
|
+
require "standard_id/testing/request_helpers"
|
|
3
|
+
|
|
4
|
+
module StandardId
|
|
5
|
+
module Testing
|
|
6
|
+
# Load StandardId's FactoryBot factory definitions.
|
|
7
|
+
#
|
|
8
|
+
# Requires the `factory_bot` (or `factory_bot_rails`) gem in the host app's
|
|
9
|
+
# Gemfile under the :test group.
|
|
10
|
+
#
|
|
11
|
+
# Recommended usage in rails_helper.rb:
|
|
12
|
+
#
|
|
13
|
+
# require "standard_id/testing"
|
|
14
|
+
# StandardId::Testing.setup_factory_bot!
|
|
15
|
+
#
|
|
16
|
+
def self.setup_factory_bot!
|
|
17
|
+
require "standard_id/testing/factory_bot"
|
|
18
|
+
rescue LoadError => e
|
|
19
|
+
raise unless e.message.include?("factory_bot")
|
|
20
|
+
|
|
21
|
+
raise LoadError,
|
|
22
|
+
"StandardId::Testing.setup_factory_bot! requires the `factory_bot` gem. " \
|
|
23
|
+
"Add `gem 'factory_bot_rails'` (or `gem 'factory_bot'`) to your Gemfile's :test group."
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
data/lib/standard_id/version.rb
CHANGED
data/lib/standard_id.rb
CHANGED
|
@@ -39,6 +39,8 @@ require "standard_id/oauth/passwordless_otp_flow"
|
|
|
39
39
|
require "standard_id/passwordless/base_strategy"
|
|
40
40
|
require "standard_id/passwordless/email_strategy"
|
|
41
41
|
require "standard_id/passwordless/sms_strategy"
|
|
42
|
+
require "standard_id/passwordless/verification_service"
|
|
43
|
+
require "standard_id/authorization_bypass"
|
|
42
44
|
require "standard_id/utils/callable_parameter_filter"
|
|
43
45
|
require "standard_id/utils/ip_normalizer"
|
|
44
46
|
|
|
@@ -75,5 +77,9 @@ module StandardId
|
|
|
75
77
|
def account_class
|
|
76
78
|
config.account_class_name.constantize
|
|
77
79
|
end
|
|
80
|
+
|
|
81
|
+
def skip_host_authorization(framework: nil, callback: nil)
|
|
82
|
+
AuthorizationBypass.apply(framework: framework, callback: callback)
|
|
83
|
+
end
|
|
78
84
|
end
|
|
79
85
|
end
|
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.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jaryl Sim
|
|
@@ -65,6 +65,34 @@ dependencies:
|
|
|
65
65
|
- - ">="
|
|
66
66
|
- !ruby/object:Gem::Version
|
|
67
67
|
version: '0'
|
|
68
|
+
- !ruby/object:Gem::Dependency
|
|
69
|
+
name: concurrent-ruby
|
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - "~>"
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '1.3'
|
|
75
|
+
type: :runtime
|
|
76
|
+
prerelease: false
|
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - "~>"
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '1.3'
|
|
82
|
+
- !ruby/object:Gem::Dependency
|
|
83
|
+
name: factory_bot
|
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - "~>"
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '6.5'
|
|
89
|
+
type: :development
|
|
90
|
+
prerelease: false
|
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - "~>"
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: '6.5'
|
|
68
96
|
description: StandardId is an authentication engine that provides a complete, secure-by-default
|
|
69
97
|
solution for identity management, reducing boilerplate and eliminating common security
|
|
70
98
|
pitfalls.
|
|
@@ -81,6 +109,7 @@ files:
|
|
|
81
109
|
- app/channels/concerns/standard_id/cable_authentication.rb
|
|
82
110
|
- app/controllers/concerns/standard_id/api_authentication.rb
|
|
83
111
|
- app/controllers/concerns/standard_id/audience_verification.rb
|
|
112
|
+
- app/controllers/concerns/standard_id/controller_policy.rb
|
|
84
113
|
- app/controllers/concerns/standard_id/inertia_rendering.rb
|
|
85
114
|
- app/controllers/concerns/standard_id/inertia_support.rb
|
|
86
115
|
- app/controllers/concerns/standard_id/passwordless_strategy.rb
|
|
@@ -174,6 +203,7 @@ files:
|
|
|
174
203
|
- lib/standard_id/api/session_manager.rb
|
|
175
204
|
- lib/standard_id/api/token_manager.rb
|
|
176
205
|
- lib/standard_id/api_engine.rb
|
|
206
|
+
- lib/standard_id/authorization_bypass.rb
|
|
177
207
|
- lib/standard_id/bearer_token_extraction.rb
|
|
178
208
|
- lib/standard_id/config/schema.rb
|
|
179
209
|
- lib/standard_id/current_attributes.rb
|
|
@@ -206,8 +236,17 @@ files:
|
|
|
206
236
|
- lib/standard_id/passwordless/base_strategy.rb
|
|
207
237
|
- lib/standard_id/passwordless/email_strategy.rb
|
|
208
238
|
- lib/standard_id/passwordless/sms_strategy.rb
|
|
239
|
+
- lib/standard_id/passwordless/verification_service.rb
|
|
209
240
|
- lib/standard_id/provider_registry.rb
|
|
210
241
|
- lib/standard_id/providers/base.rb
|
|
242
|
+
- lib/standard_id/testing.rb
|
|
243
|
+
- lib/standard_id/testing/authentication_helpers.rb
|
|
244
|
+
- lib/standard_id/testing/factories/credentials.rb
|
|
245
|
+
- lib/standard_id/testing/factories/identifiers.rb
|
|
246
|
+
- lib/standard_id/testing/factories/oauth.rb
|
|
247
|
+
- lib/standard_id/testing/factories/sessions.rb
|
|
248
|
+
- lib/standard_id/testing/factory_bot.rb
|
|
249
|
+
- lib/standard_id/testing/request_helpers.rb
|
|
211
250
|
- lib/standard_id/utils/callable_parameter_filter.rb
|
|
212
251
|
- lib/standard_id/utils/ip_normalizer.rb
|
|
213
252
|
- lib/standard_id/version.rb
|