keycloak 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/keycloak.gemspec +3 -3
- data/lib/keycloak.rb +62 -1
- data/lib/keycloak/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da54a19c777a0965809f08c8913b4bbce7c1abd3
|
4
|
+
data.tar.gz: eb76df093291e5f43789f02999ba1af0149d4421
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b438b078455362d62a4381fcc410a073c74f3aa67e45c35f4f8fe0ec2eec64540683e6ad0bf42c24005cb1755ca5b6c9f1820e91c96d327281f1d06d2a66582d
|
7
|
+
data.tar.gz: 1700bafbf32593ab794e481d48a192b6c726b60f9b3cb861493e9f69008edc5869d8883ff91edecd848c03d701589ca70d09ef9ad8d6337f361c3a60080f9011
|
data/keycloak.gemspec
CHANGED
@@ -33,7 +33,7 @@ Gem::Specification.new do |spec|
|
|
33
33
|
spec.add_development_dependency "bundler", "~> 1.15"
|
34
34
|
spec.add_development_dependency "rake", "~> 10.0"
|
35
35
|
spec.add_development_dependency "rspec", "~> 3.0"
|
36
|
-
spec.
|
37
|
-
spec.
|
38
|
-
spec.
|
36
|
+
spec.add_runtime_dependency "rest-client"
|
37
|
+
spec.add_runtime_dependency "jwt"
|
38
|
+
spec.add_runtime_dependency "json"
|
39
39
|
end
|
data/lib/keycloak.rb
CHANGED
@@ -166,7 +166,7 @@ module Keycloak
|
|
166
166
|
@secret = installation["credentials"]["secret"]
|
167
167
|
@public_key = installation["realm-public-key"]
|
168
168
|
@auth_server_url = installation["auth-server-url"]
|
169
|
-
reset_active
|
169
|
+
reset_active(false)
|
170
170
|
openid_configuration
|
171
171
|
else
|
172
172
|
raise "#{KEYCLOAK_JSON_FILE} not found."
|
@@ -513,6 +513,67 @@ module Keycloak
|
|
513
513
|
info['federationLink'] != nil
|
514
514
|
end
|
515
515
|
|
516
|
+
def self.create_starter_user(userName, password, email, clientRolesNames, proc = nil)
|
517
|
+
begin
|
518
|
+
user = get_user_info(userName, true)
|
519
|
+
newUser = false
|
520
|
+
rescue Keycloak::UserLoginNotFound
|
521
|
+
newUser = true
|
522
|
+
rescue
|
523
|
+
raise
|
524
|
+
end
|
525
|
+
|
526
|
+
procDefault = lambda {|token|
|
527
|
+
userRepresentation = {:username => userName,
|
528
|
+
:email => email,
|
529
|
+
:enabled => true}
|
530
|
+
|
531
|
+
if !newUser || Keycloak.generic_request(token["access_token"],
|
532
|
+
Keycloak::Client.auth_server_url + "/admin/realms/#{Keycloak::Client.realm}/users/",
|
533
|
+
nil, userRepresentation, 'POST')
|
534
|
+
|
535
|
+
user = get_user_info(userName, true) if newUser
|
536
|
+
|
537
|
+
credentialRepresentation = {:type => "password",
|
538
|
+
:temporary => false,
|
539
|
+
:value => password}
|
540
|
+
|
541
|
+
if Keycloak.generic_request(token["access_token"],
|
542
|
+
Keycloak::Client.auth_server_url + "/admin/realms/#{Keycloak::Client.realm}/users/#{user['id']}/reset-password",
|
543
|
+
nil, credentialRepresentation, 'PUT')
|
544
|
+
|
545
|
+
client = JSON Keycloak.generic_request(token["access_token"],
|
546
|
+
Keycloak::Client.auth_server_url + "/admin/realms/#{Keycloak::Client.realm}/clients/",
|
547
|
+
{:clientId => Keycloak::Client.client_id}, nil, 'GET')
|
548
|
+
|
549
|
+
roles = Array.new
|
550
|
+
clientRolesNames.each do |r|
|
551
|
+
if r && !r.empty?
|
552
|
+
role = JSON Keycloak.generic_request(token["access_token"],
|
553
|
+
Keycloak::Client.auth_server_url + "/admin/realms/#{Keycloak::Client.realm}/clients/#{client[0]['id']}/roles/#{r}",
|
554
|
+
nil, nil, 'GET')
|
555
|
+
roles.push(role)
|
556
|
+
end
|
557
|
+
end
|
558
|
+
|
559
|
+
if roles.count > 0
|
560
|
+
Keycloak.generic_request(token["access_token"],
|
561
|
+
Keycloak::Client.auth_server_url + "/admin/realms/#{Keycloak::Client.realm}/users/#{user['id']}/role-mappings/clients/#{client[0]['id']}",
|
562
|
+
nil, roles, 'POST')
|
563
|
+
end
|
564
|
+
end
|
565
|
+
|
566
|
+
end
|
567
|
+
}
|
568
|
+
|
569
|
+
if default_call(procDefault)
|
570
|
+
if !proc.nil?
|
571
|
+
proc.call user
|
572
|
+
end
|
573
|
+
end
|
574
|
+
|
575
|
+
end
|
576
|
+
|
516
577
|
protected
|
517
578
|
|
518
579
|
def self.default_call(proc)
|
data/lib/keycloak/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: keycloak
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guilherme Portugues
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -59,7 +59,7 @@ dependencies:
|
|
59
59
|
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
-
type: :
|
62
|
+
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
@@ -73,7 +73,7 @@ dependencies:
|
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
|
-
type: :
|
76
|
+
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
|
-
type: :
|
90
|
+
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|