Module: Keycloak::API::ClientRoleResources
- Extended by:
- ActiveSupport::Concern
- Includes:
- Concerns::APIUtil
- Included in:
- Client
- Defined in:
- lib/keycloak/api/client_role_resources.rb
Instance Method Summary collapse
-
#add_client_role_mapping(user_id, id_of_client, role_mappings) ⇒ Object
Only role id and role name are required in role_mappings.
- #create_client_role(id, role_rep) ⇒ Object
-
#find_client_role_by_name(id, name) ⇒ Keycloak::Model::RoleRepresentation
Role representation.
-
#find_client_roles(id) ⇒ Array<Keycloak::Model::ClientRepresentation>
An array of client representations.
-
#find_client_roles_for_user(user_id, id_of_client) ⇒ Array<Keycloak::Model::RoleRepresentation>
Role representations.
- #remove_client_role_mapping(user_id, id_of_client, role_mappings) ⇒ Object
Methods included from Concerns::APIUtil
#admin_realm_url, #delete, #get, #post, #put, #realm_url
Instance Method Details
#add_client_role_mapping(user_id, id_of_client, role_mappings) ⇒ Object
Only role id and role name are required in role_mappings
44 45 46 47 |
# File 'lib/keycloak/api/client_role_resources.rb', line 44 def add_client_role_mapping(user_id, id_of_client, role_mappings) url = admin_realm_url + "/users/#{user_id}/role-mappings/clients/#{id_of_client}" post(url, role_mappings.to_json, headers: {content_type: :json}) end |
#create_client_role(id, role_rep) ⇒ Object
9 10 11 12 |
# File 'lib/keycloak/api/client_role_resources.rb', line 9 def create_client_role(id, role_rep) url = admin_realm_url + "/clients/#{id}/roles" post(url, role_rep.to_json, headers: {content_type: :json}) end |
#find_client_role_by_name(id, name) ⇒ Keycloak::Model::RoleRepresentation
Returns role representation.
24 25 26 27 28 29 |
# File 'lib/keycloak/api/client_role_resources.rb', line 24 def find_client_role_by_name(id, name) url = admin_realm_url + "/clients/#{id}/roles/#{name}" Model::RoleRepresentation.new JSON.parse(get(url)) rescue RestClient::NotFound nil end |
#find_client_roles(id) ⇒ Array<Keycloak::Model::ClientRepresentation>
Returns an array of client representations.
16 17 18 19 |
# File 'lib/keycloak/api/client_role_resources.rb', line 16 def find_client_roles(id) url = admin_realm_url + "/clients/#{id}/roles" JSON.parse(get(url)).map { |role| Model::RoleRepresentation.new role } end |
#find_client_roles_for_user(user_id, id_of_client) ⇒ Array<Keycloak::Model::RoleRepresentation>
Returns role representations.
34 35 36 37 |
# File 'lib/keycloak/api/client_role_resources.rb', line 34 def find_client_roles_for_user(user_id, id_of_client) url = admin_realm_url + "/users/#{user_id}/role-mappings/clients/#{id_of_client}" JSON.parse(get(url)).map { |role| Model::RoleRepresentation.new role } end |
#remove_client_role_mapping(user_id, id_of_client, role_mappings) ⇒ Object
49 50 51 52 |
# File 'lib/keycloak/api/client_role_resources.rb', line 49 def remove_client_role_mapping(user_id, id_of_client, role_mappings) url = admin_realm_url + "/users/#{user_id}/role-mappings/clients/#{id_of_client}" delete(url, payload: role_mappings.to_json, headers: {content_type: :json}) end |