keycloak-ruby-client 0.0.13 → 0.0.14

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
  SHA1:
3
- metadata.gz: cad9329591793b920ce448c860cd14d8f08dde82
4
- data.tar.gz: b0fab2a0faa37555449701e1917ff58e6e8b6c2a
3
+ metadata.gz: ea96c6ce0461b03f3044cef0525da847469201b4
4
+ data.tar.gz: 6eb43a59c72b12bf0e54aa87b35475a2101203f0
5
5
  SHA512:
6
- metadata.gz: 8222c591f83d24f86e3e72d9d65601909325d08df60977483fe619d97711f096d096bf296a8a0c4a10a4057f9c07a26a482d7a60ca59eee50c8f71c6b93638fe
7
- data.tar.gz: '07964b5edd92032897c98558093c923a864bf35f129755cc91868c1fb3a038e3a78f7aea524fa5767f8279aa4fdb59b35ff7665a5225ea805345fb9188cea7e6'
6
+ metadata.gz: 1905046d47ebcd9572a4edfe05e7eb79b9aa12b197c1c41b97f7eea1341d600de99c5fa873ad6c04c834888fca95145d3d3c3e62bc9afc6cbad92497030bc221
7
+ data.tar.gz: 88b9cd6fa32a4bf3d978ba8fddb880fa1f59d2c71eebdf24750ac6bea65bde323e2c703e4aaa101ef7df994744c8ff25f0e58ade079dce587759c978e3080735
@@ -3,7 +3,7 @@ module Keycloak
3
3
  attr_reader :metadata, :jti, :exp, :sub, :azp, :roles, :scope,
4
4
  :phone_number, :username, :access_token, :client_roles
5
5
 
6
- def initialize(realm, access_token, decoded_token)
6
+ def initialize(realm, access_token, decoded_token, client_id = nil)
7
7
  @realm = realm
8
8
  @access_token = access_token
9
9
  @metadata = decoded_token[0]
@@ -15,13 +15,17 @@ module Keycloak
15
15
  @roles = realm_access["roles"] || []
16
16
  end
17
17
  if resource_access = @metadata["resource_access"]
18
- @client_roles = resource_access.dig(realm.name, "roles") || []
18
+ @client_roles = (client_id && resource_access.dig(client_id, "roles")) || []
19
19
  end
20
20
  @scope = @metadata["scope"]
21
21
  @phone_number = @metadata["phone_number"]
22
22
  @username = @metadata["username"] || @metadata["preferred_username"]
23
23
  end
24
24
 
25
+ def client_id
26
+ @azp
27
+ end
28
+
25
29
  def authorization
26
30
  "Bearer #{@access_token}"
27
31
  end
@@ -36,10 +36,14 @@ module Keycloak
36
36
  realm
37
37
  end
38
38
 
39
- def parse_access_token(access_token)
39
+ ParseAccessTokenError = Class.new(StandardError)
40
+
41
+ def parse_access_token(access_token, client_id:)
40
42
  alg = JWT.decode(access_token, nil, false)[1]["alg"]
41
43
  decoded_token = JWT.decode access_token, public_keys[alg], true, algorithm: alg
42
- AccessToken.new self, access_token, decoded_token
44
+ azp = decoded_token[0]["azp"]
45
+ raise ParseAccessTokenError, "Unexpected client, expect #{client_id}, got #{azp}" if client_id && azp != client_id
46
+ AccessToken.new self, access_token, decoded_token, client_id
43
47
  end
44
48
 
45
49
  def client
@@ -1,3 +1,3 @@
1
1
  module Keycloak
2
- VERSION = "0.0.13"
2
+ VERSION = "0.0.14"
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.13
4
+ version: 0.0.14
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-17 00:00:00.000000000 Z
11
+ date: 2019-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails