keycloak-ruby-client 0.0.15 → 0.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/keycloak-ruby-client.gemspec +1 -0
- data/lib/keycloak/api/client_resources.rb +20 -3
- data/lib/keycloak/api/realm_resources.rb +3 -1
- data/lib/keycloak/api/user_resources.rb +21 -0
- data/lib/keycloak/client.rb +2 -1
- data/lib/keycloak/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64fd5654b140211d2d61816df33711498be7bdc4
|
4
|
+
data.tar.gz: d263f09209a4a4d27d282ed9c5fa673c9116a0ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87621811a0e707edfe779468442738f2044943666a7392e719a1c3511130423c52b91549c7a9c8130ae11fc5454037ad2dceb7faea2a3ab3f6f3076f2c5f3731
|
7
|
+
data.tar.gz: 062f6231ea0b325c6cac2d603446c93e0fc9e0a2c0176ce2933a208c82e5759a72875f74549e7db73b37fba8d1899d6411d166b7d79f0bbc0d1145bfa8a84ed2
|
data/README.md
CHANGED
@@ -109,6 +109,8 @@ client.find_users.each { |user| puts user.to_json } # no risk of out of memory
|
|
109
109
|
|
110
110
|
```
|
111
111
|
|
112
|
+
For more examples, please take a look at [spec/api/](./spec/api/)
|
113
|
+
|
112
114
|
### Connect your rails user model with keycloak user entity:
|
113
115
|
|
114
116
|
Firstly, we create a user model with `bundle exec rails g model user`
|
@@ -4,11 +4,14 @@ module Keycloak
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
include Concerns::APIUtil
|
6
6
|
|
7
|
+
def client_resources_url
|
8
|
+
"#{admin_realm_url}/clients"
|
9
|
+
end
|
10
|
+
|
7
11
|
# @param client_id [String] client-id (not id of client)
|
8
12
|
# @return [Keycloak::Model::ClientRepresentation] client representation
|
9
13
|
def find_client_by_client_id(client_id)
|
10
|
-
|
11
|
-
data = JSON.parse(get(url, params: { clientId: client_id }).body)
|
14
|
+
data = JSON.parse(get(client_resources_url, params: { clientId: client_id }).body)
|
12
15
|
data[0] && Model::ClientRepresentation.new(data[0])
|
13
16
|
rescue RestClient::NotFound
|
14
17
|
nil
|
@@ -17,11 +20,25 @@ module Keycloak
|
|
17
20
|
# @param id [String] id of client (not client-id)
|
18
21
|
# @return [Keycloak::Model::ClientRepresentation] client representation
|
19
22
|
def find_client_by_id(id)
|
20
|
-
url =
|
23
|
+
url = client_resources_url + "/#{id}"
|
21
24
|
Model::ClientRepresentation.new JSON.parse(get(url).body)
|
22
25
|
rescue RestClient::NotFound
|
23
26
|
nil
|
24
27
|
end
|
28
|
+
|
29
|
+
# @param client_rep [Keycloak::Model::UserRepresentation] client representation
|
30
|
+
# @return [String] id of client
|
31
|
+
def create_client(client_rep)
|
32
|
+
res = post(client_resources_url, client_rep.to_json, headers: {content_type: :json})
|
33
|
+
res.headers[:location].split("/")[-1]
|
34
|
+
end
|
35
|
+
|
36
|
+
# @param id [String] id of client (not client-id)
|
37
|
+
# @param client_rep [Keycloak::Model::UserRepresentation] client representation
|
38
|
+
def update_client(id, client_rep)
|
39
|
+
url = client_resources_url + "/#{id}"
|
40
|
+
put(url, client_rep.to_json, headers: {content_type: :json})
|
41
|
+
end
|
25
42
|
end
|
26
43
|
end
|
27
44
|
end
|
@@ -5,8 +5,10 @@ module Keycloak
|
|
5
5
|
include Concerns::APIUtil
|
6
6
|
|
7
7
|
# @param realm_rep [Keycloak::Model::RealmRepresentation] realm representation
|
8
|
+
# @return [String] realm id
|
8
9
|
def create_realm(realm_rep)
|
9
|
-
post("#{@auth_server_url}/admin/realms/", realm_rep.to_json, headers: {content_type: :json})
|
10
|
+
res = post("#{@auth_server_url}/admin/realms/", realm_rep.to_json, headers: {content_type: :json})
|
11
|
+
res.headers[:location].split("/")[-1]
|
10
12
|
end
|
11
13
|
|
12
14
|
# @param realm [String] realm name
|
@@ -43,11 +43,32 @@ module Keycloak
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
+
# @param username [String] username
|
46
47
|
# @return [Keycloak::Model::UserRepresentation] user representation
|
47
48
|
def find_user_by_username(username)
|
48
49
|
find_users({username: username}).to_a[0]
|
49
50
|
end
|
50
51
|
|
52
|
+
# @param role [String] role name
|
53
|
+
# @param params [Hash] extra params
|
54
|
+
# @return [Keycloak::Model::UserRepresentation] user representation
|
55
|
+
def find_user_by_role(role, params = {})
|
56
|
+
url = "#{admin_realm_url}/roles/#{role}/users"
|
57
|
+
Utils::RepresentationIterator.new(self, params) do
|
58
|
+
JSON.parse(get(url, params: params)).map { |user| Model::UserRepresentation.new(user) }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# @param id_of_client [String] id of client (not client-id)
|
63
|
+
# @param role [String] role name
|
64
|
+
# @param params [Hash] extra params
|
65
|
+
# @return [Keycloak::Model::UserRepresentation] user representation
|
66
|
+
def find_user_by_client_role(id_of_client, role, params = {})
|
67
|
+
url = "#{admin_realm_url}/clients/#{id_of_client}/roles/#{role}/users"
|
68
|
+
Utils::RepresentationIterator.new(self, params) do
|
69
|
+
JSON.parse(get(url, params: params)).map { |user| Model::UserRepresentation.new(user) }
|
70
|
+
end
|
71
|
+
end
|
51
72
|
end
|
52
73
|
end
|
53
74
|
end
|
data/lib/keycloak/client.rb
CHANGED
@@ -39,7 +39,8 @@ module Keycloak
|
|
39
39
|
username: username,
|
40
40
|
password: password,
|
41
41
|
grant_type: grant_type,
|
42
|
-
client_id: client_id
|
42
|
+
client_id: client_id,
|
43
|
+
scope: "offline_access"
|
43
44
|
}, try_refresh_token: false).body
|
44
45
|
@access_token = res["access_token"]
|
45
46
|
@refresh_token = res["refresh_token"]
|
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.16
|
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-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: factory_bot
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
111
125
|
description: Keycloak ruby client
|
112
126
|
email:
|
113
127
|
- haofxpro@gmail.com
|