descope 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/ci.yaml +54 -0
- data/.gitignore +59 -0
- data/.release-please-manifest.json +3 -0
- data/.rubocop.yml +10 -0
- data/.rubocop_todo.yml +10 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +90 -0
- data/Gemfile +22 -0
- data/Gemfile.lock +204 -0
- data/LICENSE +21 -0
- data/README.md +1171 -0
- data/Rakefile +31 -0
- data/descope.gemspec +34 -0
- data/examples/ruby/Gemfile +4 -0
- data/examples/ruby/Gemfile.lock +41 -0
- data/examples/ruby/access_key_app.rb +45 -0
- data/examples/ruby/enchantedlink_app.rb +65 -0
- data/examples/ruby/magiclink_app.rb +81 -0
- data/examples/ruby/management/Gemfile +5 -0
- data/examples/ruby/management/Gemfile.lock +38 -0
- data/examples/ruby/management/access_key_app.rb +71 -0
- data/examples/ruby/management/audit_app.rb +25 -0
- data/examples/ruby/management/authz_app.rb +135 -0
- data/examples/ruby/management/authz_files.json +229 -0
- data/examples/ruby/management/flow_app.rb +57 -0
- data/examples/ruby/management/permission_app.rb +56 -0
- data/examples/ruby/management/role_app.rb +58 -0
- data/examples/ruby/management/tenant_app.rb +60 -0
- data/examples/ruby/management/user_app.rb +60 -0
- data/examples/ruby/oauth_app.rb +39 -0
- data/examples/ruby/otp_app.rb +50 -0
- data/examples/ruby/password_app.rb +76 -0
- data/examples/ruby/saml_app.rb +38 -0
- data/examples/ruby-on-rails-api/descope/.dockerignore +37 -0
- data/examples/ruby-on-rails-api/descope/.gitattributes +9 -0
- data/examples/ruby-on-rails-api/descope/.gitignore +40 -0
- data/examples/ruby-on-rails-api/descope/.node-version +1 -0
- data/examples/ruby-on-rails-api/descope/.ruby-version +1 -0
- data/examples/ruby-on-rails-api/descope/Dockerfile +75 -0
- data/examples/ruby-on-rails-api/descope/Gemfile +67 -0
- data/examples/ruby-on-rails-api/descope/Gemfile.lock +284 -0
- data/examples/ruby-on-rails-api/descope/Procfile.dev +3 -0
- data/examples/ruby-on-rails-api/descope/README.md +54 -0
- data/examples/ruby-on-rails-api/descope/Rakefile +6 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/.keep +0 -0
- data/examples/ruby-on-rails-api/descope/app/assets/config/manifest.js +3 -0
- data/examples/ruby-on-rails-api/descope/app/assets/images/.keep +0 -0
- data/examples/ruby-on-rails-api/descope/app/assets/images/descope.jpeg +0 -0
- data/examples/ruby-on-rails-api/descope/app/assets/images/favicon.ico +0 -0
- data/examples/ruby-on-rails-api/descope/app/assets/images/logo192.png +0 -0
- data/examples/ruby-on-rails-api/descope/app/assets/images/logo512.png +0 -0
- data/examples/ruby-on-rails-api/descope/app/assets/stylesheets/application.bootstrap.scss +67 -0
- data/examples/ruby-on-rails-api/descope/app/channels/application_cable/channel.rb +4 -0
- data/examples/ruby-on-rails-api/descope/app/channels/application_cable/connection.rb +4 -0
- data/examples/ruby-on-rails-api/descope/app/controllers/application_controller.rb +2 -0
- data/examples/ruby-on-rails-api/descope/app/controllers/concerns/.keep +0 -0
- data/examples/ruby-on-rails-api/descope/app/controllers/homepage_controller.rb +4 -0
- data/examples/ruby-on-rails-api/descope/app/controllers/session_controller.rb +66 -0
- data/examples/ruby-on-rails-api/descope/app/helpers/application_helper.rb +2 -0
- data/examples/ruby-on-rails-api/descope/app/helpers/homepage_helper.rb +2 -0
- data/examples/ruby-on-rails-api/descope/app/helpers/session_helper.rb +2 -0
- data/examples/ruby-on-rails-api/descope/app/javascript/App.css +53 -0
- data/examples/ruby-on-rails-api/descope/app/javascript/application.js +5 -0
- data/examples/ruby-on-rails-api/descope/app/javascript/components/App.jsx +4 -0
- data/examples/ruby-on-rails-api/descope/app/javascript/components/Dashboard.jsx +60 -0
- data/examples/ruby-on-rails-api/descope/app/javascript/components/Home.jsx +27 -0
- data/examples/ruby-on-rails-api/descope/app/javascript/components/Login.jsx +45 -0
- data/examples/ruby-on-rails-api/descope/app/javascript/components/Profile.jsx +81 -0
- data/examples/ruby-on-rails-api/descope/app/javascript/components/index.html +11 -0
- data/examples/ruby-on-rails-api/descope/app/javascript/components/index.jsx +24 -0
- data/examples/ruby-on-rails-api/descope/app/javascript/controllers/application.js +9 -0
- data/examples/ruby-on-rails-api/descope/app/javascript/controllers/index.js +5 -0
- data/examples/ruby-on-rails-api/descope/app/javascript/reportWebVitals.js +13 -0
- data/examples/ruby-on-rails-api/descope/app/javascript/routes/index.jsx +17 -0
- data/examples/ruby-on-rails-api/descope/app/jobs/application_job.rb +7 -0
- data/examples/ruby-on-rails-api/descope/app/mailers/application_mailer.rb +4 -0
- data/examples/ruby-on-rails-api/descope/app/models/application_record.rb +3 -0
- data/examples/ruby-on-rails-api/descope/app/models/concerns/.keep +0 -0
- data/examples/ruby-on-rails-api/descope/app/views/homepage/index.html.erb +2 -0
- data/examples/ruby-on-rails-api/descope/app/views/layouts/application.html.erb +16 -0
- data/examples/ruby-on-rails-api/descope/app/views/layouts/mailer.html.erb +13 -0
- data/examples/ruby-on-rails-api/descope/app/views/layouts/mailer.text.erb +1 -0
- data/examples/ruby-on-rails-api/descope/app/views/session/index.html.erb +2 -0
- data/examples/ruby-on-rails-api/descope/bin/bundle +109 -0
- data/examples/ruby-on-rails-api/descope/bin/dev +11 -0
- data/examples/ruby-on-rails-api/descope/bin/docker-entrypoint +8 -0
- data/examples/ruby-on-rails-api/descope/bin/rails +4 -0
- data/examples/ruby-on-rails-api/descope/bin/rake +4 -0
- data/examples/ruby-on-rails-api/descope/bin/setup +36 -0
- data/examples/ruby-on-rails-api/descope/build.js +30 -0
- data/examples/ruby-on-rails-api/descope/config/application.rb +42 -0
- data/examples/ruby-on-rails-api/descope/config/boot.rb +4 -0
- data/examples/ruby-on-rails-api/descope/config/cable.yml +10 -0
- data/examples/ruby-on-rails-api/descope/config/config.yml +9 -0
- data/examples/ruby-on-rails-api/descope/config/credentials.yml.enc +1 -0
- data/examples/ruby-on-rails-api/descope/config/database.yml +25 -0
- data/examples/ruby-on-rails-api/descope/config/environment.rb +5 -0
- data/examples/ruby-on-rails-api/descope/config/environments/development.rb +76 -0
- data/examples/ruby-on-rails-api/descope/config/environments/production.rb +97 -0
- data/examples/ruby-on-rails-api/descope/config/environments/test.rb +64 -0
- data/examples/ruby-on-rails-api/descope/config/initializers/assets.rb +13 -0
- data/examples/ruby-on-rails-api/descope/config/initializers/content_security_policy.rb +25 -0
- data/examples/ruby-on-rails-api/descope/config/initializers/filter_parameter_logging.rb +8 -0
- data/examples/ruby-on-rails-api/descope/config/initializers/inflections.rb +16 -0
- data/examples/ruby-on-rails-api/descope/config/initializers/load_config.rb +12 -0
- data/examples/ruby-on-rails-api/descope/config/initializers/permissions_policy.rb +13 -0
- data/examples/ruby-on-rails-api/descope/config/locales/en.yml +31 -0
- data/examples/ruby-on-rails-api/descope/config/puma.rb +35 -0
- data/examples/ruby-on-rails-api/descope/config/routes.rb +18 -0
- data/examples/ruby-on-rails-api/descope/config/storage.yml +34 -0
- data/examples/ruby-on-rails-api/descope/config.ru +6 -0
- data/examples/ruby-on-rails-api/descope/db/seeds.rb +9 -0
- data/examples/ruby-on-rails-api/descope/lib/assets/.keep +0 -0
- data/examples/ruby-on-rails-api/descope/lib/tasks/.keep +0 -0
- data/examples/ruby-on-rails-api/descope/log/.keep +0 -0
- data/examples/ruby-on-rails-api/descope/package-lock.json +19680 -0
- data/examples/ruby-on-rails-api/descope/package.json +51 -0
- data/examples/ruby-on-rails-api/descope/public/404.html +67 -0
- data/examples/ruby-on-rails-api/descope/public/422.html +67 -0
- data/examples/ruby-on-rails-api/descope/public/500.html +66 -0
- data/examples/ruby-on-rails-api/descope/public/apple-touch-icon-precomposed.png +0 -0
- data/examples/ruby-on-rails-api/descope/public/apple-touch-icon.png +0 -0
- data/examples/ruby-on-rails-api/descope/public/favicon.ico +0 -0
- data/examples/ruby-on-rails-api/descope/public/robots.txt +1 -0
- data/examples/ruby-on-rails-api/descope/storage/.keep +0 -0
- data/examples/ruby-on-rails-api/descope/tmp/.keep +0 -0
- data/examples/ruby-on-rails-api/descope/tmp/pids/.keep +0 -0
- data/examples/ruby-on-rails-api/descope/tmp/storage/.keep +0 -0
- data/examples/ruby-on-rails-api/descope/vendor/.keep +0 -0
- data/examples/ruby-on-rails-api/descope/yarn.lock +10780 -0
- data/lib/descope/api/v1/auth/enchantedlink.rb +156 -0
- data/lib/descope/api/v1/auth/magiclink.rb +170 -0
- data/lib/descope/api/v1/auth/oauth.rb +72 -0
- data/lib/descope/api/v1/auth/otp.rb +186 -0
- data/lib/descope/api/v1/auth/password.rb +100 -0
- data/lib/descope/api/v1/auth/saml.rb +48 -0
- data/lib/descope/api/v1/auth/totp.rb +72 -0
- data/lib/descope/api/v1/auth.rb +452 -0
- data/lib/descope/api/v1/management/access_key.rb +81 -0
- data/lib/descope/api/v1/management/audit.rb +82 -0
- data/lib/descope/api/v1/management/authz.rb +165 -0
- data/lib/descope/api/v1/management/common.rb +147 -0
- data/lib/descope/api/v1/management/flow.rb +55 -0
- data/lib/descope/api/v1/management/password.rb +58 -0
- data/lib/descope/api/v1/management/permission.rb +48 -0
- data/lib/descope/api/v1/management/project.rb +53 -0
- data/lib/descope/api/v1/management/role.rb +48 -0
- data/lib/descope/api/v1/management/scim.rb +206 -0
- data/lib/descope/api/v1/management/sso_settings.rb +153 -0
- data/lib/descope/api/v1/management/tenant.rb +71 -0
- data/lib/descope/api/v1/management/user.rb +619 -0
- data/lib/descope/api/v1/management.rb +38 -0
- data/lib/descope/api/v1/session.rb +84 -0
- data/lib/descope/api/v1.rb +13 -0
- data/lib/descope/client.rb +6 -0
- data/lib/descope/exception.rb +50 -0
- data/lib/descope/mixins/common.rb +129 -0
- data/lib/descope/mixins/headers.rb +15 -0
- data/lib/descope/mixins/http.rb +133 -0
- data/lib/descope/mixins/initializer.rb +80 -0
- data/lib/descope/mixins/logging.rb +30 -0
- data/lib/descope/mixins/validation.rb +79 -0
- data/lib/descope/mixins.rb +22 -0
- data/lib/descope/version.rb +7 -0
- data/lib/descope.rb +9 -0
- data/lib/descope_client.rb +5 -0
- data/release-please-config.json +18 -0
- data/renovate.json +6 -0
- data/spec/factories/user.rb +16 -0
- data/spec/lib.descope/api/v1/auth/enchantedlink_spec.rb +159 -0
- data/spec/lib.descope/api/v1/auth/magiclink_spec.rb +282 -0
- data/spec/lib.descope/api/v1/auth/oauth_spec.rb +117 -0
- data/spec/lib.descope/api/v1/auth/otp_spec.rb +285 -0
- data/spec/lib.descope/api/v1/auth/password_spec.rb +124 -0
- data/spec/lib.descope/api/v1/auth/saml_spec.rb +55 -0
- data/spec/lib.descope/api/v1/auth/totp_spec.rb +70 -0
- data/spec/lib.descope/api/v1/auth_spec.rb +372 -0
- data/spec/lib.descope/api/v1/management/access_key_spec.rb +118 -0
- data/spec/lib.descope/api/v1/management/audit_spec.rb +78 -0
- data/spec/lib.descope/api/v1/management/authz_spec.rb +336 -0
- data/spec/lib.descope/api/v1/management/flow_spec.rb +78 -0
- data/spec/lib.descope/api/v1/management/password_spec.rb +25 -0
- data/spec/lib.descope/api/v1/management/permission_spec.rb +81 -0
- data/spec/lib.descope/api/v1/management/project_spec.rb +63 -0
- data/spec/lib.descope/api/v1/management/role_spec.rb +85 -0
- data/spec/lib.descope/api/v1/management/scim_spec.rb +312 -0
- data/spec/lib.descope/api/v1/management/sso_settings_spec.rb +172 -0
- data/spec/lib.descope/api/v1/management/tenant_spec.rb +141 -0
- data/spec/lib.descope/api/v1/management/user_spec.rb +667 -0
- data/spec/lib.descope/api/v1/session_spec.rb +117 -0
- data/spec/lib.descope/client_spec.rb +40 -0
- data/spec/spec_helper.rb +72 -0
- data/spec/support/client_config.rb +14 -0
- data/spec/support/dummy_class.rb +36 -0
- data/spec/support/utils.rb +32 -0
- metadata +420 -0
@@ -0,0 +1,229 @@
|
|
1
|
+
{
|
2
|
+
"name": "Files",
|
3
|
+
"namespaces": [
|
4
|
+
{
|
5
|
+
"name": "org",
|
6
|
+
"relationDefinitions": [
|
7
|
+
{
|
8
|
+
"name": "parent"
|
9
|
+
},
|
10
|
+
{
|
11
|
+
"name": "member",
|
12
|
+
"complexDefinition": {
|
13
|
+
"nType": "union",
|
14
|
+
"children": [
|
15
|
+
{
|
16
|
+
"nType": "child",
|
17
|
+
"expression": {
|
18
|
+
"neType": "self"
|
19
|
+
}
|
20
|
+
},
|
21
|
+
{
|
22
|
+
"nType": "child",
|
23
|
+
"expression": {
|
24
|
+
"neType": "relationLeft",
|
25
|
+
"relationDefinition": "parent",
|
26
|
+
"relationDefinitionNamespace": "org",
|
27
|
+
"targetRelationDefinition": "member",
|
28
|
+
"targetRelationDefinitionNamespace": "org"
|
29
|
+
}
|
30
|
+
}
|
31
|
+
]
|
32
|
+
}
|
33
|
+
}
|
34
|
+
]
|
35
|
+
},
|
36
|
+
{
|
37
|
+
"name": "folder",
|
38
|
+
"relationDefinitions": [
|
39
|
+
{
|
40
|
+
"name": "parent"
|
41
|
+
},
|
42
|
+
{
|
43
|
+
"name": "owner",
|
44
|
+
"complexDefinition": {
|
45
|
+
"nType": "union",
|
46
|
+
"children": [
|
47
|
+
{
|
48
|
+
"nType": "child",
|
49
|
+
"expression": {
|
50
|
+
"neType": "self"
|
51
|
+
}
|
52
|
+
},
|
53
|
+
{
|
54
|
+
"nType": "child",
|
55
|
+
"expression": {
|
56
|
+
"neType": "relationRight",
|
57
|
+
"relationDefinition": "parent",
|
58
|
+
"relationDefinitionNamespace": "folder",
|
59
|
+
"targetRelationDefinition": "owner",
|
60
|
+
"targetRelationDefinitionNamespace": "folder"
|
61
|
+
}
|
62
|
+
}
|
63
|
+
]
|
64
|
+
}
|
65
|
+
},
|
66
|
+
{
|
67
|
+
"name": "editor",
|
68
|
+
"complexDefinition": {
|
69
|
+
"nType": "union",
|
70
|
+
"children": [
|
71
|
+
{
|
72
|
+
"nType": "child",
|
73
|
+
"expression": {
|
74
|
+
"neType": "self"
|
75
|
+
}
|
76
|
+
},
|
77
|
+
{
|
78
|
+
"nType": "child",
|
79
|
+
"expression": {
|
80
|
+
"neType": "relationRight",
|
81
|
+
"relationDefinition": "parent",
|
82
|
+
"relationDefinitionNamespace": "folder",
|
83
|
+
"targetRelationDefinition": "editor",
|
84
|
+
"targetRelationDefinitionNamespace": "folder"
|
85
|
+
}
|
86
|
+
},
|
87
|
+
{
|
88
|
+
"nType": "child",
|
89
|
+
"expression": {
|
90
|
+
"neType": "targetSet",
|
91
|
+
"targetRelationDefinition": "owner",
|
92
|
+
"targetRelationDefinitionNamespace": "folder"
|
93
|
+
}
|
94
|
+
}
|
95
|
+
]
|
96
|
+
}
|
97
|
+
},
|
98
|
+
{
|
99
|
+
"name": "viewer",
|
100
|
+
"complexDefinition": {
|
101
|
+
"nType": "union",
|
102
|
+
"children": [
|
103
|
+
{
|
104
|
+
"nType": "child",
|
105
|
+
"expression": {
|
106
|
+
"neType": "self"
|
107
|
+
}
|
108
|
+
},
|
109
|
+
{
|
110
|
+
"nType": "child",
|
111
|
+
"expression": {
|
112
|
+
"neType": "relationRight",
|
113
|
+
"relationDefinition": "parent",
|
114
|
+
"relationDefinitionNamespace": "folder",
|
115
|
+
"targetRelationDefinition": "viewer",
|
116
|
+
"targetRelationDefinitionNamespace": "folder"
|
117
|
+
}
|
118
|
+
},
|
119
|
+
{
|
120
|
+
"nType": "child",
|
121
|
+
"expression": {
|
122
|
+
"neType": "targetSet",
|
123
|
+
"targetRelationDefinition": "editor",
|
124
|
+
"targetRelationDefinitionNamespace": "folder"
|
125
|
+
}
|
126
|
+
}
|
127
|
+
]
|
128
|
+
}
|
129
|
+
}
|
130
|
+
]
|
131
|
+
},
|
132
|
+
{
|
133
|
+
"name": "doc",
|
134
|
+
"relationDefinitions": [
|
135
|
+
{
|
136
|
+
"name": "parent"
|
137
|
+
},
|
138
|
+
{
|
139
|
+
"name": "owner",
|
140
|
+
"complexDefinition": {
|
141
|
+
"nType": "union",
|
142
|
+
"children": [
|
143
|
+
{
|
144
|
+
"nType": "child",
|
145
|
+
"expression": {
|
146
|
+
"neType": "self"
|
147
|
+
}
|
148
|
+
},
|
149
|
+
{
|
150
|
+
"nType": "child",
|
151
|
+
"expression": {
|
152
|
+
"neType": "relationRight",
|
153
|
+
"relationDefinition": "parent",
|
154
|
+
"relationDefinitionNamespace": "doc",
|
155
|
+
"targetRelationDefinition": "owner",
|
156
|
+
"targetRelationDefinitionNamespace": "folder"
|
157
|
+
}
|
158
|
+
}
|
159
|
+
]
|
160
|
+
}
|
161
|
+
},
|
162
|
+
{
|
163
|
+
"name": "editor",
|
164
|
+
"complexDefinition": {
|
165
|
+
"nType": "union",
|
166
|
+
"children": [
|
167
|
+
{
|
168
|
+
"nType": "child",
|
169
|
+
"expression": {
|
170
|
+
"neType": "self"
|
171
|
+
}
|
172
|
+
},
|
173
|
+
{
|
174
|
+
"nType": "child",
|
175
|
+
"expression": {
|
176
|
+
"neType": "relationRight",
|
177
|
+
"relationDefinition": "parent",
|
178
|
+
"relationDefinitionNamespace": "doc",
|
179
|
+
"targetRelationDefinition": "editor",
|
180
|
+
"targetRelationDefinitionNamespace": "folder"
|
181
|
+
}
|
182
|
+
},
|
183
|
+
{
|
184
|
+
"nType": "child",
|
185
|
+
"expression": {
|
186
|
+
"neType": "targetSet",
|
187
|
+
"targetRelationDefinition": "owner",
|
188
|
+
"targetRelationDefinitionNamespace": "doc"
|
189
|
+
}
|
190
|
+
}
|
191
|
+
]
|
192
|
+
}
|
193
|
+
},
|
194
|
+
{
|
195
|
+
"name": "viewer",
|
196
|
+
"complexDefinition": {
|
197
|
+
"nType": "union",
|
198
|
+
"children": [
|
199
|
+
{
|
200
|
+
"nType": "child",
|
201
|
+
"expression": {
|
202
|
+
"neType": "self"
|
203
|
+
}
|
204
|
+
},
|
205
|
+
{
|
206
|
+
"nType": "child",
|
207
|
+
"expression": {
|
208
|
+
"neType": "relationRight",
|
209
|
+
"relationDefinition": "parent",
|
210
|
+
"relationDefinitionNamespace": "doc",
|
211
|
+
"targetRelationDefinition": "viewer",
|
212
|
+
"targetRelationDefinitionNamespace": "folder"
|
213
|
+
}
|
214
|
+
},
|
215
|
+
{
|
216
|
+
"nType": "child",
|
217
|
+
"expression": {
|
218
|
+
"neType": "targetSet",
|
219
|
+
"targetRelationDefinition": "editor",
|
220
|
+
"targetRelationDefinitionNamespace": "doc"
|
221
|
+
}
|
222
|
+
}
|
223
|
+
]
|
224
|
+
}
|
225
|
+
}
|
226
|
+
]
|
227
|
+
}
|
228
|
+
]
|
229
|
+
}
|
@@ -0,0 +1,57 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'descope'
|
5
|
+
|
6
|
+
@logger = Logger.new($stdout)
|
7
|
+
|
8
|
+
@project_id = ENV['DESCOPE_PROJECT_ID']
|
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
|
+
@client = Descope::Client.new({ project_id: @project_id, management_key: @management_key })
|
14
|
+
|
15
|
+
begin
|
16
|
+
name = 'sign-up-or-in'
|
17
|
+
|
18
|
+
begin
|
19
|
+
@logger.info("Going to export 'sign-up-or-in' flow")
|
20
|
+
@res = @client.export_flow(name)
|
21
|
+
|
22
|
+
rescue Descope::AuthException => e
|
23
|
+
@logger.error("Export flow failed #{e}")
|
24
|
+
end
|
25
|
+
|
26
|
+
begin
|
27
|
+
@logger.info('Importing sign-up-or-in flow and change name')
|
28
|
+
@res['flow']['name'] = 'Importing from SDK'
|
29
|
+
@client.import_flow(
|
30
|
+
flow_id: 'sign-up-or-in',
|
31
|
+
flow: @res['flow'],
|
32
|
+
screens: @res['screens']
|
33
|
+
)
|
34
|
+
rescue Descope::AuthException => e
|
35
|
+
@logger.info("Importing flow failed #{e}")
|
36
|
+
end
|
37
|
+
|
38
|
+
begin
|
39
|
+
@logger.info('Going to export the project theme')
|
40
|
+
@res = @client.export_theme
|
41
|
+
@logger.info("Export theme success: #{@res}")
|
42
|
+
|
43
|
+
rescue Descope::AuthException => e
|
44
|
+
@logger.info("Export theme failed #{e}")
|
45
|
+
end
|
46
|
+
|
47
|
+
begin
|
48
|
+
@logger.info('Importing theme back')
|
49
|
+
@client.import_theme(@res)
|
50
|
+
@logger.info('Importing theme success')
|
51
|
+
rescue Descope::AuthException => e
|
52
|
+
@logger.error("Importing theme failed #{e}")
|
53
|
+
end
|
54
|
+
|
55
|
+
rescue Descope::AuthException
|
56
|
+
raise
|
57
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'descope'
|
5
|
+
|
6
|
+
@logger = Logger.new($stdout)
|
7
|
+
|
8
|
+
@project_id = ENV['DESCOPE_PROJECT_ID']
|
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
|
+
@client = Descope::Client.new({ project_id: @project_id, management_key: @management_key })
|
14
|
+
|
15
|
+
begin
|
16
|
+
@logger.info('Going to create a new permission')
|
17
|
+
name = 'My Permission'
|
18
|
+
@client.create_permission(name:, description: 'Allowed to test')
|
19
|
+
|
20
|
+
rescue Descope::AuthException => e
|
21
|
+
@logger.info("Permission creation failed #{e}")
|
22
|
+
end
|
23
|
+
|
24
|
+
begin
|
25
|
+
@logger.info('Loading all permissions')
|
26
|
+
permissions_resp = @client.load_all_permissions
|
27
|
+
permissions = permissions_resp['permissions']
|
28
|
+
permissions.each do |permission|
|
29
|
+
@logger.info("Search Found permission #{permission}")
|
30
|
+
end
|
31
|
+
|
32
|
+
rescue Descope::AuthException => e
|
33
|
+
@logger.error("Permission load failed #{e}")
|
34
|
+
end
|
35
|
+
|
36
|
+
begin
|
37
|
+
@logger.info('Updating newly created permission')
|
38
|
+
# update overrides all fields, must provide the entire entity
|
39
|
+
# we mean to update.
|
40
|
+
name = 'My Permission'
|
41
|
+
@client.update_permission(
|
42
|
+
name:, new_name: 'My Updated Permission', description: 'New Description'
|
43
|
+
)
|
44
|
+
|
45
|
+
rescue Descope::AuthException => e
|
46
|
+
@logger.error("Permission update failed #{e}")
|
47
|
+
end
|
48
|
+
|
49
|
+
begin
|
50
|
+
@logger.info('Deleting newly created permission')
|
51
|
+
@client.delete_permission('My Updated Permission')
|
52
|
+
|
53
|
+
rescue Descope::AuthException => e
|
54
|
+
@logger.error("Permission deletion failed #{e}")
|
55
|
+
end
|
56
|
+
|
@@ -0,0 +1,58 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'descope'
|
5
|
+
|
6
|
+
@logger = Logger.new($stdout)
|
7
|
+
|
8
|
+
@project_id = ENV['DESCOPE_PROJECT_ID']
|
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
|
+
@client = Descope::Client.new({ project_id: @project_id, management_key: @management_key })
|
14
|
+
|
15
|
+
name = 'My Role'
|
16
|
+
|
17
|
+
begin
|
18
|
+
@logger.info('Going to create a new role')
|
19
|
+
@client.create_role(
|
20
|
+
name:, description: 'Allowed to test :)', permission_names: ['SSO Admin']
|
21
|
+
)
|
22
|
+
rescue Descope::AuthException => e
|
23
|
+
@logger.info("Role creation failed #{e}")
|
24
|
+
end
|
25
|
+
|
26
|
+
begin
|
27
|
+
@logger.info('Loading all roles')
|
28
|
+
roles_resp = @client.load_all_roles
|
29
|
+
roles = roles_resp['roles']
|
30
|
+
roles.each do |role|
|
31
|
+
@logger.info("Search Found role #{role}")
|
32
|
+
end
|
33
|
+
|
34
|
+
rescue Descope::AuthException => e
|
35
|
+
@logger.error("Role load failed #{e}")
|
36
|
+
end
|
37
|
+
|
38
|
+
begin
|
39
|
+
@logger.info('Updating newly created role')
|
40
|
+
@client.update_role(
|
41
|
+
name:,
|
42
|
+
new_name: 'My Updated Role',
|
43
|
+
description: 'New Description',
|
44
|
+
permission_names: ['User Admin']
|
45
|
+
)
|
46
|
+
|
47
|
+
rescue Descope::AuthException => e
|
48
|
+
@logger.error("Role update failed #{e}")
|
49
|
+
end
|
50
|
+
|
51
|
+
begin
|
52
|
+
@logger.info('Deleting newly created role')
|
53
|
+
@client.delete_role('My Updated Role')
|
54
|
+
|
55
|
+
rescue Descope::AuthException => e
|
56
|
+
@logger.error("Role deletion failed #{e}")
|
57
|
+
end
|
58
|
+
|
@@ -0,0 +1,60 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'descope'
|
5
|
+
|
6
|
+
@logger = Logger.new($stdout)
|
7
|
+
|
8
|
+
@project_id = ENV['DESCOPE_PROJECT_ID']
|
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
|
+
@client = Descope::Client.new({ project_id: @project_id, management_key: @management_key })
|
14
|
+
|
15
|
+
@tenant_id = ''
|
16
|
+
|
17
|
+
begin
|
18
|
+
@logger.info('Going to create a new tenant')
|
19
|
+
resp = @client.create_tenant(name: 'My First Tenant')
|
20
|
+
@tenant_id = resp['id']
|
21
|
+
@logger.info("Tenant creation response: #{resp}")
|
22
|
+
rescue Descope::AuthException => e
|
23
|
+
@logger.info("Tenant creation failed #{e}")
|
24
|
+
end
|
25
|
+
|
26
|
+
begin
|
27
|
+
@logger.info('Loading tenant by id')
|
28
|
+
tenant_resp = @client.load_tenant(@tenant_id)
|
29
|
+
@logger.info("Found tenant #{tenant_resp}")
|
30
|
+
rescue Descope::AuthException => e
|
31
|
+
@logger.info("Permission load failed #{e}")
|
32
|
+
end
|
33
|
+
|
34
|
+
begin
|
35
|
+
@logger.info('Loading all tenants')
|
36
|
+
tenants_resp = @client.load_all_tenants
|
37
|
+
tenants = tenants_resp['tenants']
|
38
|
+
tenants.each do |tenant|
|
39
|
+
@logger.info("Search Found tenant #{tenant}")
|
40
|
+
end
|
41
|
+
rescue Descope::AuthException => e
|
42
|
+
@logger.error("Permission load failed #{e}")
|
43
|
+
end
|
44
|
+
|
45
|
+
begin
|
46
|
+
@logger.info('Updating newly created tenant')
|
47
|
+
@client.update_tenant(
|
48
|
+
name: 'My First Tenant', id: @tenant_id, self_provisioning_domains: ['mydomain.com']
|
49
|
+
)
|
50
|
+
rescue Descope::AuthException => e
|
51
|
+
@logger.error("Tenant update failed #{e}")
|
52
|
+
end
|
53
|
+
|
54
|
+
begin
|
55
|
+
@logger.info('Deleting newly created tenant')
|
56
|
+
@client.delete_tenant(@tenant_id)
|
57
|
+
rescue Descope::AuthException => e
|
58
|
+
@logger.error("Tenant deletion failed #{e}")
|
59
|
+
end
|
60
|
+
|
@@ -0,0 +1,60 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'descope'
|
5
|
+
|
6
|
+
@logger = Logger.new($stdout)
|
7
|
+
|
8
|
+
@project_id = ENV['DESCOPE_PROJECT_ID']
|
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
|
+
@client = Descope::Client.new({ project_id: @project_id, management_key: @management_key })
|
14
|
+
|
15
|
+
user_login_id = 'des@copeland.com'
|
16
|
+
|
17
|
+
begin
|
18
|
+
@logger.info('Going to create a new user')
|
19
|
+
@client.create_user(login_id: user_login_id)
|
20
|
+
rescue Descope::AuthException => e
|
21
|
+
@logger.info("User creation failed #{e}")
|
22
|
+
end
|
23
|
+
|
24
|
+
begin
|
25
|
+
@logger.info('Searching for created user')
|
26
|
+
user_resp = @client.load_user(user_login_id)
|
27
|
+
user_res = user_resp['user']
|
28
|
+
@logger.info("Load: found user #{user_res}")
|
29
|
+
rescue Descope::AuthException => e
|
30
|
+
@logger.info("User load failed #{e}")
|
31
|
+
end
|
32
|
+
|
33
|
+
begin
|
34
|
+
@logger.info('Searching all users created user')
|
35
|
+
users_resp = @client.search_all_users
|
36
|
+
users = users_resp['users']
|
37
|
+
users.each do |user|
|
38
|
+
@logger.info("Search Found user #{user}")
|
39
|
+
end
|
40
|
+
rescue Descope::AuthException => e
|
41
|
+
@logger.info("User load failed #{e}")
|
42
|
+
end
|
43
|
+
|
44
|
+
begin
|
45
|
+
@logger.info('Updating newly created user')
|
46
|
+
# update overrides all fields, must provide the entire entity
|
47
|
+
# we mean to update.
|
48
|
+
@client.update_user(
|
49
|
+
login_id: user_login_id, name: 'Desmond Copeland'
|
50
|
+
)
|
51
|
+
rescue Descope::AuthException => e
|
52
|
+
@logger.info("User update failed #{e}")
|
53
|
+
end
|
54
|
+
|
55
|
+
begin
|
56
|
+
@logger.info('Deleting newly created user')
|
57
|
+
@client.delete_user(user_login_id)
|
58
|
+
rescue Descope::AuthException => e
|
59
|
+
@logger.info("User deletion failed #{e}")
|
60
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'descope'
|
5
|
+
require 'launchy'
|
6
|
+
|
7
|
+
@logger = Logger.new($stdout)
|
8
|
+
|
9
|
+
@project_id = ENV['DESCOPE_PROJECT_ID']
|
10
|
+
@management_key = ENV['DESCOPE_MANAGEMENT_KEY']
|
11
|
+
|
12
|
+
@logger.info("Initializing Descope API with project_id: #{@project_id} and base_uri: #{@base_uri}")
|
13
|
+
|
14
|
+
@client = Descope::Client.new({ project_id: @project_id, management_key: @management_key })
|
15
|
+
|
16
|
+
begin
|
17
|
+
@logger.info('Going to login with Oauth auth method ...')
|
18
|
+
resp = @client.oauth_start(provider: 'github', return_url: 'https://www.google.com')
|
19
|
+
@logger.info("oauth response: #{resp}")
|
20
|
+
|
21
|
+
# open the browser with the url
|
22
|
+
link = resp['url']
|
23
|
+
Launchy.open(link) # open the browser with the
|
24
|
+
|
25
|
+
|
26
|
+
puts "Please insert the code you received from redirect URI:\n"
|
27
|
+
code = gets.chomp
|
28
|
+
|
29
|
+
jwt_response = @client.oauth_exchange_token(code)
|
30
|
+
@logger.info('oauth code valid')
|
31
|
+
refresh_token = jwt_response['refreshSessionToken']['jwt']
|
32
|
+
my_details = @client.me(refresh_token)
|
33
|
+
@logger.info("my details: #{my_details}")
|
34
|
+
|
35
|
+
@client.sign_out(refresh_token)
|
36
|
+
@logger.info('User logged out')
|
37
|
+
rescue Descope::AuthException => e
|
38
|
+
@logger.error("Error: #{e.message}")
|
39
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'descope'
|
5
|
+
|
6
|
+
@logger = Logger.new($stdout)
|
7
|
+
|
8
|
+
@project_id = ENV['DESCOPE_PROJECT_ID']
|
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
|
+
@client = Descope::Client.new({ project_id: @project_id, management_key: @management_key })
|
14
|
+
|
15
|
+
begin
|
16
|
+
@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
|
+
|
23
|
+
puts "Please insert the code you received by email to #{masked_email}:\n"
|
24
|
+
value = gets.chomp
|
25
|
+
|
26
|
+
jwt_response = @client.otp_verify_code(
|
27
|
+
method: Descope::Mixins::Common::DeliveryMethod::EMAIL, login_id: email, code: value
|
28
|
+
)
|
29
|
+
@logger.info('Code is valid')
|
30
|
+
puts "jwt_response: #{jwt_response}"
|
31
|
+
session_token = jwt_response[Descope::Mixins::Common::SESSION_TOKEN_NAME].fetch('jwt')
|
32
|
+
refresh_token = jwt_response[Descope::Mixins::Common::REFRESH_SESSION_TOKEN_NAME].fetch('jwt')
|
33
|
+
@logger.info("jwt_response: #{jwt_response}")
|
34
|
+
|
35
|
+
@logger.info('going to validate session..')
|
36
|
+
@client.validate_session(session_token:)
|
37
|
+
@logger.info('Session is valid and all is OK')
|
38
|
+
|
39
|
+
@logger.info('refreshing the session token..')
|
40
|
+
claims = @client.refresh_session(refresh_token:)
|
41
|
+
@logger.info(
|
42
|
+
'going to revalidate the session with the newly refreshed token..'
|
43
|
+
)
|
44
|
+
|
45
|
+
new_session_token = claims.fetch(Descope::Mixins::Common::SESSION_TOKEN_NAME).fetch('jwt')
|
46
|
+
@client.validate_and_refresh_session(session_token: new_session_token, refresh_token:)
|
47
|
+
@logger.info('Session is valid also for the refreshed token.')
|
48
|
+
rescue Descope::AuthException => e
|
49
|
+
@logger.error("Error: #{e.message}")
|
50
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'descope'
|
5
|
+
|
6
|
+
@logger = Logger.new($stdout)
|
7
|
+
|
8
|
+
@project_id = ENV['DESCOPE_PROJECT_ID']
|
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
|
+
@client = Descope::Client.new({ project_id: @project_id, management_key: @management_key })
|
14
|
+
|
15
|
+
begin
|
16
|
+
@logger.info('Going to signup using password...')
|
17
|
+
puts 'Please insert email to signup with:\n'
|
18
|
+
email = gets.chomp
|
19
|
+
|
20
|
+
puts 'Please insert password to signup with:\n'
|
21
|
+
password = gets.chomp
|
22
|
+
|
23
|
+
jwt_response = @client.password_sign_up(login_id: email, password:)
|
24
|
+
@logger.info("Signup successful! jwt_response: #{jwt_response}")
|
25
|
+
puts "=> #{Descope::Mixins::Common::SESSION_TOKEN_NAME}"
|
26
|
+
session_token = jwt_response[Descope::Mixins::Common::SESSION_TOKEN_NAME].fetch('jwt')
|
27
|
+
refresh_token = jwt_response[Descope::Mixins::Common::REFRESH_SESSION_TOKEN_NAME].fetch('jwt')
|
28
|
+
|
29
|
+
@logger.info('Validating email address...')
|
30
|
+
@client.magiclink_update_user_email(login_id: email, email:, refresh_token:)
|
31
|
+
|
32
|
+
puts "Validation email send, please paste the token you received by email:\n"
|
33
|
+
token = gets.chomp
|
34
|
+
jwt_response = @client.magiclink_verify_token(token)
|
35
|
+
@logger.info('Token verified successfully! #{jwt_response}')
|
36
|
+
session_token = jwt_response[Descope::Mixins::Common::SESSION_TOKEN_NAME].fetch('jwt')
|
37
|
+
refresh_token = jwt_response[Descope::Mixins::Common::REFRESH_SESSION_TOKEN_NAME].fetch('jwt')
|
38
|
+
|
39
|
+
@logger.info('Going to reset password...')
|
40
|
+
@client.password_reset(login_id: email)
|
41
|
+
puts 'Reset password email send, please paste the token you received by email:\n'
|
42
|
+
token = gets.chomp
|
43
|
+
jwt_response = @client.magiclink_verify_token(token)
|
44
|
+
@logger.info('Token verified successfully!')
|
45
|
+
session_token = jwt_response[Descope::Mixins::Common::SESSION_TOKEN_NAME].fetch('jwt')
|
46
|
+
refresh_token = jwt_response[Descope::Mixins::Common::REFRESH_SESSION_TOKEN_NAME].fetch('jwt')
|
47
|
+
@logger.info("jwt_response: #{jwt_response}")
|
48
|
+
|
49
|
+
puts "Please insert new password:\n"
|
50
|
+
new_password = gets.chomp
|
51
|
+
@client.password_update(login_id: email, new_password:, refresh_token:)
|
52
|
+
@logger.info('Attempting to sign in with new password...')
|
53
|
+
jwt_response = @client.password_sign_in(login_id: email, password: new_password)
|
54
|
+
session_token = jwt_response[Descope::Mixins::Common::SESSION_TOKEN_NAME].fetch('jwt')
|
55
|
+
refresh_token = jwt_response[Descope::Mixins::Common::REFRESH_SESSION_TOKEN_NAME].fetch('jwt')
|
56
|
+
@logger.info("jwt_response: #{jwt_response}")
|
57
|
+
|
58
|
+
@logger.info('going to validate session...')
|
59
|
+
@client.validate_session(session_token:)
|
60
|
+
@logger.info('Session validated successfully and all is OK!')
|
61
|
+
|
62
|
+
@logger.info('refreshing the session token...')
|
63
|
+
claims = @client.refresh_session(refresh_token:)
|
64
|
+
@logger.info('going to revalidate the session with the newly refreshed token...')
|
65
|
+
|
66
|
+
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
|
+
@logger.info('Session is also valid for the refreshed token.')
|
69
|
+
|
70
|
+
@logger.info('going to sign out...')
|
71
|
+
@client.sign_out(refresh_token)
|
72
|
+
@logger.info('Session is signed out successfully.')
|
73
|
+
|
74
|
+
rescue Descope::AuthException => e
|
75
|
+
@logger.error("Error: #{e.message}")
|
76
|
+
end
|