lib/keycloak.rb in keycloak-2.2.6 vs lib/keycloak.rb in keycloak-2.2.7
- old
+ new
@@ -587,12 +587,13 @@
def self.logged_federation_user?
info = get_logged_user_info
info['federationLink'] != nil
end
- def self.create_starter_user(username, password, email, client_roles_names, proc = nil)
+ def self.create_simple_user(username, password, email, first_name, last_name, realm_roles_names, client_roles_names, proc = nil)
begin
+ username.downcase!
user = get_user_info(username, true)
newUser = false
rescue Keycloak::UserLoginNotFound
newUser = true
rescue
@@ -600,10 +601,12 @@
end
proc_default = lambda { |token|
user_representation = { username: username,
email: email,
+ firstName: first_name,
+ lastName: last_name,
enabled: true }
if !newUser || Keycloak.generic_request(token["access_token"],
Keycloak::Admin.full_url("users/"),
nil, user_representation, 'POST')
@@ -635,17 +638,37 @@
if roles.count > 0
Keycloak.generic_request(token["access_token"],
Keycloak::Admin.full_url("users/#{user['id']}/role-mappings/clients/#{client[0]['id']}"),
nil, roles, 'POST')
end
+
+ roles = []
+ realm_roles_names.each do |r|
+ if r.present?
+ role = JSON Keycloak.generic_request(token["access_token"],
+ Keycloak::Admin.full_url("roles/#{r}"),
+ nil, nil, 'GET')
+ roles.push(role)
+ end
+ end
+
+ if roles.count > 0
+ Keycloak.generic_request(token["access_token"],
+ Keycloak::Admin.full_url("users/#{user['id']}/role-mappings/realm"),
+ nil, roles, 'POST')
+ end
end
end
}
if default_call(proc_default)
proc.call user unless proc.nil?
end
+ end
+
+ def self.create_starter_user(username, password, email, client_roles_names, proc = nil)
+ Keycloak::Internal.create_simple_user(username, password, email, '', '', [], client_roles_names, proc)
end
def self.get_client_roles
proc = lambda {|token|
client = JSON Keycloak::Admin.get_clients({ clientId: Keycloak::Client.client_id }, token["access_token"])
\ No newline at end of file