kinde_sdk 1.0.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.
Files changed (128) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +15 -0
  3. data/Gemfile.lock +119 -0
  4. data/LICENSE +21 -0
  5. data/README.md +342 -0
  6. data/Rakefile +10 -0
  7. data/kinde_api/.gitignore +39 -0
  8. data/kinde_api/.rspec +2 -0
  9. data/kinde_api/README.md +103 -0
  10. data/kinde_api/docs/AddOrganizationUsers200Response.md +22 -0
  11. data/kinde_api/docs/AddOrganizationUsersRequest.md +18 -0
  12. data/kinde_api/docs/ApiResult.md +18 -0
  13. data/kinde_api/docs/ConnectedAppsAccessToken.md +20 -0
  14. data/kinde_api/docs/ConnectedAppsApi.md +219 -0
  15. data/kinde_api/docs/ConnectedAppsAuthUrl.md +20 -0
  16. data/kinde_api/docs/CreateOrganization201Response.md +20 -0
  17. data/kinde_api/docs/CreateOrganizationRequest.md +20 -0
  18. data/kinde_api/docs/CreateUser200Response.md +22 -0
  19. data/kinde_api/docs/CreateUserRequest.md +20 -0
  20. data/kinde_api/docs/CreateUserRequestIdentitiesInner.md +20 -0
  21. data/kinde_api/docs/CreateUserRequestIdentitiesInnerDetails.md +18 -0
  22. data/kinde_api/docs/CreateUserRequestProfile.md +20 -0
  23. data/kinde_api/docs/EnvironmentsApi.md +216 -0
  24. data/kinde_api/docs/Error.md +20 -0
  25. data/kinde_api/docs/ErrorResponse.md +18 -0
  26. data/kinde_api/docs/FeatureFlagsApi.md +239 -0
  27. data/kinde_api/docs/GetOrganizationUsers200Response.md +24 -0
  28. data/kinde_api/docs/GetOrganizations200Response.md +24 -0
  29. data/kinde_api/docs/GetUsers200Response.md +24 -0
  30. data/kinde_api/docs/OAuthApi.md +141 -0
  31. data/kinde_api/docs/Organization.md +22 -0
  32. data/kinde_api/docs/OrganizationUser.md +26 -0
  33. data/kinde_api/docs/OrganizationsApi.md +671 -0
  34. data/kinde_api/docs/RemoveOrganizationUsers200Response.md +20 -0
  35. data/kinde_api/docs/RemoveOrganizationUsersRequest.md +18 -0
  36. data/kinde_api/docs/SuccessResponse.md +20 -0
  37. data/kinde_api/docs/UpdateUserRequest.md +22 -0
  38. data/kinde_api/docs/User.md +28 -0
  39. data/kinde_api/docs/UserIdentity.md +20 -0
  40. data/kinde_api/docs/UserIdentityResult.md +20 -0
  41. data/kinde_api/docs/UserProfile.md +26 -0
  42. data/kinde_api/docs/UserProfileV2.md +30 -0
  43. data/kinde_api/docs/UsersApi.md +603 -0
  44. data/kinde_api/lib/kinde_api/api/connected_apps_api.rb +221 -0
  45. data/kinde_api/lib/kinde_api/api/environments_api.rb +212 -0
  46. data/kinde_api/lib/kinde_api/api/feature_flags_api.rb +309 -0
  47. data/kinde_api/lib/kinde_api/api/o_auth_api.rb +136 -0
  48. data/kinde_api/lib/kinde_api/api/organizations_api.rb +634 -0
  49. data/kinde_api/lib/kinde_api/api/users_api.rb +560 -0
  50. data/kinde_api/lib/kinde_api/api_client.rb +397 -0
  51. data/kinde_api/lib/kinde_api/api_error.rb +58 -0
  52. data/kinde_api/lib/kinde_api/configuration.rb +295 -0
  53. data/kinde_api/lib/kinde_api/models/add_organization_users200_response.rb +239 -0
  54. data/kinde_api/lib/kinde_api/models/add_organization_users_request.rb +220 -0
  55. data/kinde_api/lib/kinde_api/models/api_result.rb +218 -0
  56. data/kinde_api/lib/kinde_api/models/connected_apps_access_token.rb +228 -0
  57. data/kinde_api/lib/kinde_api/models/connected_apps_auth_url.rb +228 -0
  58. data/kinde_api/lib/kinde_api/models/create_organization201_response.rb +228 -0
  59. data/kinde_api/lib/kinde_api/models/create_organization_request.rb +252 -0
  60. data/kinde_api/lib/kinde_api/models/create_user200_response.rb +239 -0
  61. data/kinde_api/lib/kinde_api/models/create_user_request.rb +229 -0
  62. data/kinde_api/lib/kinde_api/models/create_user_request_identities_inner.rb +228 -0
  63. data/kinde_api/lib/kinde_api/models/create_user_request_identities_inner_details.rb +219 -0
  64. data/kinde_api/lib/kinde_api/models/create_user_request_profile.rb +229 -0
  65. data/kinde_api/lib/kinde_api/models/error.rb +228 -0
  66. data/kinde_api/lib/kinde_api/models/error_response.rb +219 -0
  67. data/kinde_api/lib/kinde_api/models/get_organization_users200_response.rb +249 -0
  68. data/kinde_api/lib/kinde_api/models/get_organizations200_response.rb +249 -0
  69. data/kinde_api/lib/kinde_api/models/get_users200_response.rb +249 -0
  70. data/kinde_api/lib/kinde_api/models/organization.rb +235 -0
  71. data/kinde_api/lib/kinde_api/models/organization_user.rb +253 -0
  72. data/kinde_api/lib/kinde_api/models/remove_organization_users200_response.rb +228 -0
  73. data/kinde_api/lib/kinde_api/models/remove_organization_users_request.rb +220 -0
  74. data/kinde_api/lib/kinde_api/models/success_response.rb +226 -0
  75. data/kinde_api/lib/kinde_api/models/update_user_request.rb +238 -0
  76. data/kinde_api/lib/kinde_api/models/user.rb +269 -0
  77. data/kinde_api/lib/kinde_api/models/user_identity.rb +227 -0
  78. data/kinde_api/lib/kinde_api/models/user_identity_result.rb +229 -0
  79. data/kinde_api/lib/kinde_api/models/user_profile.rb +259 -0
  80. data/kinde_api/lib/kinde_api/models/user_profile_v2.rb +279 -0
  81. data/kinde_api/lib/kinde_api/version.rb +15 -0
  82. data/kinde_api/lib/kinde_api.rb +73 -0
  83. data/kinde_api/spec/api/connected_apps_api_spec.rb +72 -0
  84. data/kinde_api/spec/api/environments_api_spec.rb +71 -0
  85. data/kinde_api/spec/api/feature_flags_api_spec.rb +82 -0
  86. data/kinde_api/spec/api/o_auth_api_spec.rb +57 -0
  87. data/kinde_api/spec/api/organizations_api_spec.rb +154 -0
  88. data/kinde_api/spec/api/users_api_spec.rb +141 -0
  89. data/kinde_api/spec/api_client_spec.rb +229 -0
  90. data/kinde_api/spec/configuration_spec.rb +42 -0
  91. data/kinde_api/spec/models/add_organization_users200_response_spec.rb +46 -0
  92. data/kinde_api/spec/models/add_organization_users_request_spec.rb +34 -0
  93. data/kinde_api/spec/models/api_result_spec.rb +34 -0
  94. data/kinde_api/spec/models/connected_apps_access_token_spec.rb +40 -0
  95. data/kinde_api/spec/models/connected_apps_auth_url_spec.rb +40 -0
  96. data/kinde_api/spec/models/create_organization201_response_spec.rb +40 -0
  97. data/kinde_api/spec/models/create_organization_request_spec.rb +44 -0
  98. data/kinde_api/spec/models/create_user200_response_spec.rb +46 -0
  99. data/kinde_api/spec/models/create_user_request_identities_inner_details_spec.rb +34 -0
  100. data/kinde_api/spec/models/create_user_request_identities_inner_spec.rb +40 -0
  101. data/kinde_api/spec/models/create_user_request_profile_spec.rb +40 -0
  102. data/kinde_api/spec/models/create_user_request_spec.rb +40 -0
  103. data/kinde_api/spec/models/error_response_spec.rb +34 -0
  104. data/kinde_api/spec/models/error_spec.rb +40 -0
  105. data/kinde_api/spec/models/get_organization_users200_response_spec.rb +52 -0
  106. data/kinde_api/spec/models/get_organizations200_response_spec.rb +52 -0
  107. data/kinde_api/spec/models/get_users200_response_spec.rb +52 -0
  108. data/kinde_api/spec/models/organization_spec.rb +46 -0
  109. data/kinde_api/spec/models/organization_user_spec.rb +58 -0
  110. data/kinde_api/spec/models/remove_organization_users200_response_spec.rb +40 -0
  111. data/kinde_api/spec/models/remove_organization_users_request_spec.rb +34 -0
  112. data/kinde_api/spec/models/success_response_spec.rb +40 -0
  113. data/kinde_api/spec/models/update_user_request_spec.rb +46 -0
  114. data/kinde_api/spec/models/user_identity_result_spec.rb +40 -0
  115. data/kinde_api/spec/models/user_identity_spec.rb +40 -0
  116. data/kinde_api/spec/models/user_profile_spec.rb +58 -0
  117. data/kinde_api/spec/models/user_profile_v2_spec.rb +70 -0
  118. data/kinde_api/spec/models/user_spec.rb +64 -0
  119. data/kinde_api/spec/spec_helper.rb +111 -0
  120. data/kinde_sdk.gemspec +33 -0
  121. data/lib/kinde_sdk/client.rb +49 -0
  122. data/lib/kinde_sdk/configuration.rb +50 -0
  123. data/lib/kinde_sdk/version.rb +3 -0
  124. data/lib/kinde_sdk.rb +109 -0
  125. data/openapitools.json +7 -0
  126. data/spec/kinde_sdk_spec.rb +105 -0
  127. data/spec/spec_helper.rb +82 -0
  128. metadata +291 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8682cdbb9fc753d2d2709a6af5daa79bbf0e58277a11140e12b77726bd69d58e
4
+ data.tar.gz: bef3ea899737940e81b08de2341f4f588640339b85b7ed607320f10e447cfb5e
5
+ SHA512:
6
+ metadata.gz: 71eb38523a787138251941b911893f4343f155db71c43dccc6b07946a12b7e67e589caeff5546ec793d5a9005ef84e68dc9ad13cb979737b57504bcc02d71127
7
+ data.tar.gz: 21b7c9219f45e7ecf2f7d7b8b4a2f549926c23b29553ba817d04db0b962f2ee4dda38e9f6de03042153a1072cbe28b62c4e92d3d5e6138ba106d624be13bfd0f
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :development, :test do
6
+ gem "rake", "~> 13.0.1"
7
+ gem "pry-byebug"
8
+ gem "rubocop"
9
+ gem "rubocop-rake", require: false
10
+ gem "rubocop-rspec", require: false
11
+ end
12
+
13
+ group :test do
14
+ gem "webmock"
15
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,119 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ kinde_sdk (1.0.0)
5
+ faraday-follow_redirects
6
+ oauth2 (~> 2.0)
7
+ pkce_challenge
8
+ typhoeus (~> 1.0, >= 1.0.1)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ addressable (2.8.3)
14
+ public_suffix (>= 2.0.2, < 6.0)
15
+ ast (2.4.2)
16
+ byebug (11.1.3)
17
+ coderay (1.1.3)
18
+ crack (0.4.5)
19
+ rexml
20
+ diff-lcs (1.5.0)
21
+ ethon (0.16.0)
22
+ ffi (>= 1.15.0)
23
+ faraday (2.7.4)
24
+ faraday-net_http (>= 2.0, < 3.1)
25
+ ruby2_keywords (>= 0.0.4)
26
+ faraday-follow_redirects (0.3.0)
27
+ faraday (>= 1, < 3)
28
+ faraday-net_http (3.0.2)
29
+ ffi (1.15.5)
30
+ hashdiff (1.0.1)
31
+ hashie (5.0.0)
32
+ json (2.6.3)
33
+ jwt (2.7.0)
34
+ method_source (1.0.0)
35
+ multi_xml (0.6.0)
36
+ oauth2 (2.0.9)
37
+ faraday (>= 0.17.3, < 3.0)
38
+ jwt (>= 1.0, < 3.0)
39
+ multi_xml (~> 0.5)
40
+ rack (>= 1.2, < 4)
41
+ snaky_hash (~> 2.0)
42
+ version_gem (~> 1.1)
43
+ parallel (1.22.1)
44
+ parser (3.2.2.0)
45
+ ast (~> 2.4.1)
46
+ pkce_challenge (1.0.0)
47
+ pry (0.14.2)
48
+ coderay (~> 1.1)
49
+ method_source (~> 1.0)
50
+ pry-byebug (3.10.1)
51
+ byebug (~> 11.0)
52
+ pry (>= 0.13, < 0.15)
53
+ public_suffix (5.0.1)
54
+ rack (3.0.7)
55
+ rainbow (3.1.1)
56
+ rake (13.0.6)
57
+ regexp_parser (2.7.0)
58
+ rexml (3.2.5)
59
+ rspec (3.12.0)
60
+ rspec-core (~> 3.12.0)
61
+ rspec-expectations (~> 3.12.0)
62
+ rspec-mocks (~> 3.12.0)
63
+ rspec-core (3.12.1)
64
+ rspec-support (~> 3.12.0)
65
+ rspec-expectations (3.12.2)
66
+ diff-lcs (>= 1.2.0, < 2.0)
67
+ rspec-support (~> 3.12.0)
68
+ rspec-mocks (3.12.5)
69
+ diff-lcs (>= 1.2.0, < 2.0)
70
+ rspec-support (~> 3.12.0)
71
+ rspec-support (3.12.0)
72
+ rubocop (1.49.0)
73
+ json (~> 2.3)
74
+ parallel (~> 1.10)
75
+ parser (>= 3.2.0.0)
76
+ rainbow (>= 2.2.2, < 4.0)
77
+ regexp_parser (>= 1.8, < 3.0)
78
+ rexml (>= 3.2.5, < 4.0)
79
+ rubocop-ast (>= 1.28.0, < 2.0)
80
+ ruby-progressbar (~> 1.7)
81
+ unicode-display_width (>= 2.4.0, < 3.0)
82
+ rubocop-ast (1.28.0)
83
+ parser (>= 3.2.1.0)
84
+ rubocop-capybara (2.17.1)
85
+ rubocop (~> 1.41)
86
+ rubocop-rake (0.6.0)
87
+ rubocop (~> 1.0)
88
+ rubocop-rspec (2.19.0)
89
+ rubocop (~> 1.33)
90
+ rubocop-capybara (~> 2.17)
91
+ ruby-progressbar (1.13.0)
92
+ ruby2_keywords (0.0.5)
93
+ snaky_hash (2.0.1)
94
+ hashie
95
+ version_gem (~> 1.1, >= 1.1.1)
96
+ typhoeus (1.4.0)
97
+ ethon (>= 0.9.0)
98
+ unicode-display_width (2.4.2)
99
+ version_gem (1.1.2)
100
+ webmock (3.18.1)
101
+ addressable (>= 2.8.0)
102
+ crack (>= 0.3.2)
103
+ hashdiff (>= 0.4.0, < 2.0.0)
104
+
105
+ PLATFORMS
106
+ arm64-darwin-21
107
+
108
+ DEPENDENCIES
109
+ kinde_sdk!
110
+ pry-byebug
111
+ rake (~> 13.0.1)
112
+ rspec (~> 3.6, >= 3.6.0)
113
+ rubocop
114
+ rubocop-rake
115
+ rubocop-rspec
116
+ webmock
117
+
118
+ BUNDLED WITH
119
+ 2.3.16
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Kinde
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,342 @@
1
+ # Kinde Ruby SDK
2
+
3
+ The Kinde Ruby SDK gem allows developers to integrate Kinde API into any ruby-based applications, Rails or non-Rails.
4
+ The gem contains all the related oauth2 authorization, so you need only to integrate it properly.
5
+ The gem contains 3 pre-built OAuth flows: **client credentials**, **authorization code** and **authorization code with PKCE code verifier**.
6
+
7
+ ## Register for Kinde
8
+
9
+ If you haven’t already got a Kinde account, register for free [here](http://app.kinde.com/register) (no credit card required).
10
+
11
+ You need a Kinde domain to get started, e.g. yourapp.kinde.com.
12
+
13
+ ## Installation
14
+
15
+ Add this line into your Gemfile and run bundler:
16
+ ```
17
+ gem 'kinde_sdk', git: 'https://github.com/kinde-oss/kinde-ruby-sdk.git', branch: 'main'
18
+ ```
19
+ or install manually through gem command.
20
+
21
+ ## Getting started
22
+
23
+ ### Kinde configuration
24
+
25
+ On the Kinde web app navigate to `Settings` in the left menu, then select `App keys` and find the `Callbacks` input field.
26
+
27
+ Here you want to put in the callback URLs for your application, which should look something like this:
28
+
29
+ - **Allowed callback URLs** - `http://localhost:3000/api/auth/kinde_callback`
30
+ - **Allowed logout redirect URLs** - `http://localhost:3000`
31
+
32
+ Make sure you press the Save button at the bottom of the page!
33
+
34
+ _Note_: The `http://localhost:3000` is used as an example of local address, don't forget to add all the required addresses that you are going to use in any environments.
35
+
36
+ ### Environments
37
+
38
+ If you would like to use our Environments feature as part of your development process. You will need to create them first within your Kinde account, see the guide here.
39
+ In this case you would use the Environment subdomain in the code block above.
40
+
41
+ ### Configuring your app
42
+
43
+ In a basic scenario it requires several steps to be made:
44
+ 1. proper configuring of client credentials and domain
45
+ 2. external service authorization
46
+ 3. callback processing
47
+ 4. bearer token receiving
48
+ 5. Usage
49
+
50
+ #### Integration
51
+ The gem contains simple configurator which you can use whenever you want. For example, in a typical Rails-app it can be
52
+ configured through initializer file:
53
+
54
+ ```ruby
55
+ # domain, client_id/secret and callback defined somewhere in your settings
56
+
57
+ KindeSdk.configure do |c|
58
+ c.domain = domain
59
+ c.client_id = client_id
60
+ c.client_secret = client_secret
61
+ c.callback_url = callback_url
62
+ c.logout_url = logout_url
63
+ # c.scope = 'openid offline email profile' # default value
64
+ # c.pkce_enabled = true # default value
65
+ # c.authorize_url = '/oauth2/auth' # default value
66
+ # c.token_url = '/oauth2/token' # default value
67
+ # c.debugging = false # default value
68
+ # c.business_name = nil # default value
69
+ c.logger = Rails.logger
70
+ end
71
+ ```
72
+ Snippet above contains all the possible configuration values.
73
+ Here is detailed explanation on them:
74
+
75
+ - `Domain` refers to your organization - for example, `your-biz.kinde.com`.
76
+ - `Client id` and `Client secret` can be fetched from your Kinde application credentials in a setting section.
77
+ - `Callback url` refers to your callback processing controller action. Remember that
78
+ the url must be defined in allowed callback urls of your kinde organization's [application config](#Kinde-configuration).
79
+ - `Logout url` will be triggered after successful logout on kinde. Same as callback url, it should be
80
+ defined in allowed logout urls of your kinde organization's application config
81
+ - `Scope` is an oauth special parameter which is used to limit some rights. Probably, you don't need to change in.
82
+ - `PKCE enabled` is a flag that can turn off PKCE auth flow. By default it is activated to improve your security.
83
+ - `Authorize url` and `Token url` are paths to oauth2 methods in kinde. You don't need to change it.
84
+ - `Debugging` set to true start writing verbose request logs. Might be useful while developing your application.
85
+ - `Business name` is a parameter which is used in requests building. By default it is extracted from your
86
+ `domain` endpoint. For example, if your domain is `your-biz.kinde.com`, then business name will be set to`your-biz`.
87
+ You don't need to change it in general.
88
+ - `Logger` might be set to any kind of loggers you are using. By default it is set to `Rails.logger` if gem is used in
89
+ rails application or `Logger.new(STDOUT)` if it is not a rails app.
90
+
91
+ These variables can be handled with any system you want: .env files, settings.yml or any type of config files.
92
+ For example, .env file (you can name variables by yourself):
93
+ ```
94
+ KINDE_DOMAIN=https://example.kinde.com
95
+ KINDE_CLIENT_ID=qwe
96
+ KINDE_CLIENT_SECRET=wert
97
+ KINDE_CALLBACK_URL=http://localhost:3000/callback
98
+ KINDE_LOGOUT_URL=http://localhost:3000/logout_callback
99
+ ```
100
+
101
+ can be used as:
102
+ ```ruby
103
+ KindeSdk.configure do |c|
104
+ c.domain = ENV['KINDE_DOMAIN']
105
+ c.client_id = ENV['KINDE_CLIENT_ID']
106
+ # ....
107
+ end
108
+ ```
109
+
110
+ #### Login / Register
111
+ The next step is to authorize you in the Kinde.
112
+ For this, you need to acquire auth url by calling:
113
+ ```ruby
114
+ KindeSdk.auth_url
115
+ # =>
116
+ {
117
+ url: "https://<domain>/oauth2/auth?client_id=<client_id>&code_challenge=<generated code>&code_challenge_method=S256&redirect_uri=<redirect_uri>&response_type=code&scope=openid+offline+email+profile&state=<random string>",
118
+ code_verifier: "<challenge verifier>"
119
+ }
120
+ ```
121
+ By default, gem uses PKCE verification flow - this means that in your auth url will be added special `code challenge`
122
+ param and the method returns verification string for the code, which should be used later in token acquiring request.
123
+ You are free to disable PKCE by setting `pkce_enabled` to false in your configuration.
124
+ In this case, `KindeSdk.auth_url` will return only url itself:
125
+ ```ruby
126
+ KindeSdk.auth_url
127
+ # => {url: ......}
128
+ ```
129
+ If you are about to use PCKE, our recommendation to save code verifier output somewhere near your later tokens output.
130
+
131
+ You can put the link right in your web-application page or you can use it under the hood through redirection.
132
+ After visiting the link you'll be redirected to Kinde's sign in/sign up form.
133
+ And after authorizing in Kinde, you'll be redirected to callback url.
134
+
135
+ #### Handle redirect
136
+ Next step is to extract code from the callback redirection. Your callback endpoint should contain logic to call exchange method.
137
+ Callback will be triggered with body, where will be code present. You are free to use the whole `params` object or to extract code from `params["code"]`.
138
+
139
+ Next, it needs to be exchanged for the access and refresh tokens.
140
+ `code` is the parameter which received in the callback endpoint, `code_verifier` (if PKCE enabled) should be used from previous step:
141
+ ```ruby
142
+ KindeSdk.fetch_tokens(code, code_verifier)
143
+ # =>
144
+ {"access_token"=>"eyJhbGciOiJSUzI1NiIsIm...",
145
+ "expires_in"=>86399,
146
+ "id_token"=>"eyJhbGciOiJSUz",
147
+ "refresh_token"=>"eyJhbGciOiJSUz",
148
+ "scope"=>"openid offline email profile",
149
+ "token_type"=>"bearer"}
150
+ ```
151
+
152
+ This is your tokens - save the whole hash in your session, redis or any other storage and use it to build your client:
153
+ ```ruby
154
+ # In case of preventing cookie overflow, you need to limit what exactly your are saving.
155
+ # Here is the required minimum of params. But in general you are able save it wherever you want to.
156
+ # For example, in database, without any limiting.
157
+ session[:kinde_auth] = KindeSdk.fetch_tokens(code).slice(:access_token, :refresh_token, :expires_at)
158
+ # ...
159
+ client = KindeSdk.client(session[:kinde_auth]["access_token"]) # => #<KindeSdk::Client:0x00007faf31e5ecb8>
160
+ ```
161
+
162
+ #### Token expiration and refreshing
163
+ For proper refreshing you'll need to use `access_token`, `refresh_token` and probably `expires_in` if you want to know is your access token still actual.
164
+ Use these two methods to work with refreshing:
165
+ ```ruby
166
+ KindeSdk.token_expired?(session[:kinde_auth]) # => false
167
+ KindeSdk.refresh_token(session[:kinde_auth]) # => {"access_token" => "qwe...", "refresh_token" => "fqw...", .....}
168
+ ```
169
+ `KindeSdk#refresh_token` returns new token hash, so it needs to be updated in your storage.
170
+
171
+ #### Audience
172
+ An `audience` is the intended recipient of an access token - for example the API for your application.
173
+ The audience argument can be passed to the Kinde `#auth_url` method to request an audience be added to the provided token:
174
+ ```ruby
175
+ KindeSdk.auth_url(audience: "https://your-app.kinde.com/api")
176
+ ```
177
+ For details on how to connect, see [Register an API](https://kinde.com/docs/developer-tools/register-an-api/)
178
+
179
+ #### Overriding scope
180
+ By default `KindeSdk` requests the following scopes:
181
+
182
+ - profile
183
+ - email
184
+ - offline
185
+ - openid
186
+
187
+ You are able to change it - by configuring as mentioned at [Integration](#integration) or by direct param passing into `auth_url` method:
188
+ ```ruby
189
+ KindeSdk.auth_url(scope: "openid offline")
190
+ ```
191
+
192
+ #### Getting claims
193
+ We have provided a helper to grab any claim from your id or access tokens. The helper defaults to access tokens:
194
+ ```ruby
195
+ client = KindeSdk.client(session[:kinde_auth]["access_token"])
196
+ client.get_claim("aud") #=> ['api.yourapp.com']
197
+ client.get_claim("scp") #=> ["openid", "offline"]
198
+ ```
199
+
200
+ #### User permissions
201
+ After a user signs in and they are verified, the token return includes permissions for that user.
202
+ [User permissions](https://kinde.com/docs/user-management/user-permissions) are set in Kinde,
203
+ but you must also configure your application to unlock these functions.
204
+ ```
205
+ permissions" => [
206
+ "create:todos",
207
+ "update:todos",
208
+ "read:todos",
209
+ "delete:todos",
210
+ "create:tasks",
211
+ "update:tasks",
212
+ "read:tasks",
213
+ "delete:tasks",
214
+ ]
215
+ ```
216
+ We provide helper functions to more easily access permissions:
217
+ ```ruby
218
+ client = KindeSdk.client(session[:kinde_auth]["access_token"])
219
+ client.get_permission("create:todos") # => {org_code: "org_1234", is_granted: true}
220
+ client.permission_granted?("create:todos") # => true
221
+ client.permission_granted?("create:orders") # => false
222
+ ```
223
+
224
+ #### Client usage
225
+ API part is mounted in the `KindeSdk::Client` instance, so the short usage is just simple as:
226
+ ```ruby
227
+ client.oauth.get_user
228
+ client.users.create_user(args)
229
+ client.organizations.get_organizations
230
+ ```
231
+ The method name will be the same as API module from sdk without `-Api` part in the end.
232
+ Alternatively, you can initialize each API module by yourself:
233
+ ```ruby
234
+ # use initialized and configured api client
235
+ api_client = KindeSdk.api_client(access_token)
236
+ instance_client = KindeApi::UsersApi.new(api_client)
237
+ instance_client.create_user(args)
238
+ ```
239
+
240
+ #### Logout
241
+ For logout you need to call:
242
+ ```ruby
243
+ instance_client.logout
244
+ # or
245
+ KindeSdk.logout(access_token)
246
+ ```
247
+ then clear your session or storage (delete your token) and redirect wherever you want to.
248
+ If you configured logout redirect url correct (e.g. added in the admin panel allowed logout redirect), you can receive
249
+ a logout callback. Use it if it needs to perform some clean-ups or any other jobs.
250
+
251
+ ### Organizations
252
+ #### Create an organization
253
+ To have a new organization created within your application, you will need to run something like:
254
+ ```ruby
255
+ client.organizations.create_organization(create_organization_request: {name: "new_org"})
256
+ # or `client.organizations.create_organization` without name
257
+ ```
258
+
259
+ ### Sign up and sign in to organizations
260
+ Kinde has a unique code for every organization.
261
+ If you want a user to sign into a particular organization, call the `#auth_url` method with `org_code` param passing:
262
+ ```ruby
263
+ KindeSdk.auth_url(org_code: "org_1234", start_page: "registration") # to enforce new user creation form
264
+ KindeSdk.auth_url(org_code: "org_1234") # to login by default
265
+ ```
266
+
267
+ Following authentication, Kinde provides a json web token (jwt) to your application.
268
+ Along with the standard information we also include the `org_code` and the permissions for that organization (this is important as a user can belong to multiple organizations and have different permissions for each).
269
+
270
+ Example of a returned token:
271
+ ```ruby
272
+ [
273
+ {
274
+ "aud" => [],
275
+ "exp" => 1658475930,
276
+ "iat" => 1658472329,
277
+ "iss" => "https://your_subdomain.kinde.com",
278
+ "jti" => "123457890",
279
+ "org_code" => "org_1234",
280
+ "permissions" => ["read:todos", "create:todos"],
281
+ "scp" => [
282
+ "openid",
283
+ "profile",
284
+ "email",
285
+ "offline"
286
+ ],
287
+ "sub" => "kp:123457890"
288
+ }
289
+ ]
290
+ ```
291
+ The `id_token` will also contain an array of organizations that a user belongs to - this is useful if you wanted to build out an organization switcher for example:
292
+ ```ruby
293
+ client.get_claim("org_codes") # => ["org_1234", "org_5462"]
294
+ ```
295
+
296
+ ### API reference
297
+ Detailed API reference described in [KindeSDK README](kinde-sdk/README.md) and underlying description docs.
298
+ Here are some selected examples of usage.
299
+
300
+ #### Getting user info
301
+
302
+ ```ruby
303
+ KindeSdk.client(session[:kinde_auth]["access_token"]).oauth.get_user
304
+ # => {id: ..., preferred_email: ..., provided_id: ..., last_name: ..., first_name: ...}
305
+ ```
306
+
307
+ #### Management API
308
+ These sections below are part of management API. It should be configured first at your Kinde account
309
+ [Here is detailed note about it](https://kinde.notion.site/Management-API-via-client_credentials-240e6fa548c144828d4981ddbaa0f6b2),
310
+ you need to add `Machine to Machine` (M2M) application and use another grant type for authorization:
311
+ ```ruby
312
+ result = KindeSdk.client_credentials_access(
313
+ client_id: ENV["KINDE_MANAGEMENT_CLIENT_ID"],
314
+ client_secret: ENV["KINDE_MANAGEMENT_CLIENT_SECRET"]
315
+ )
316
+ # as an example of usage redis to save access token:
317
+ $redis.set("kinde_m2m_token", result["access_token"], ex: result["expires_in"].to_i)
318
+ ```
319
+
320
+ ##### Organizations handling
321
+ ```ruby
322
+ client = KindeSdk.client($redis.get("kinde_m2m_token"))
323
+ # get organizations list:
324
+ client.organizations.get_organizations
325
+ # => {"code": "OK", "message": "Success", "next_token": "qweqweqwe", "organizations": [{"code": "org_casda123c", "name": "Default Organization", "is_default": true}]}
326
+
327
+ # create new organization:
328
+ client.organizations.create_organization(create_organization_request: {name: "new_org"})
329
+ # this variant for more strict input params validation:
330
+ # client.organizations.create_organization(create_organization_request: KindeApi::CreateOrganizationRequest.new(name: new_org_name))
331
+ ```
332
+
333
+ #### Create new user
334
+ ```ruby
335
+ client.users.create_user
336
+ ```
337
+
338
+ #### Add organization users
339
+
340
+ ```ruby
341
+ client.organizations.add_organization_users(code: "org_1111", users: ["kp:12311...."])
342
+ ```
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ begin
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec) do |t|
7
+ t.pattern = ['spec/*_spec.rb', 'kinde_api/spec/*_spec.rb', 'kinde_api/spec/*/*_spec.rb']
8
+ end
9
+ task default: :spec
10
+ end
@@ -0,0 +1,39 @@
1
+ # Generated by: https://openapi-generator.tech
2
+ #
3
+
4
+ *.gem
5
+ *.rbc
6
+ /.config
7
+ /coverage/
8
+ /InstalledFiles
9
+ /pkg/
10
+ /spec/reports/
11
+ /spec/examples.txt
12
+ /test/tmp/
13
+ /test/version_tmp/
14
+ /tmp/
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+
21
+ ## Documentation cache and generated files:
22
+ /.yardoc/
23
+ /_yardoc/
24
+ /doc/
25
+ /rdoc/
26
+
27
+ ## Environment normalization:
28
+ /.bundle/
29
+ /vendor/bundle
30
+ /lib/bundler/man/
31
+
32
+ # for a library or gem, you might want to ignore these files since the code is
33
+ # intended to run in multiple environments; otherwise, check them in:
34
+ # Gemfile.lock
35
+ # .ruby-version
36
+ # .ruby-gemset
37
+
38
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
39
+ .rvmrc
data/kinde_api/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,103 @@
1
+ ## Getting Started
2
+
3
+ ```ruby
4
+ # Load the gem
5
+ require 'kinde_api'
6
+
7
+ # Setup authorization
8
+ KindeApi.configure do |config|
9
+ # Configure Bearer authorization (JWT): kindeBearerAuth
10
+ config.access_token = 'YOUR_BEARER_TOKEN'
11
+ # Configure a proc to get access tokens in lieu of the static access_token configuration
12
+ config.access_token_getter = -> { 'YOUR TOKEN GETTER PROC' }
13
+ end
14
+
15
+ api_instance = KindeApi::ConnectedAppsApi.new
16
+ key_code_ref = 'key_code_ref_example' # String | The unique key code reference of the connected app to authenticate against.
17
+ user_id = 56 # Integer | The id of the user that needs to authenticate to the third-party connected app.
18
+
19
+ begin
20
+ #Get Connected App URL
21
+ result = api_instance.get_connected_app_auth_url(key_code_ref, user_id)
22
+ p result
23
+ rescue KindeApi::ApiError => e
24
+ puts "Exception when calling ConnectedAppsApi->get_connected_app_auth_url: #{e}"
25
+ end
26
+
27
+ ```
28
+
29
+ ## Documentation for API Endpoints
30
+
31
+ All URIs are relative to *https://app.kinde.com*
32
+
33
+ Class | Method | HTTP request | Description
34
+ ------------ | ------------- | ------------- | -------------
35
+ *KindeApi::ConnectedAppsApi* | [**get_connected_app_auth_url**](docs/ConnectedAppsApi.md#get_connected_app_auth_url) | **GET** /api/v1/connected_apps/auth_url | Get Connected App URL
36
+ *KindeApi::ConnectedAppsApi* | [**get_connected_app_token**](docs/ConnectedAppsApi.md#get_connected_app_token) | **GET** /api/v1/connected_apps/token | Get Connected App Token
37
+ *KindeApi::ConnectedAppsApi* | [**revoke_connected_app_token**](docs/ConnectedAppsApi.md#revoke_connected_app_token) | **POST** /api/v1/connected_apps/revoke | Revoke Connected App Token
38
+ *KindeApi::EnvironmentsApi* | [**delete_environement_feature_flag_override**](docs/EnvironmentsApi.md#delete_environement_feature_flag_override) | **DELETE** /api/v1/environment/feature_flags/{feature_flag_key} | Delete environment feature flag override
39
+ *KindeApi::EnvironmentsApi* | [**delete_environement_feature_flag_overrides**](docs/EnvironmentsApi.md#delete_environement_feature_flag_overrides) | **DELETE** /api/v1/environment/feature_flags/ | Delete all environment feature flag overrides
40
+ *KindeApi::EnvironmentsApi* | [**update_environement_feature_flag_override**](docs/EnvironmentsApi.md#update_environement_feature_flag_override) | **PATCH** /api/v1/environment/feature_flags/{feature_flag_key} | Update environment feature flag override
41
+ *KindeApi::FeatureFlagsApi* | [**create_feature_flag**](docs/FeatureFlagsApi.md#create_feature_flag) | **POST** /api/v1/feature_flags | Create a new feature flag
42
+ *KindeApi::FeatureFlagsApi* | [**delete_feature_flag**](docs/FeatureFlagsApi.md#delete_feature_flag) | **DELETE** /api/v1/feature_flags/{feature_flag_key} | Delete a feature flag
43
+ *KindeApi::FeatureFlagsApi* | [**update_feature_flag**](docs/FeatureFlagsApi.md#update_feature_flag) | **PUT** /api/v1/feature_flags/{feature_flag_key} | Update a feature flag
44
+ *KindeApi::OAuthApi* | [**get_user**](docs/OAuthApi.md#get_user) | **GET** /oauth2/user_profile | Returns the details of the currently logged in user
45
+ *KindeApi::OAuthApi* | [**get_user_profile_v2**](docs/OAuthApi.md#get_user_profile_v2) | **GET** /oauth2/v2/user_profile | Returns the details of the currently logged in user
46
+ *KindeApi::OrganizationsApi* | [**add_organization_users**](docs/OrganizationsApi.md#add_organization_users) | **POST** /api/v1/organization/users | Assign Users to an Organization
47
+ *KindeApi::OrganizationsApi* | [**create_organization**](docs/OrganizationsApi.md#create_organization) | **POST** /api/v1/organization | Create Organization
48
+ *KindeApi::OrganizationsApi* | [**delete_organization_feature_flag_override**](docs/OrganizationsApi.md#delete_organization_feature_flag_override) | **DELETE** /api/v1/organizations/{org_code}/feature_flags/{feature_flag_key} | Delete organization feature flag override
49
+ *KindeApi::OrganizationsApi* | [**delete_organization_feature_flag_overrides**](docs/OrganizationsApi.md#delete_organization_feature_flag_overrides) | **DELETE** /api/v1/organizations/{org_code}/feature_flags | Delete all organization feature flag overrides
50
+ *KindeApi::OrganizationsApi* | [**get_organization**](docs/OrganizationsApi.md#get_organization) | **GET** /api/v1/organization | Get Organization
51
+ *KindeApi::OrganizationsApi* | [**get_organization_users**](docs/OrganizationsApi.md#get_organization_users) | **GET** /api/v1/organization/users | List Organization Users
52
+ *KindeApi::OrganizationsApi* | [**get_organizations**](docs/OrganizationsApi.md#get_organizations) | **GET** /api/v1/organizations | List Organizations
53
+ *KindeApi::OrganizationsApi* | [**remove_organization_users**](docs/OrganizationsApi.md#remove_organization_users) | **PATCH** /api/v1/organization/users | Remove Users from an Organization
54
+ *KindeApi::OrganizationsApi* | [**update_organization_feature_flag_override**](docs/OrganizationsApi.md#update_organization_feature_flag_override) | **PATCH** /api/v1/organizations/{org_code}/feature_flags/{feature_flag_key} | Update organization feature flag override
55
+ *KindeApi::UsersApi* | [**add_organization_users**](docs/UsersApi.md#add_organization_users) | **POST** /api/v1/organization/users | Assign Users to an Organization
56
+ *KindeApi::UsersApi* | [**create_user**](docs/UsersApi.md#create_user) | **POST** /api/v1/user | Create User
57
+ *KindeApi::UsersApi* | [**deleteuser**](docs/UsersApi.md#deleteuser) | **DELETE** /api/v1/user | Delete User
58
+ *KindeApi::UsersApi* | [**get_organization_users**](docs/UsersApi.md#get_organization_users) | **GET** /api/v1/organization/users | List Organization Users
59
+ *KindeApi::UsersApi* | [**get_user_data**](docs/UsersApi.md#get_user_data) | **GET** /api/v1/user | Get User
60
+ *KindeApi::UsersApi* | [**get_users**](docs/UsersApi.md#get_users) | **GET** /api/v1/users | List Users
61
+ *KindeApi::UsersApi* | [**remove_organization_users**](docs/UsersApi.md#remove_organization_users) | **PATCH** /api/v1/organization/users | Remove Users from an Organization
62
+ *KindeApi::UsersApi* | [**update_user**](docs/UsersApi.md#update_user) | **PATCH** /api/v1/user | Update User
63
+
64
+
65
+ ## Documentation for Models
66
+
67
+ - [KindeApi::AddOrganizationUsers200Response](docs/AddOrganizationUsers200Response.md)
68
+ - [KindeApi::AddOrganizationUsersRequest](docs/AddOrganizationUsersRequest.md)
69
+ - [KindeApi::ApiResult](docs/ApiResult.md)
70
+ - [KindeApi::ConnectedAppsAccessToken](docs/ConnectedAppsAccessToken.md)
71
+ - [KindeApi::ConnectedAppsAuthUrl](docs/ConnectedAppsAuthUrl.md)
72
+ - [KindeApi::CreateOrganization201Response](docs/CreateOrganization201Response.md)
73
+ - [KindeApi::CreateOrganizationRequest](docs/CreateOrganizationRequest.md)
74
+ - [KindeApi::CreateUser200Response](docs/CreateUser200Response.md)
75
+ - [KindeApi::CreateUserRequest](docs/CreateUserRequest.md)
76
+ - [KindeApi::CreateUserRequestIdentitiesInner](docs/CreateUserRequestIdentitiesInner.md)
77
+ - [KindeApi::CreateUserRequestIdentitiesInnerDetails](docs/CreateUserRequestIdentitiesInnerDetails.md)
78
+ - [KindeApi::CreateUserRequestProfile](docs/CreateUserRequestProfile.md)
79
+ - [KindeApi::Error](docs/Error.md)
80
+ - [KindeApi::ErrorResponse](docs/ErrorResponse.md)
81
+ - [KindeApi::GetOrganizationUsers200Response](docs/GetOrganizationUsers200Response.md)
82
+ - [KindeApi::GetOrganizations200Response](docs/GetOrganizations200Response.md)
83
+ - [KindeApi::GetUsers200Response](docs/GetUsers200Response.md)
84
+ - [KindeApi::Organization](docs/Organization.md)
85
+ - [KindeApi::OrganizationUser](docs/OrganizationUser.md)
86
+ - [KindeApi::RemoveOrganizationUsers200Response](docs/RemoveOrganizationUsers200Response.md)
87
+ - [KindeApi::RemoveOrganizationUsersRequest](docs/RemoveOrganizationUsersRequest.md)
88
+ - [KindeApi::SuccessResponse](docs/SuccessResponse.md)
89
+ - [KindeApi::UpdateUserRequest](docs/UpdateUserRequest.md)
90
+ - [KindeApi::User](docs/User.md)
91
+ - [KindeApi::UserIdentity](docs/UserIdentity.md)
92
+ - [KindeApi::UserIdentityResult](docs/UserIdentityResult.md)
93
+ - [KindeApi::UserProfile](docs/UserProfile.md)
94
+ - [KindeApi::UserProfileV2](docs/UserProfileV2.md)
95
+
96
+
97
+ ## Documentation for Authorization
98
+
99
+
100
+ ### kindeBearerAuth
101
+
102
+ - **Type**: Bearer authentication (JWT)
103
+