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 +4 -4
- data/lib/keycloak/access_token.rb +6 -2
- data/lib/keycloak/realm.rb +6 -2
- 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: ea96c6ce0461b03f3044cef0525da847469201b4
|
4
|
+
data.tar.gz: 6eb43a59c72b12bf0e54aa87b35475a2101203f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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(
|
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
|
data/lib/keycloak/realm.rb
CHANGED
@@ -36,10 +36,14 @@ module Keycloak
|
|
36
36
|
realm
|
37
37
|
end
|
38
38
|
|
39
|
-
|
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
|
-
|
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
|
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.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-
|
11
|
+
date: 2019-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|