kinde_sdk 1.1.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: ff03b45588d7636dddb42047a5376ca7e987b0af67a34d9875aa4d2f21174082
4
- data.tar.gz: 4e94bf93e1ff2cf76ff5ec561e7258a49f2bdcd6761c854ace4c8a2e7dc58121
3
+ metadata.gz: 3166fc3f21315cb21235d7c303440266daef8b2d4b37d983e2bc06bb28fd5acd
4
+ data.tar.gz: 7421f7964d90a458b47724a4073711480a6caeac1cc6fe3e68989dfbe2045821
5
5
  SHA512:
6
- metadata.gz: f2f46b4988a9206f9ec6814e0fb16b393048097f39dd063901924bdbbceed1881f7f3a8776aa62cd31cdee13922ca437c8c63161119e1e3c07a7328b65f62413
7
- data.tar.gz: f54cfbb9548d5d4a73d93126e970194e4c7fbc1cc25ddb5041cb1c4967a101a361a190217840b830bc1fe22eeffa07dbcaf60be871a486295c1ceddc4f9eafeb
6
+ metadata.gz: 380bac0d796adc5daf5b55faea19d130e32fc248b2e2fb5f91e0e74bb267b4ac617fb1f51163ce2871a0c78ed2447161a8be316f972a20d694dfd9a665b9fb2c
7
+ data.tar.gz: d667129a0d21dca7dd07baecedc96e78470eb0952744c7921e2bdb96445524bb378eef2625c99c87b6357ff1183b44e32e1df93fea1f05bf518bb926f53a51d8
data/README.md CHANGED
@@ -239,15 +239,23 @@ instance_client.create_user(args)
239
239
  ```
240
240
 
241
241
  #### Logout
242
- For logout you need to call:
242
+ For logout you need to call (in case of rails app) in your controller:
243
243
  ```ruby
244
- instance_client.logout
245
- # or
246
- 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
+ # ......
247
256
  ```
248
- then clear your session or storage (delete your token) and redirect wherever you want to.
249
257
  If you configured logout redirect url correct (e.g. added in the admin panel allowed logout redirect), you can receive
250
- 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.
251
259
 
252
260
  ### Organizations
253
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.1.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(
@@ -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://example.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.1.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-28 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