keycloak 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 664d5f8c6abad5cc3a139175fe7125f9ca41342a
4
- data.tar.gz: 4e3c751dd137ba1081acf6a4e1c968c762459210
3
+ metadata.gz: 150ce5ce029c263fab2a539579f45d6259b94ad6
4
+ data.tar.gz: 12040f7b119b72eafdce1e33d8850b10ee37beb6
5
5
  SHA512:
6
- metadata.gz: 947e8843b23edd19b26120fb7f2b505e75e316600eaa4855dbf0c39047e0813c8272e386d2180b9b794d6d95550f2e41b72f18213e18f0141d05ed455c571c16
7
- data.tar.gz: 174f31ed0058103d9e83f859fb821fa47bf0e21846ac88de822987d8ce582df71d93b302539c3305d3c17047dab441265f33d697c646fa1e8eaac9c2080b8933
6
+ metadata.gz: b1eda036c71582bfe38585a7c1370fc7b5a56346baa45793ef75181deb8b3feebd6add71d15d9a74398834d8aca3ac8d7caf13c0af31e06001c0d127b37fb161
7
+ data.tar.gz: 7c6db8a0d53a3759f771ac18d7a4d775f3730990bd0896b6fee3d8812af8340ce100e80cc406818eb90c8c8abe647fb70a530c72987395593810b80ab8bf7fa0
data/lib/keycloak.rb CHANGED
@@ -1,4 +1,4 @@
1
- require "keycloak/version"
1
+ require 'keycloak/version'
2
2
  require 'rest-client'
3
3
  require 'json'
4
4
  require 'jwt'
@@ -441,7 +441,7 @@ module Keycloak
441
441
  attr_accessor :admin_user, :admin_password
442
442
  end
443
443
 
444
- def self.forgot_password(userID, redirectURI)
444
+ def self.change_password(userID, redirectURI = '')
445
445
  proc = lambda {|token|
446
446
  Keycloak.generic_request(token["access_token"],
447
447
  Keycloak::Client.auth_server_url + "/admin/realms/#{Keycloak::Client.realm}/users/#{userID}/execute-actions-email",
@@ -451,7 +451,11 @@ module Keycloak
451
451
  }
452
452
 
453
453
  default_call(proc)
454
+ end
454
455
 
456
+ def self.forgot_password(userLogin, redirectURI = '')
457
+ user = get_user_info(userLogin, true)
458
+ change_password(user['id'], redirectURI)
455
459
  end
456
460
 
457
461
  def self.get_logged_user_info
@@ -465,6 +469,45 @@ module Keycloak
465
469
  default_call(proc)
466
470
  end
467
471
 
472
+ def self.get_user_info(userLogin, wholeWord = false)
473
+ proc = lambda {|token|
474
+ if userLogin.index('@').nil?
475
+ search = {:username => userLogin}
476
+ else
477
+ search = {:email => userLogin}
478
+ end
479
+ users = JSON Keycloak.generic_request(token["access_token"],
480
+ Keycloak::Client.auth_server_url + "/admin/realms/#{Keycloak::Client.realm}/users/",
481
+ search, nil, 'GET')
482
+ users[0]
483
+ if users.count == 0
484
+ raise Keycloak::UserLoginNotFound
485
+ else
486
+ efectiveIndex = -1
487
+ users.each_with_index do |user, i|
488
+ if wholeWord
489
+ efectiveIndex = i if userLogin == user['username'] || userLogin == user['email']
490
+ else
491
+ efectiveIndex = 0
492
+ end
493
+ break if efectiveIndex >= 0
494
+ end
495
+
496
+ if efectiveIndex >= 0
497
+ if wholeWord
498
+ users[efectiveIndex]
499
+ else
500
+ users
501
+ end
502
+ else
503
+ raise Keycloak::UserLoginNotFound
504
+ end
505
+ end
506
+ }
507
+
508
+ default_call(proc)
509
+ end
510
+
468
511
  def self.is_logged_federation_user?
469
512
  info = get_logged_user_info
470
513
  info['federationLink'] != nil
@@ -609,3 +652,5 @@ module Keycloak
609
652
  end
610
653
 
611
654
  end
655
+
656
+ require 'keycloak/exceptions'
@@ -0,0 +1,3 @@
1
+ module Keycloak
2
+ class UserLoginNotFound < StandardError; end
3
+ end
@@ -1,3 +1,3 @@
1
1
  module Keycloak
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
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.1.0
4
+ version: 1.1.1
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-04 00:00:00.000000000 Z
11
+ date: 2017-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -114,6 +114,7 @@ files:
114
114
  - keycloak.gemspec
115
115
  - lib/generators/initializer_generator.rb
116
116
  - lib/keycloak.rb
117
+ - lib/keycloak/exceptions.rb
117
118
  - lib/keycloak/version.rb
118
119
  homepage: https://github.com/imagov/keycloak.git
119
120
  licenses: