descope 1.0.5 → 1.0.7
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/.github/workflows/ci.yaml +2 -2
- data/.github/workflows/publish-gem.yaml +39 -7
- data/.gitignore +2 -0
- data/.ruby-version +1 -1
- data/Gemfile +7 -7
- data/Gemfile.lock +70 -65
- data/README.md +175 -52
- data/descope.gemspec +25 -20
- data/examples/ruby/.ruby-version +1 -0
- data/examples/ruby/access_key_app.rb +4 -3
- data/examples/ruby/enchantedlink_app.rb +1 -0
- data/examples/ruby/magiclink_app.rb +1 -0
- data/examples/ruby/management/.ruby-version +1 -0
- data/examples/ruby/management/Gemfile +2 -2
- data/examples/ruby/management/access_key_app.rb +2 -0
- data/examples/ruby/management/audit_app.rb +32 -8
- data/examples/ruby/management/authz_app.rb +1 -0
- data/examples/ruby/management/flow_app.rb +1 -0
- data/examples/ruby/management/permission_app.rb +3 -2
- data/examples/ruby/management/role_app.rb +3 -2
- data/examples/ruby/management/tenant_app.rb +1 -0
- data/examples/ruby/management/user_app.rb +1 -0
- data/examples/ruby/oauth_app.rb +1 -0
- data/examples/ruby/otp_app.rb +38 -12
- data/examples/ruby/password_app.rb +8 -7
- data/examples/ruby/saml_app.rb +1 -0
- data/examples/ruby/version_check.rb +17 -0
- data/examples/ruby-on-rails-api/descope/Gemfile +9 -7
- data/examples/ruby-on-rails-api/descope/Gemfile.lock +121 -90
- data/examples/ruby-on-rails-api/descope/README.md +18 -18
- data/examples/ruby-on-rails-api/descope/app/assets/builds/application.css +20092 -23
- data/examples/ruby-on-rails-api/descope/app/assets/builds/application.js +0 -1
- data/examples/ruby-on-rails-api/descope/app/assets/builds/components/index.js +0 -14
- data/examples/ruby-on-rails-api/descope/package-lock.json +1073 -19302
- data/examples/ruby-on-rails-api/descope/package.json +8 -16
- data/examples/ruby-on-rails-api/descope/yarn.lock +557 -10641
- data/lib/descope/api/v1/auth/enchantedlink.rb +3 -1
- data/lib/descope/api/v1/auth/magiclink.rb +3 -1
- data/lib/descope/api/v1/auth/otp.rb +24 -15
- data/lib/descope/api/v1/auth/password.rb +6 -2
- data/lib/descope/api/v1/auth/totp.rb +3 -1
- data/lib/descope/api/v1/auth.rb +64 -32
- data/lib/descope/api/v1/management/audit.rb +24 -0
- data/lib/descope/api/v1/management/common.rb +21 -5
- data/lib/descope/api/v1/management/sso_application.rb +236 -0
- data/lib/descope/api/v1/management/sso_settings.rb +2 -24
- data/lib/descope/api/v1/management/user.rb +151 -13
- data/lib/descope/api/v1/management.rb +2 -0
- data/lib/descope/api/v1/session.rb +37 -4
- data/lib/descope/mixins/common.rb +6 -2
- data/lib/descope/mixins/http.rb +60 -9
- data/lib/descope/mixins/initializer.rb +2 -1
- data/lib/descope/mixins/logging.rb +12 -4
- data/lib/descope/mixins/validation.rb +21 -6
- data/lib/descope/version.rb +1 -1
- data/spec/descope/api/v1/auth_spec.rb +29 -0
- data/spec/descope/api/v1/auth_token_extraction_spec.rb +126 -0
- data/spec/descope/api/v1/session_refresh_spec.rb +98 -0
- data/spec/factories/user.rb +1 -1
- data/spec/integration/lib.descope/api/v1/auth/enchantedlink_spec.rb +1 -1
- data/spec/integration/lib.descope/api/v1/auth/magiclink_spec.rb +1 -1
- data/spec/integration/lib.descope/api/v1/auth/otp_spec.rb +73 -8
- data/spec/integration/lib.descope/api/v1/auth/session_spec.rb +49 -0
- data/spec/integration/lib.descope/api/v1/auth/totp_spec.rb +1 -1
- data/spec/integration/lib.descope/api/v1/management/access_key_spec.rb +3 -0
- data/spec/integration/lib.descope/api/v1/management/audit_spec.rb +38 -0
- data/spec/integration/lib.descope/api/v1/management/authz_spec.rb +2 -0
- data/spec/integration/lib.descope/api/v1/management/flow_spec.rb +3 -1
- data/spec/integration/lib.descope/api/v1/management/permissions_spec.rb +4 -2
- data/spec/integration/lib.descope/api/v1/management/project_spec.rb +2 -0
- data/spec/integration/lib.descope/api/v1/management/roles_spec.rb +3 -1
- data/spec/integration/lib.descope/api/v1/management/user_spec.rb +55 -6
- data/spec/lib.descope/api/v1/auth/enchantedlink_spec.rb +11 -2
- data/spec/lib.descope/api/v1/auth/otp_spec.rb +176 -18
- data/spec/lib.descope/api/v1/auth/password_spec.rb +10 -1
- data/spec/lib.descope/api/v1/auth_spec.rb +168 -6
- data/spec/lib.descope/api/v1/cookie_domain_fix_integration_spec.rb +245 -0
- data/spec/lib.descope/api/v1/management/audit_spec.rb +92 -0
- data/spec/lib.descope/api/v1/management/sso_application_spec.rb +217 -0
- data/spec/lib.descope/api/v1/management/sso_settings_spec.rb +2 -2
- data/spec/lib.descope/api/v1/management/user_spec.rb +134 -46
- data/spec/lib.descope/api/v1/session_spec.rb +119 -6
- data/spec/lib.descope/mixins/http_spec.rb +218 -0
- data/spec/support/client_config.rb +0 -1
- data/spec/support/utils.rb +6 -0
- metadata +34 -137
- data/examples/ruby-on-rails-api/descope/app/assets/builds/reportWebVitals.js +0 -211
- data/examples/ruby-on-rails-api/descope/app/assets/builds/reportWebVitals.js.map +0 -7
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
+
require_relative '../version_check'
|
|
4
5
|
require 'descope'
|
|
5
6
|
|
|
6
7
|
@logger = Logger.new($stdout)
|
|
@@ -13,13 +14,36 @@ require 'descope'
|
|
|
13
14
|
@client = Descope::Client.new({ project_id: @project_id, management_key: @management_key })
|
|
14
15
|
|
|
15
16
|
begin
|
|
16
|
-
@logger.info('
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
@logger.info('Do you want to to create a new audit event? [y/n] ')
|
|
18
|
+
create_audit = gets.chomp
|
|
19
|
+
if create_audit == 'y'
|
|
20
|
+
@logger.info('Enter the action for the audit event: ')
|
|
21
|
+
action = gets.chomp
|
|
22
|
+
@logger.info('Enter the type for the audit event: [info/warn/error] ')
|
|
23
|
+
type = gets.chomp
|
|
24
|
+
@logger.info('Enter the actorId for the audit event: ')
|
|
25
|
+
actor_id = gets.chomp
|
|
26
|
+
@logger.info('Enter the tenantId for the audit event: ')
|
|
27
|
+
tenant_id = gets.chomp
|
|
28
|
+
res = @client.audit_create_event(
|
|
29
|
+
action: action,
|
|
30
|
+
type: type,
|
|
31
|
+
actor_id: actor_id,
|
|
32
|
+
tenant_id: tenant_id
|
|
33
|
+
)
|
|
34
|
+
@logger.info("Audit event created successfully: #{res}")
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
@logger.info('Do you want to search the audit trail? [y/n] ')
|
|
38
|
+
search_audit = gets.chomp
|
|
39
|
+
if search_audit == 'y'
|
|
40
|
+
@logger.info('Enter the text to search: ')
|
|
41
|
+
text = gets.chomp
|
|
42
|
+
@logger.info('Enter the from_ts in ISO8601 format (2024-01-01 15:00:00.000) to search: ')
|
|
43
|
+
from_ts = gets.chomp
|
|
44
|
+
res = @client.audit_search(text: text, from_ts: from_ts)
|
|
45
|
+
@logger.info("Audit search result: #{res}")
|
|
46
|
+
end
|
|
23
47
|
rescue Descope::AuthException => e
|
|
24
|
-
@logger.error("Audit
|
|
48
|
+
@logger.error("Audit action failed #{e}")
|
|
25
49
|
end
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
+
require_relative '../version_check'
|
|
4
5
|
require 'descope'
|
|
5
6
|
|
|
6
7
|
@logger = Logger.new($stdout)
|
|
@@ -15,7 +16,7 @@ require 'descope'
|
|
|
15
16
|
begin
|
|
16
17
|
@logger.info('Going to create a new permission')
|
|
17
18
|
name = 'My Permission'
|
|
18
|
-
@client.create_permission(name
|
|
19
|
+
@client.create_permission(name: name, description: 'Allowed to test')
|
|
19
20
|
|
|
20
21
|
rescue Descope::AuthException => e
|
|
21
22
|
@logger.info("Permission creation failed #{e}")
|
|
@@ -39,7 +40,7 @@ begin
|
|
|
39
40
|
# we mean to update.
|
|
40
41
|
name = 'My Permission'
|
|
41
42
|
@client.update_permission(
|
|
42
|
-
name
|
|
43
|
+
name: name, new_name: 'My Updated Permission', description: 'New Description'
|
|
43
44
|
)
|
|
44
45
|
|
|
45
46
|
rescue Descope::AuthException => e
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
+
require_relative '../version_check'
|
|
4
5
|
require 'descope'
|
|
5
6
|
|
|
6
7
|
@logger = Logger.new($stdout)
|
|
@@ -21,7 +22,7 @@ begin
|
|
|
21
22
|
tenant = @client.create_tenant(name: tenant_name)
|
|
22
23
|
@logger.info('Going to create a new role')
|
|
23
24
|
@client.create_role(
|
|
24
|
-
name
|
|
25
|
+
name: name, description: 'Allowed to test :)', permission_names: ['SSO Admin'], tenant_id: tenant['id']
|
|
25
26
|
)
|
|
26
27
|
rescue Descope::AuthException => e
|
|
27
28
|
@logger.info("Role creation failed #{e}")
|
|
@@ -42,7 +43,7 @@ end
|
|
|
42
43
|
begin
|
|
43
44
|
@logger.info('Updating newly created role')
|
|
44
45
|
@client.update_role(
|
|
45
|
-
name
|
|
46
|
+
name: name,
|
|
46
47
|
new_name: 'My Updated Role',
|
|
47
48
|
description: 'New Description',
|
|
48
49
|
permission_names: ['User Admin'],
|
data/examples/ruby/oauth_app.rb
CHANGED
data/examples/ruby/otp_app.rb
CHANGED
|
@@ -7,25 +7,51 @@ require 'descope'
|
|
|
7
7
|
|
|
8
8
|
@project_id = ENV['DESCOPE_PROJECT_ID']
|
|
9
9
|
@management_key = ENV['DESCOPE_MANAGEMENT_KEY']
|
|
10
|
-
|
|
11
|
-
@logger.info("Initializing Descope API with project_id: #{@project_id} and base_uri: #{@base_uri}")
|
|
12
|
-
|
|
13
10
|
@client = Descope::Client.new({ project_id: @project_id, management_key: @management_key })
|
|
11
|
+
@logger.info("Initializing Descope API with project_id: #{@project_id} and base_uri: #{@client.base_uri}")
|
|
14
12
|
|
|
15
13
|
begin
|
|
16
14
|
@logger.info('Going to signup or in using OTP...')
|
|
17
|
-
puts 'Please insert email to signup or in:\n'
|
|
18
|
-
email = gets.chomp
|
|
19
|
-
masked_email = @client.otp_sign_up_or_in(
|
|
20
|
-
method: Descope::Mixins::Common::DeliveryMethod::EMAIL, login_id: email
|
|
21
|
-
)
|
|
22
15
|
|
|
23
|
-
puts "Please
|
|
16
|
+
puts "Please select OTP method: [email, sms, voice]:\n"
|
|
17
|
+
method = gets.chomp
|
|
18
|
+
|
|
19
|
+
case method
|
|
20
|
+
when 'email'
|
|
21
|
+
requested_method = Descope::Mixins::Common::DeliveryMethod::EMAIL
|
|
22
|
+
puts "Please insert the email address you want to use:\n"
|
|
23
|
+
email = gets.chomp
|
|
24
|
+
requested_params = { login_id: email }
|
|
25
|
+
when 'sms'
|
|
26
|
+
requested_method = Descope::Mixins::Common::DeliveryMethod::SMS
|
|
27
|
+
@logger.info('Once signed up, we will use the update phone number')
|
|
28
|
+
puts "Please insert the phone number you want to use:\n"
|
|
29
|
+
phone = gets.chomp
|
|
30
|
+
requested_params = { login_id: phone }
|
|
31
|
+
when 'voice'
|
|
32
|
+
requested_method = Descope::Mixins::Common::DeliveryMethod::VOICE
|
|
33
|
+
@logger.info('Once signed up, we will use the update phone number')
|
|
34
|
+
puts "Please insert the phone number you want to use:\n"
|
|
35
|
+
phone = gets.chomp
|
|
36
|
+
requested_params = { login_id: phone }
|
|
37
|
+
else
|
|
38
|
+
raise 'Invalid method'
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
@logger.info("Signing up using OTP with #{method}...")
|
|
42
|
+
if method == 'email'
|
|
43
|
+
user = { login_id: email, name: 'John Doe', email: email, phone: phone }
|
|
44
|
+
login_id = email
|
|
45
|
+
masked_method = @client.otp_sign_up(method: requested_method, user: user, login_id: email, phone: phone)
|
|
46
|
+
else
|
|
47
|
+
login_id = phone
|
|
48
|
+
masked_method = @client.otp_sign_up_or_in(method: requested_method, login_id: phone)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
puts "Please insert the code you received by #{method} to #{masked_method}:\n"
|
|
24
52
|
value = gets.chomp
|
|
25
53
|
|
|
26
|
-
jwt_response = @client.otp_verify_code(
|
|
27
|
-
method: Descope::Mixins::Common::DeliveryMethod::EMAIL, login_id: email, code: value
|
|
28
|
-
)
|
|
54
|
+
jwt_response = @client.otp_verify_code(method: requested_method, login_id: login_id, code: value)
|
|
29
55
|
@logger.info('Code is valid')
|
|
30
56
|
puts "jwt_response: #{jwt_response}"
|
|
31
57
|
session_token = jwt_response[Descope::Mixins::Common::SESSION_TOKEN_NAME].fetch('jwt')
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
+
require_relative './version_check'
|
|
4
5
|
require 'descope'
|
|
5
6
|
|
|
6
7
|
@logger = Logger.new($stdout)
|
|
@@ -20,19 +21,19 @@ begin
|
|
|
20
21
|
puts 'Please insert password to signup with:\n'
|
|
21
22
|
password = gets.chomp
|
|
22
23
|
|
|
23
|
-
jwt_response = @client.password_sign_up(login_id: email, password:)
|
|
24
|
+
jwt_response = @client.password_sign_up(login_id: email, password: password)
|
|
24
25
|
@logger.info("Signup successful! jwt_response: #{jwt_response}")
|
|
25
26
|
puts "=> #{Descope::Mixins::Common::SESSION_TOKEN_NAME}"
|
|
26
27
|
session_token = jwt_response[Descope::Mixins::Common::SESSION_TOKEN_NAME].fetch('jwt')
|
|
27
28
|
refresh_token = jwt_response[Descope::Mixins::Common::REFRESH_SESSION_TOKEN_NAME].fetch('jwt')
|
|
28
29
|
|
|
29
30
|
@logger.info('Validating email address...')
|
|
30
|
-
@client.magiclink_update_user_email(login_id: email, email
|
|
31
|
+
@client.magiclink_update_user_email(login_id: email, email: email, refresh_token: refresh_token)
|
|
31
32
|
|
|
32
33
|
puts "Validation email send, please paste the token you received by email:\n"
|
|
33
34
|
token = gets.chomp
|
|
34
35
|
jwt_response = @client.magiclink_verify_token(token)
|
|
35
|
-
@logger.info(
|
|
36
|
+
@logger.info("Token verified successfully! #{jwt_response}")
|
|
36
37
|
session_token = jwt_response[Descope::Mixins::Common::SESSION_TOKEN_NAME].fetch('jwt')
|
|
37
38
|
refresh_token = jwt_response[Descope::Mixins::Common::REFRESH_SESSION_TOKEN_NAME].fetch('jwt')
|
|
38
39
|
|
|
@@ -48,7 +49,7 @@ begin
|
|
|
48
49
|
|
|
49
50
|
puts "Please insert new password:\n"
|
|
50
51
|
new_password = gets.chomp
|
|
51
|
-
@client.password_update(login_id: email, new_password
|
|
52
|
+
@client.password_update(login_id: email, new_password: new_password, refresh_token: refresh_token)
|
|
52
53
|
@logger.info('Attempting to sign in with new password...')
|
|
53
54
|
jwt_response = @client.password_sign_in(login_id: email, password: new_password)
|
|
54
55
|
session_token = jwt_response[Descope::Mixins::Common::SESSION_TOKEN_NAME].fetch('jwt')
|
|
@@ -56,15 +57,15 @@ begin
|
|
|
56
57
|
@logger.info("jwt_response: #{jwt_response}")
|
|
57
58
|
|
|
58
59
|
@logger.info('going to validate session...')
|
|
59
|
-
@client.validate_session(session_token:)
|
|
60
|
+
@client.validate_session(session_token: session_token)
|
|
60
61
|
@logger.info('Session validated successfully and all is OK!')
|
|
61
62
|
|
|
62
63
|
@logger.info('refreshing the session token...')
|
|
63
|
-
claims = @client.refresh_session(refresh_token:)
|
|
64
|
+
claims = @client.refresh_session(refresh_token: refresh_token)
|
|
64
65
|
@logger.info('going to revalidate the session with the newly refreshed token...')
|
|
65
66
|
|
|
66
67
|
new_session_token = claims[Descope::Mixins::Common::SESSION_TOKEN_NAME].fetch('jwt')
|
|
67
|
-
@client.validate_and_refresh_session(session_token: new_session_token, refresh_token:)
|
|
68
|
+
@client.validate_and_refresh_session(session_token: new_session_token, refresh_token: refresh_token)
|
|
68
69
|
@logger.info('Session is also valid for the refreshed token.')
|
|
69
70
|
|
|
70
71
|
@logger.info('going to sign out...')
|
data/examples/ruby/saml_app.rb
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
required_version = File.read('.ruby-version').strip
|
|
4
|
+
|
|
5
|
+
begin
|
|
6
|
+
# Check the Ruby version using RUBY_VERSION constant
|
|
7
|
+
current_version = RUBY_VERSION
|
|
8
|
+
|
|
9
|
+
# Compare major, minor and patch versions
|
|
10
|
+
if current_version.split('.').map(&:to_i) != required_version.split('.').map(&:to_i)
|
|
11
|
+
raise StandardError, "Script requires Ruby version #{required_version} but found #{current_version}"
|
|
12
|
+
end
|
|
13
|
+
rescue StandardError => e
|
|
14
|
+
puts "Error: #{e}"
|
|
15
|
+
puts "Script cannot run with incompatible Ruby version. Please install version #{required_version}."
|
|
16
|
+
exit(1) # Exit with an error code
|
|
17
|
+
end
|
|
@@ -3,12 +3,12 @@ source "https://rubygems.org"
|
|
|
3
3
|
ruby "3.3.0"
|
|
4
4
|
|
|
5
5
|
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
|
|
6
|
-
gem "rails", "~> 7.1.3"
|
|
6
|
+
gem "rails", "~> 7.1.3.3"
|
|
7
7
|
|
|
8
8
|
gem 'descope', path: '../../../..'
|
|
9
9
|
|
|
10
10
|
# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
|
|
11
|
-
gem "sprockets-rails"
|
|
11
|
+
gem "sprockets-rails", ">= 3.5.0"
|
|
12
12
|
|
|
13
13
|
# Use sqlite3 as the database for Active Record
|
|
14
14
|
gem "sqlite3", "~> 1.4"
|
|
@@ -17,19 +17,19 @@ gem "sqlite3", "~> 1.4"
|
|
|
17
17
|
gem "puma", ">= 5.0"
|
|
18
18
|
|
|
19
19
|
# Bundle and transpile JavaScript [https://github.com/rails/jsbundling-rails]
|
|
20
|
-
gem "jsbundling-rails"
|
|
20
|
+
gem "jsbundling-rails", ">= 1.3.1"
|
|
21
21
|
|
|
22
22
|
# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
|
|
23
|
-
gem "turbo-rails"
|
|
23
|
+
gem "turbo-rails", ">= 2.0.6"
|
|
24
24
|
|
|
25
25
|
# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
|
|
26
|
-
gem "stimulus-rails"
|
|
26
|
+
gem "stimulus-rails", ">= 1.3.4"
|
|
27
27
|
|
|
28
28
|
# Bundle and process CSS [https://github.com/rails/cssbundling-rails]
|
|
29
|
-
gem "cssbundling-rails"
|
|
29
|
+
gem "cssbundling-rails", ">= 1.4.1"
|
|
30
30
|
|
|
31
31
|
# Build JSON APIs with ease [https://github.com/rails/jbuilder]
|
|
32
|
-
gem "jbuilder"
|
|
32
|
+
gem "jbuilder", ">= 2.12.0"
|
|
33
33
|
|
|
34
34
|
# Use Redis adapter to run Action Cable in production
|
|
35
35
|
# gem "redis", ">= 4.0.1"
|
|
@@ -63,5 +63,7 @@ group :development do
|
|
|
63
63
|
|
|
64
64
|
# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
|
|
65
65
|
# gem "spring"
|
|
66
|
+
gem 'rubocop-rails', '2.25.0', require: false
|
|
67
|
+
gem "rdoc", ">= 6.6.3.1", require: false
|
|
66
68
|
end
|
|
67
69
|
|