keycloak-ruby-client 0.0.14 → 0.0.15

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ea96c6ce0461b03f3044cef0525da847469201b4
4
- data.tar.gz: 6eb43a59c72b12bf0e54aa87b35475a2101203f0
3
+ metadata.gz: a5fb941053a36de82d660a51be6d041b432c9342
4
+ data.tar.gz: 5c9ffc4b484fed6cdbff04f937b0a96f603e457e
5
5
  SHA512:
6
- metadata.gz: 1905046d47ebcd9572a4edfe05e7eb79b9aa12b197c1c41b97f7eea1341d600de99c5fa873ad6c04c834888fca95145d3d3c3e62bc9afc6cbad92497030bc221
7
- data.tar.gz: 88b9cd6fa32a4bf3d978ba8fddb880fa1f59d2c71eebdf24750ac6bea65bde323e2c703e4aaa101ef7df994744c8ff25f0e58ade079dce587759c978e3080735
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
- res = JSON.parse post(url, {
23
- grant_type: "urn:ietf:params:oauth:grant-type:uma-ticket",
24
- audience: @realm,
25
- permission: permissions,
26
- response_mode: "decision"
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['result']
36
+ res["result"]
32
37
  rescue RestClient::Forbidden, RestClient::Unauthorized
33
38
  false
34
39
  end
@@ -64,18 +64,18 @@ module Keycloak
64
64
  @expires_in = now + res["expires_in"].seconds
65
65
  end
66
66
 
67
- def access_token_expired?
68
- @expires_in && @expires_in < DateTime.now
67
+ def access_token_valid?
68
+ @expires_in && @expires_in > DateTime.now
69
69
  end
70
70
 
71
- def refresh_token_expired?
72
- @refresh_expires_in && @refresh_expires_in < DateTime.now
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 unless access_token_expired?
76
+ return if access_token_valid?
77
77
 
78
- if !refresh_token_expired?
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)
@@ -74,11 +74,11 @@ module Keycloak
74
74
  v = instance_variable_get("@#{attr}")
75
75
  h[attr] = v unless v.nil?
76
76
  end
77
- h
77
+ h.as_json(*options)
78
78
  end
79
79
 
80
- def to_json
81
- as_json.to_json
80
+ def to_json(*options)
81
+ as_json(*options).to_json
82
82
  end
83
83
  end
84
84
  end
@@ -1,3 +1,3 @@
1
1
  module Keycloak
2
- VERSION = "0.0.14"
2
+ VERSION = "0.0.15"
3
3
  end
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.14
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-09-27 00:00:00.000000000 Z
11
+ date: 2019-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails