Module: Keycloak::API::UserResources
- Extended by:
- ActiveSupport::Concern
- Includes:
- Concerns::APIUtil
- Included in:
- Client
- Defined in:
- lib/keycloak/api/user_resources.rb
Instance Method Summary collapse
-
#create_user(user_rep, roles = []) ⇒ String
Keycloak server doesn’t support assign roles at creating user, so we actually implement this in 2 steps.
- #delete_user(id) ⇒ Object
-
#find_user(id) ⇒ Keycloak::Model::UserRepresentation
User representation.
-
#find_user_by_client_role(id_of_client, role, params = {}) ⇒ Keycloak::Model::UserRepresentation
User representation.
-
#find_user_by_role(role, params = {}) ⇒ Keycloak::Model::UserRepresentation
User representation.
-
#find_user_by_username(username) ⇒ Keycloak::Model::UserRepresentation
User representation.
-
#find_users(params = {}) ⇒ Keycloak::Utils::RepresentationIterator
see www.keycloak.org/docs-api/6.0/rest-api/index.html#_users_resource for params details.
- #update_user(id, user_rep) ⇒ Object
- #user_resources_url ⇒ Object
Methods included from Concerns::APIUtil
#admin_realm_url, #delete, #get, #post, #put, #realm_url
Instance Method Details
#create_user(user_rep, roles = []) ⇒ String
Keycloak server doesn’t support assign roles at creating user, so we actually implement this in 2 steps.
17 18 19 20 21 22 23 |
# File 'lib/keycloak/api/user_resources.rb', line 17 def create_user(user_rep, roles = []) res = post(user_resources_url, user_rep.to_json, headers: {content_type: :json}) id = res.headers[:location].split("/")[-1] return id if roles.empty? add_role_mapping(id, roles) id end |
#delete_user(id) ⇒ Object
74 75 76 |
# File 'lib/keycloak/api/user_resources.rb', line 74 def delete_user(id) delete("#{user_resources_url}/#{id}", headers: {content_type: :json}) end |
#find_user(id) ⇒ Keycloak::Model::UserRepresentation
Returns user representation.
27 28 29 |
# File 'lib/keycloak/api/user_resources.rb', line 27 def find_user(id) Model::UserRepresentation.new JSON.parse(get("#{user_resources_url}/#{id}")) end |
#find_user_by_client_role(id_of_client, role, params = {}) ⇒ Keycloak::Model::UserRepresentation
Returns user representation.
66 67 68 69 70 71 |
# File 'lib/keycloak/api/user_resources.rb', line 66 def find_user_by_client_role(id_of_client, role, params = {}) url = "#{admin_realm_url}/clients/#{id_of_client}/roles/#{role}/users" Utils::RepresentationIterator.new(self, params) do JSON.parse(get(url, params: params)).map { |user| Model::UserRepresentation.new(user) } end end |
#find_user_by_role(role, params = {}) ⇒ Keycloak::Model::UserRepresentation
Returns user representation.
55 56 57 58 59 60 |
# File 'lib/keycloak/api/user_resources.rb', line 55 def find_user_by_role(role, params = {}) url = "#{admin_realm_url}/roles/#{role}/users" Utils::RepresentationIterator.new(self, params) do JSON.parse(get(url, params: params)).map { |user| Model::UserRepresentation.new(user) } end end |
#find_user_by_username(username) ⇒ Keycloak::Model::UserRepresentation
Returns user representation.
48 49 50 |
# File 'lib/keycloak/api/user_resources.rb', line 48 def find_user_by_username(username) find_users({username: username}).to_a[0] end |
#find_users(params = {}) ⇒ Keycloak::Utils::RepresentationIterator
see www.keycloak.org/docs-api/6.0/rest-api/index.html#_users_resource for params details
39 40 41 42 43 44 |
# File 'lib/keycloak/api/user_resources.rb', line 39 def find_users(params = {}) Utils::RepresentationIterator.new(self, params) do res = JSON.parse(get(user_resources_url, params: params)) res.map { |user| Model::UserRepresentation.new user } end end |
#update_user(id, user_rep) ⇒ Object
32 33 34 |
# File 'lib/keycloak/api/user_resources.rb', line 32 def update_user(id, user_rep) put("#{user_resources_url}/#{id}", user_rep.to_json, headers: {content_type: :json}) end |
#user_resources_url ⇒ Object
7 8 9 |
# File 'lib/keycloak/api/user_resources.rb', line 7 def user_resources_url admin_realm_url + "/users" end |