kinde_sdk 1.0.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8682cdbb9fc753d2d2709a6af5daa79bbf0e58277a11140e12b77726bd69d58e
4
- data.tar.gz: bef3ea899737940e81b08de2341f4f588640339b85b7ed607320f10e447cfb5e
3
+ metadata.gz: 3166fc3f21315cb21235d7c303440266daef8b2d4b37d983e2bc06bb28fd5acd
4
+ data.tar.gz: 7421f7964d90a458b47724a4073711480a6caeac1cc6fe3e68989dfbe2045821
5
5
  SHA512:
6
- metadata.gz: 71eb38523a787138251941b911893f4343f155db71c43dccc6b07946a12b7e67e589caeff5546ec793d5a9005ef84e68dc9ad13cb979737b57504bcc02d71127
7
- data.tar.gz: 21b7c9219f45e7ecf2f7d7b8b4a2f549926c23b29553ba817d04db0b962f2ee4dda38e9f6de03042153a1072cbe28b62c4e92d3d5e6138ba106d624be13bfd0f
6
+ metadata.gz: 380bac0d796adc5daf5b55faea19d130e32fc248b2e2fb5f91e0e74bb267b4ac617fb1f51163ce2871a0c78ed2447161a8be316f972a20d694dfd9a665b9fb2c
7
+ data.tar.gz: d667129a0d21dca7dd07baecedc96e78470eb0952744c7921e2bdb96445524bb378eef2625c99c87b6357ff1183b44e32e1df93fea1f05bf518bb926f53a51d8
data/README.md CHANGED
@@ -83,8 +83,9 @@ defined in allowed logout urls of your kinde organization's application config
83
83
  - `Authorize url` and `Token url` are paths to oauth2 methods in kinde. You don't need to change it.
84
84
  - `Debugging` set to true start writing verbose request logs. Might be useful while developing your application.
85
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.
86
+ `domain` endpoint. For example, if your domain is `https://your-biz.kinde.com`, then business name will be set
87
+ to `your-biz`, for `https://example-chamois.au.kinde.com` it'll be `example-chamois.au` and so on.
88
+ You don't need to change it in general, but it is possible to override if needed.
88
89
  - `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
90
  rails application or `Logger.new(STDOUT)` if it is not a rails app.
90
91
 
@@ -238,15 +239,23 @@ instance_client.create_user(args)
238
239
  ```
239
240
 
240
241
  #### Logout
241
- For logout you need to call:
242
+ For logout you need to call (in case of rails app) in your controller:
242
243
  ```ruby
243
- instance_client.logout
244
- # or
245
- KindeSdk.logout(access_token)
244
+ redirect_to KindeSdk.logout_url, allow_other_host: true
245
+ ```
246
+ Your app should handle logout callback url (which was configured separately).
247
+ After calling redirect to logout_url (if set), Kinde redirect it back to logout callback path, where you need to clear your session:
248
+ ```ruby
249
+ # .......
250
+ def logout_callback
251
+ Rails.logger.info("logout callback successfully received")
252
+ reset_session
253
+ redirect_to root_path
254
+ end
255
+ # ......
246
256
  ```
247
- then clear your session or storage (delete your token) and redirect wherever you want to.
248
257
  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.
258
+ a logout callback. Otherwise Kinde logout message will be shown.
250
259
 
251
260
  ### Organizations
252
261
  #### Create an organization
@@ -30,10 +30,6 @@ module KindeSdk
30
30
  get_claim("permissions").include?(permission)
31
31
  end
32
32
 
33
- def logout
34
- KindeSdk.logout(bearer_token, kinde_api_client)
35
- end
36
-
37
33
  ::KindeApi.constants.filter { |klass| klass.to_s.end_with?("Api") }.each do |klass|
38
34
  api_klass = Kernel.const_get("KindeApi::#{klass}")
39
35
 
@@ -1,3 +1,3 @@
1
1
  module KindeSdk
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.1"
3
3
  end
data/lib/kinde_sdk.rb CHANGED
@@ -56,13 +56,10 @@ module KindeSdk
56
56
  KindeSdk::Client.new(sdk_api_client, bearer_token)
57
57
  end
58
58
 
59
- def logout(bearer_token, sdk_api_client = nil)
60
- (sdk_api_client || api_client(bearer_token))
61
- .call_api(
62
- :get, '/logout',
63
- query_params: { 'redirect' => @config.logout_url },
64
- header_params: { 'Authorization' => "Bearer #{bearer_token}" }
65
- )
59
+ def logout_url
60
+ query = @config.logout_url ? URI.encode_www_form(redirect: @config.logout_url) : nil
61
+ host = URI::parse(@config.domain).host
62
+ URI::HTTP.build(host: host, path: '/logout', query: query).to_s
66
63
  end
67
64
 
68
65
  def client_credentials_access(
@@ -97,7 +94,7 @@ module KindeSdk
97
94
  config = KindeApi::Configuration.default
98
95
  config.configure do |c|
99
96
  c.access_token = bearer_token
100
- c.server_variables = { businessName: @config.business_name || @config.domain.split("//")[1].split(".")[0] }
97
+ c.server_variables = { businessName: business_name }
101
98
  c.host = @config.domain
102
99
  c.debugging = @config.debugging
103
100
  c.logger = @config.logger
@@ -105,5 +102,13 @@ module KindeSdk
105
102
 
106
103
  KindeApi::ApiClient.new(config)
107
104
  end
105
+
106
+ private
107
+
108
+ def business_name
109
+ # from https://example.kinde.com fetches `example`
110
+ # from https://example-chamois.au.kinde.com fetches `example-chamois.au`
111
+ @config.business_name || @config.domain.split("//")[1].split(".")[0..-3].join(".")
112
+ end
108
113
  end
109
114
  end
@@ -5,6 +5,7 @@ describe KindeSdk do
5
5
  let(:client_id) { "client_id" }
6
6
  let(:client_secret) { "client_secret" }
7
7
  let(:callback_url) { "http://localhost:3000/callback" }
8
+ let(:logout_url) { "http://localhost/logout-callback" }
8
9
 
9
10
  before do
10
11
  KindeSdk.configure do |c|
@@ -12,6 +13,7 @@ describe KindeSdk do
12
13
  c.client_id = client_id
13
14
  c.client_secret = client_secret
14
15
  c.callback_url = callback_url
16
+ c.logout_url = logout_url
15
17
  end
16
18
  end
17
19
 
@@ -23,6 +25,20 @@ describe KindeSdk do
23
25
  end
24
26
  end
25
27
 
28
+ describe "#logout_url" do
29
+ it "returns logout url" do
30
+ expect(described_class.logout_url)
31
+ .to eq("http://example.com/logout?redirect=http%3A%2F%2Flocalhost%2Flogout-callback")
32
+ end
33
+
34
+ context "when logout url not set" do
35
+ let(:logout_url) { nil }
36
+ it "returns logout url without redirect query" do
37
+ expect(described_class.logout_url).to eq("http://example.com/logout")
38
+ end
39
+ end
40
+ end
41
+
26
42
  describe "#api_client" do
27
43
  it "returns initialized api_client instance of KindeApi" do
28
44
  expect(described_class.api_client("bearer-token")).to be_instance_of(KindeApi::ApiClient)
@@ -59,16 +75,16 @@ describe KindeSdk do
59
75
  describe "client" do
60
76
  let(:hash_to_encode) do
61
77
  { "aud" => [],
62
- "azp" => "19ebb687cd2f405c9f2daf645a8db895",
63
- "exp" => 1679600554,
64
- "feature_flags" => nil,
65
- "iat" => 1679514154,
66
- "iss" => "https://qwv2.kinde.com",
67
- "jti" => "22c48b2c-da46-4661-a7ff-425c23eceab5",
68
- "org_code" => "org_cb4544175bc",
69
- "permissions" => ["read:todos", "create:todos"],
70
- "scp" => ["openid", "offline"],
71
- "sub" => "kp:b17adf719f7d4b87b611d1a88a09fd15" }
78
+ "azp" => "19ebb687cd2f405c9f2daf645a8db895",
79
+ "exp" => 1679600554,
80
+ "feature_flags" => nil,
81
+ "iat" => 1679514154,
82
+ "iss" => "https://example.kinde.com",
83
+ "jti" => "22c48b2c-da46-4661-a7ff-425c23eceab5",
84
+ "org_code" => "org_cb4544175bc",
85
+ "permissions" => ["read:todos", "create:todos"],
86
+ "scp" => ["openid", "offline"],
87
+ "sub" => "kp:b17adf719f7d4b87b611d1a88a09fd15" }
72
88
  end
73
89
  let(:token) { JWT.encode(hash_to_encode, nil, "none") }
74
90
  let(:client) { described_class.client(token) }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kinde_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kinde Australia Pty Ltd
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-07 00:00:00.000000000 Z
11
+ date: 2023-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus
@@ -100,7 +100,6 @@ extensions: []
100
100
  extra_rdoc_files: []
101
101
  files:
102
102
  - Gemfile
103
- - Gemfile.lock
104
103
  - LICENSE
105
104
  - README.md
106
105
  - Rakefile
data/Gemfile.lock DELETED
@@ -1,119 +0,0 @@
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