keycloak-ruby-client 0.0.14 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +8 -1
- data/lib/keycloak/api/protection_resources.rb +13 -8
- data/lib/keycloak/client.rb +6 -6
- data/lib/keycloak/model/base_representation.rb +3 -3
- data/lib/keycloak/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5fb941053a36de82d660a51be6d041b432c9342
|
4
|
+
data.tar.gz: 5c9ffc4b484fed6cdbff04f937b0a96f603e457e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb526460464780a4be8667ce19e576d3ff790b169d22edf0502f20d9684bab8ca22a65c71c9aeecd7a9e6534729739420d40917208a93c4f791062062adbaf5f
|
7
|
+
data.tar.gz: 50e74f7a50372209f4b011076ecb9ceeda1b4898ed718b6e4fdf01b4a54ab8ca5415ae28cc4b92d73f16a1880bdabc85343de35bf7dbac05e1a784b9337c3acc
|
data/Rakefile
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
2
3
|
task :default => :spec
|
3
4
|
|
4
5
|
gem 'rails'
|
5
|
-
gem 'rest-client'
|
6
|
+
gem 'rest-client'
|
7
|
+
|
8
|
+
desc "Run the specs."
|
9
|
+
RSpec::Core::RakeTask.new do |task|
|
10
|
+
task.pattern = "spec/**/*_spec.rb"
|
11
|
+
task.verbose = false
|
12
|
+
end
|
@@ -17,18 +17,23 @@ module Keycloak
|
|
17
17
|
# for more details.
|
18
18
|
# @param access_token [Keycloak::AccessToken] access token
|
19
19
|
# @return [Boolean] true if the permissions granted or false when forbidden
|
20
|
-
def granted_by_server(permissions, access_token)
|
20
|
+
def granted_by_server(permissions, access_token, extra_claims: {})
|
21
21
|
url = admin_realm_url + "/protocol/openid-connect/token"
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
params = {
|
23
|
+
grant_type: "urn:ietf:params:oauth:grant-type:uma-ticket",
|
24
|
+
audience: @realm,
|
25
|
+
permission: permissions,
|
26
|
+
response_mode: "decision"
|
27
|
+
}
|
28
|
+
if !extra_claims.empty?
|
29
|
+
params[:claim_token] = Base64.strict_decode64(extra_claims.to_json)
|
30
|
+
params[:claim_token_format] = "urn:ietf:params:oauth:token-type:jwt"
|
31
|
+
end
|
32
|
+
res = JSON.parse post(url, params,
|
28
33
|
headers: {content_type: :json, authorization: access_token.authorization},
|
29
34
|
try_refresh_token: false
|
30
35
|
)
|
31
|
-
res[
|
36
|
+
res["result"]
|
32
37
|
rescue RestClient::Forbidden, RestClient::Unauthorized
|
33
38
|
false
|
34
39
|
end
|
data/lib/keycloak/client.rb
CHANGED
@@ -64,18 +64,18 @@ module Keycloak
|
|
64
64
|
@expires_in = now + res["expires_in"].seconds
|
65
65
|
end
|
66
66
|
|
67
|
-
def
|
68
|
-
@expires_in && @expires_in
|
67
|
+
def access_token_valid?
|
68
|
+
@expires_in && @expires_in > DateTime.now
|
69
69
|
end
|
70
70
|
|
71
|
-
def
|
72
|
-
@refresh_expires_in && @refresh_expires_in
|
71
|
+
def refresh_token_valid?
|
72
|
+
@refresh_expires_in && @refresh_expires_in > DateTime.now
|
73
73
|
end
|
74
74
|
|
75
75
|
def try_refresh_token!
|
76
|
-
return
|
76
|
+
return if access_token_valid?
|
77
77
|
|
78
|
-
if
|
78
|
+
if refresh_token_valid?
|
79
79
|
refresh_token!
|
80
80
|
elsif @authenticate_username && @authenticate_password
|
81
81
|
authenticate(@authenticate_username, @authenticate_password, @authenticate_grant_type, @authenticate_client_id, @authenticate_realm, auto: false)
|
data/lib/keycloak/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: keycloak-ruby-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fuxin Hao
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|