descope 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/publish-gem.yaml +30 -5
  3. data/Gemfile +3 -3
  4. data/Gemfile.lock +12 -20
  5. data/README.md +18 -3
  6. data/descope.gemspec +25 -20
  7. data/examples/ruby/.ruby-version +1 -0
  8. data/examples/ruby/access_key_app.rb +4 -3
  9. data/examples/ruby/enchantedlink_app.rb +1 -0
  10. data/examples/ruby/magiclink_app.rb +1 -0
  11. data/examples/ruby/management/.ruby-version +1 -0
  12. data/examples/ruby/management/Gemfile +2 -2
  13. data/examples/ruby/management/access_key_app.rb +2 -0
  14. data/examples/ruby/management/audit_app.rb +32 -8
  15. data/examples/ruby/management/authz_app.rb +1 -0
  16. data/examples/ruby/management/flow_app.rb +1 -0
  17. data/examples/ruby/management/permission_app.rb +3 -2
  18. data/examples/ruby/management/role_app.rb +3 -2
  19. data/examples/ruby/management/tenant_app.rb +1 -0
  20. data/examples/ruby/management/user_app.rb +1 -0
  21. data/examples/ruby/oauth_app.rb +1 -0
  22. data/examples/ruby/otp_app.rb +38 -12
  23. data/examples/ruby/password_app.rb +8 -7
  24. data/examples/ruby/saml_app.rb +1 -0
  25. data/examples/ruby/version_check.rb +17 -0
  26. data/examples/ruby-on-rails-api/descope/Gemfile +3 -1
  27. data/examples/ruby-on-rails-api/descope/Gemfile.lock +121 -90
  28. data/examples/ruby-on-rails-api/descope/README.md +18 -18
  29. data/examples/ruby-on-rails-api/descope/app/assets/builds/application.css +20092 -23
  30. data/examples/ruby-on-rails-api/descope/app/assets/builds/application.js +0 -1
  31. data/examples/ruby-on-rails-api/descope/app/assets/builds/components/index.js +0 -14
  32. data/examples/ruby-on-rails-api/descope/package-lock.json +1021 -19306
  33. data/examples/ruby-on-rails-api/descope/package.json +8 -16
  34. data/examples/ruby-on-rails-api/descope/yarn.lock +459 -10641
  35. data/lib/descope/api/v1/auth/otp.rb +21 -14
  36. data/lib/descope/api/v1/auth.rb +17 -20
  37. data/lib/descope/api/v1/management/audit.rb +24 -0
  38. data/lib/descope/api/v1/management/common.rb +1 -0
  39. data/lib/descope/mixins/common.rb +5 -2
  40. data/lib/descope/mixins/validation.rb +21 -6
  41. data/lib/descope/version.rb +1 -1
  42. data/spec/integration/lib.descope/api/v1/auth/otp_spec.rb +72 -7
  43. data/spec/integration/lib.descope/api/v1/management/audit_spec.rb +36 -0
  44. data/spec/integration/lib.descope/api/v1/management/roles_spec.rb +1 -1
  45. data/spec/lib.descope/api/v1/auth/otp_spec.rb +176 -18
  46. data/spec/lib.descope/api/v1/auth_spec.rb +1 -1
  47. data/spec/lib.descope/api/v1/management/audit_spec.rb +92 -0
  48. metadata +25 -133
  49. data/examples/ruby-on-rails-api/descope/app/assets/builds/reportWebVitals.js +0 -211
  50. data/examples/ruby-on-rails-api/descope/app/assets/builds/reportWebVitals.js.map +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cec3cb315d2015591a727a55440f878d49df010ad72f31522eb93bf927bc1cf8
4
- data.tar.gz: e207e1b64908011868e269257d2879d2ebc112025e56cea97a15aed0eefc8dbc
3
+ metadata.gz: c34965cb6d8afe8eef75358f8a2bfe51a4c85732b7a6704352d67429be4ef2a1
4
+ data.tar.gz: d683b72349fe21ad68c8eb5ba3f5efc630f6d064d725200d874b0b1a07fda450
5
5
  SHA512:
6
- metadata.gz: 46585ad1d53f2383c9458d310ae8e41a13bb3da9c72479b5ebd4e91f73544f8d4cb7dca8e3e2b4704e87f4532046a014bb4b5f3c7206d53a1a37da1634e152e9
7
- data.tar.gz: 47383953f8613b0ae07e3ced035d5f06392faeec4b7cb0756bdc2dc7793c75c607f99b54bd46ea292cfb62ce55767e0b364ba04c39a46718e3507693262e0599
6
+ metadata.gz: aed5e37a77c61eca6ee2e52cef996ebc5088b57dd78ed566cb2c4e21b7b939ddd5779712de35fdba59e13990872757dc8fb3a84a6c05b4bf8d169fefa281dcc9
7
+ data.tar.gz: 6cca87aa406e2eda34f7d38ad02178422c5b37262d0c4d5195f582ab7b4eabffe4c5508a06c10615f165de612e0a2b6caf5d14d7c19157b245354746f582810a
@@ -4,17 +4,16 @@ on:
4
4
  release:
5
5
  types: [published]
6
6
 
7
- permissions:
8
- contents: read
9
- pull-requests: read # to detect changes files
10
-
11
7
  jobs:
12
- publish-gem:
8
+ release:
13
9
  name: Publish Ruby Gem
14
10
  runs-on: ubuntu-latest
15
11
  steps:
16
12
  - name: Checkout Code
17
13
  uses: actions/checkout@v4
14
+ with:
15
+ ref: main
16
+ fetch-depth: 0
18
17
 
19
18
  - uses: ruby/setup-ruby@v1
20
19
  with:
@@ -24,6 +23,32 @@ jobs:
24
23
  - name: Install dependencies
25
24
  run: bundle install
26
25
 
26
+ - name: Bump version
27
+ run: |
28
+ NEW_VERSION=$(echo ${{ github.event.release.tag_name }} | sed 's/^v//') # strip the 'v' from the tag if present
29
+ sed -i "s/^ VERSION = '.*'/ VERSION = '${NEW_VERSION}'/g" lib/descope/version.rb
30
+ echo -e "Updated version file:\n $(cat lib/descope/version.rb)"
31
+
32
+ - name: Commit changes
33
+ run: |
34
+ git config --global user.name 'github-actions'
35
+ git config --global user.email 'github-actions@github.com'
36
+ git checkout main
37
+ git add ./lib/descope/version.rb
38
+ git commit -m "Bump version to $NEW_VERSION"
39
+ git push origin main
40
+ env:
41
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42
+
43
+ - name: Repoint the tag to latest commit
44
+ run: |
45
+ git tag -d ${{ github.event.release.tag_name }}
46
+ git tag ${{ github.event.release.tag_name }} -m "Release $NEW_VERSION"
47
+ git push origin :${{ github.event.release.tag_name }}
48
+ git push
49
+ env:
50
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51
+
27
52
  - name: Publish to RubyGems
28
53
  run: |
29
54
  mkdir -p $HOME/.gem
data/Gemfile CHANGED
@@ -4,8 +4,8 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  group :development do
7
- gem 'rubocop', '1.60.2', require: false
8
- gem 'rubocop-rails', '2.23.1', require: false
7
+ gem 'rubocop', '1.63.2', require: false
8
+ gem 'rubocop-rails', '2.24.1', require: false
9
9
  end
10
10
 
11
11
  group :test do
@@ -14,7 +14,7 @@ group :test do
14
14
  gem 'rack-test', '2.1.0', require: false
15
15
  gem 'rotp', '6.3.0', require: false
16
16
  gem 'rspec', '3.13.0', require: false
17
- gem 'selenium-webdriver', '4.17.0', require: false
17
+ gem 'selenium-webdriver', '4.19.0', require: false
18
18
  gem 'simplecov', '0.22.0', require: false
19
19
  gem 'super_diff', '0.11.0', require: false
20
20
  end
data/Gemfile.lock CHANGED
@@ -35,17 +35,14 @@ GEM
35
35
  drb (2.2.1)
36
36
  factory_bot (6.4.6)
37
37
  activesupport (>= 5.0.0)
38
- faker (3.2.3)
38
+ faker (3.3.1)
39
39
  i18n (>= 1.8.11, < 2)
40
- fuubar (2.5.1)
41
- rspec-core (~> 3.0)
42
- ruby-progressbar (~> 1.4)
43
40
  http-accept (1.7.0)
44
41
  http-cookie (1.0.5)
45
42
  domain_name (~> 0.5)
46
43
  i18n (1.14.4)
47
44
  concurrent-ruby (~> 1.0)
48
- json (2.7.1)
45
+ json (2.7.2)
49
46
  jwt (2.8.1)
50
47
  base64
51
48
  language_server-protocol (3.17.0.3)
@@ -62,13 +59,12 @@ GEM
62
59
  racc
63
60
  patience_diff (1.2.0)
64
61
  optimist (~> 3.0)
65
- public_suffix (5.0.4)
62
+ public_suffix (5.0.5)
66
63
  racc (1.7.3)
67
- rack (3.0.9.1)
64
+ rack (3.0.10)
68
65
  rack-test (2.1.0)
69
66
  rack (>= 1.3)
70
67
  rainbow (3.1.1)
71
- rake (13.1.0)
72
68
  regexp_parser (2.9.0)
73
69
  rest-client (2.1.0)
74
70
  http-accept (>= 1.7.0, < 2.0)
@@ -91,7 +87,7 @@ GEM
91
87
  diff-lcs (>= 1.2.0, < 2.0)
92
88
  rspec-support (~> 3.13.0)
93
89
  rspec-support (3.13.1)
94
- rubocop (1.60.2)
90
+ rubocop (1.63.2)
95
91
  json (~> 2.3)
96
92
  language_server-protocol (>= 3.17.0)
97
93
  parallel (~> 1.10)
@@ -99,19 +95,19 @@ GEM
99
95
  rainbow (>= 2.2.2, < 4.0)
100
96
  regexp_parser (>= 1.8, < 3.0)
101
97
  rexml (>= 3.2.5, < 4.0)
102
- rubocop-ast (>= 1.30.0, < 2.0)
98
+ rubocop-ast (>= 1.31.1, < 2.0)
103
99
  ruby-progressbar (~> 1.7)
104
100
  unicode-display_width (>= 2.4.0, < 3.0)
105
101
  rubocop-ast (1.31.2)
106
102
  parser (>= 3.3.0.4)
107
- rubocop-rails (2.23.1)
103
+ rubocop-rails (2.24.1)
108
104
  activesupport (>= 4.2.0)
109
105
  rack (>= 1.1)
110
106
  rubocop (>= 1.33.0, < 2.0)
111
- rubocop-ast (>= 1.30.0, < 2.0)
107
+ rubocop-ast (>= 1.31.1, < 2.0)
112
108
  ruby-progressbar (1.13.0)
113
109
  rubyzip (2.3.2)
114
- selenium-webdriver (4.17.0)
110
+ selenium-webdriver (4.19.0)
115
111
  base64 (~> 0.2)
116
112
  rexml (~> 3.2, >= 3.2.5)
117
113
  rubyzip (>= 1.2.2, < 3.0)
@@ -137,19 +133,15 @@ PLATFORMS
137
133
  x86_64-linux
138
134
 
139
135
  DEPENDENCIES
140
- bundler
141
- concurrent-ruby (~> 1.1)
142
136
  descope!
143
137
  factory_bot (= 6.4.6)
144
138
  faker
145
- fuubar (~> 2.0)
146
139
  rack-test (= 2.1.0)
147
- rake (~> 13.0)
148
140
  rotp (= 6.3.0)
149
141
  rspec (= 3.13.0)
150
- rubocop (= 1.60.2)
151
- rubocop-rails (= 2.23.1)
152
- selenium-webdriver (= 4.17.0)
142
+ rubocop (= 1.63.2)
143
+ rubocop-rails (= 2.24.1)
144
+ selenium-webdriver (= 4.19.0)
153
145
  simplecov (= 0.22.0)
154
146
  super_diff (= 0.11.0)
155
147
 
data/README.md CHANGED
@@ -67,7 +67,7 @@ These sections show how to use the SDK to perform permission and user management
67
67
  8. [Manage Flows](#manage-flows-and-theme)
68
68
  9. [Manage JWTs](#manage-jwts)
69
69
  10. [Embedded links](#embedded-links)
70
- 11. [Search Audit](#search-audit)
70
+ 11. [Audit](#audit)
71
71
  12. [Manage ReBAC Authz](#manage-rebac-authz)
72
72
  13. [Manage Project](#manage-project)
73
73
 
@@ -79,7 +79,7 @@ For rate limiting information, please confer to the [API Rate Limits](#api-rate-
79
79
 
80
80
  ### OTP Authentication
81
81
 
82
- Send a user a one-time password (OTP) using your preferred delivery method (email/SMS). An email address or phone number must be provided accordingly.
82
+ Send a user a one-time password (OTP) using your preferred delivery method (email/SMS/Voice call). An email address or phone number must be provided accordingly.
83
83
 
84
84
  The user can either `sign up`, `sign in` or `sign up or in`
85
85
 
@@ -871,7 +871,7 @@ This token can then be verified using the magic link 'verify' function, either d
871
871
  token = descope_client.generate_embedded_link(login_id: 'desmond@descope.com', custom_claims: {'key1':'value1'})
872
872
  ```
873
873
 
874
- ### Search Audit
874
+ ### Audit
875
875
 
876
876
  You can perform an audit search for either specific values or full-text across the fields. Audit search is limited to the last 30 days.
877
877
  Below are some examples. For a full list of available search criteria options, see the function documentation.
@@ -898,6 +898,21 @@ audits = descope_client.audit_search(
898
898
  audits = descope_client.audit_search(actions: ['LoginSucceed'])
899
899
  ```
900
900
 
901
+ You can also create audit event with data
902
+
903
+ ```ruby
904
+ descope_client.audit_create_event(
905
+ actor_id: "UXXX", # required, for example a user ID
906
+ tenant_id: "tenant-id", # required
907
+ action: "pencil.created", # required
908
+ type: "info", # either: info/warn/error # required
909
+ data: {
910
+ pencil_id: "PXXX",
911
+ pencil_name: "Pencil Name"
912
+ } # optional
913
+ )
914
+ ```
915
+
901
916
  ### Manage ReBAC Authz
902
917
 
903
918
  Descope supports full relation based access control (ReBAC) using a [Google Zanzibar](https://research.google/pubs/pub48190/) like schema and operations.
data/descope.gemspec CHANGED
@@ -1,34 +1,39 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $LOAD_PATH.push File.expand_path('../lib', __FILE__)
3
3
  require 'descope/version'
4
+ version = Descope::VERSION
4
5
 
5
6
  Gem::Specification.new do |s|
6
- s.name = 'descope'
7
- s.version = Descope::VERSION
8
- s.authors = ['Descope']
9
- s.email = ['support@descope.com']
10
- s.homepage = 'https://github.com/descope/descope-ruby-sdk'
11
- s.summary = 'Descope API Client'
12
- s.description = 'Ruby API Client for Descope API https://descope.com'
7
+ s.platform = Gem::Platform::RUBY
8
+ s.name = "descope"
9
+ s.version = version
10
+ s.summary = "Descope Ruby API Client"
11
+ s.description = "Ruby API Client for Descope API https://descope.com"
12
+
13
+ s.required_ruby_version = ">= 3.3.0"
14
+ s.required_rubygems_version = ">= 3.5"
15
+
16
+ s.author = "Descope Inc."
17
+ s.email = "support@descope.com"
18
+ s.homepage = "https://github.com/descope/descope-ruby-sdk"
19
+
20
+ s.license = "MIT"
13
21
 
14
22
  s.files = `git ls-files`.split("\n")
15
23
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
24
  s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
17
25
  s.require_paths = ['lib']
18
26
 
19
- s.add_runtime_dependency 'rest-client', '~> 2.1'
20
- s.add_runtime_dependency 'jwt', '~> 2.7'
21
- s.add_runtime_dependency 'zache', '~> 0.12'
27
+ s.metadata = {
28
+ "bug_tracker_uri" => "https://github.com/descope/descope-ruby-sdk/issues",
29
+ "changelog_uri" => "https://github.com/descope/descope-ruby-sdk/releases/tag/#{version}",
30
+ "documentation_uri" => "https://docs.descope.com",
31
+ "source_code_uri" => "https://github.com/descope/descope-ruby-sdk/tree/#{version}",
32
+ }
33
+
22
34
  s.add_runtime_dependency 'addressable', '~> 2.8'
35
+ s.add_runtime_dependency 'jwt', '~> 2.7'
36
+ s.add_runtime_dependency 'rest-client', '~> 2.1'
23
37
  s.add_runtime_dependency 'retryable', '~> 3.0'
24
-
25
- s.add_development_dependency 'bundler'
26
- s.add_development_dependency 'rake', '~> 13.0'
27
- s.add_development_dependency 'fuubar', '~> 2.0'
28
- s.add_development_dependency 'rspec', '~> 3.11'
29
- s.add_development_dependency 'simplecov', '~> 0.9'
30
- s.add_development_dependency 'faker', '~> 2.0'
31
- s.add_development_dependency "super_diff", "~> 1.0"
32
- s.add_development_dependency 'concurrent-ruby', '~> 1.1'
33
- s.license = 'MIT'
38
+ s.add_runtime_dependency 'zache', '~> 0.12'
34
39
  end
@@ -0,0 +1 @@
1
+ 3.3.0
@@ -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)
@@ -25,17 +26,17 @@ begin
25
26
  login_options = {
26
27
  customClaims: { "k1": 'v1' }
27
28
  }
28
- jwt_response = @client.exchange_access_key(access_key:, login_options:)
29
+ jwt_response = @client.exchange_access_key(access_key: access_key, login_options: login_options)
29
30
  @logger.info('exchange access key successfully')
30
31
  @logger.info("jwt_response: #{jwt_response}")
31
32
 
32
33
  permission_name = 'TestPermission'
33
34
  permission_presented = @client.validate_permissions(
34
- jwt_response:, permissions: [permission_name]
35
+ jwt_response: jwt_response, permissions: [permission_name]
35
36
  )
36
37
  @logger.info("#{permission_name} presented on the jwt: [#{permission_presented}]")
37
38
  role_name = 'TestRole'
38
- role_presented = @client.validate_roles(jwt_response:, roles: [role_name])
39
+ role_presented = @client.validate_roles(jwt_response: jwt_response, roles: [role_name])
39
40
  @logger.info("#{role_name} presented on the jwt: [#{role_presented}]")
40
41
  rescue Descope::AuthException => e
41
42
  @logger.error("Failed to exchange access key #{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)
@@ -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
  # include Descope::Mixin::Common
@@ -0,0 +1 @@
1
+ 3.3.0
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  # A sample Gemfile
3
- source 'http://rubygems.org'
3
+ source 'https://rubygems.org'
4
4
 
5
- gem 'descope'
5
+ gem 'descope'
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
+
5
+ require_relative '../version_check'
4
6
  require 'descope'
5
7
 
6
8
  @logger = Logger.new($stdout)
@@ -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('Going to search audit')
17
- text = nil
18
- text = ARGV[0] if ARGV.length > 1
19
- from_ts = nil
20
- from_ts = DateTime.iso8601(ARGV[1]) if ARGV.length > 2
21
- res = @client.audit_search(text:, from_ts:)
22
- @logger.info("Audit search result: #{res}")
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 search failed #{e}")
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)
@@ -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)
@@ -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:, description: 'Allowed to test')
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:, new_name: 'My Updated Permission', description: 'New Description'
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:, description: 'Allowed to test :)', permission_names: ['SSO Admin'], tenant_id: tenant['id']
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'],
@@ -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)
@@ -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)
@@ -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
  require 'launchy'
6
7
 
@@ -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 insert the code you received by email to #{masked_email}:\n"
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:, refresh_token:)
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('Token verified successfully! #{jwt_response}')
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:, refresh_token:)
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...')
@@ -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)
@@ -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