keycloak-ruby-client 0.0.9 → 0.0.10

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: 91adde1a917a9abc16e320afab4bceb64ffcc177
4
- data.tar.gz: 349fe8ced7814acfd3f9b09a77aa4d0b4cff0afd
3
+ metadata.gz: a8d34f9a8a043e0dab94b853945713d98b5e84e1
4
+ data.tar.gz: b2db73176d2c8db05167a90efc59a9d78aff2d4d
5
5
  SHA512:
6
- metadata.gz: 4f2f96727de3173f496d9919cd85e5acec9d5ec6fe85dcfe28c164e296befa01fa9a4ea054c682d5f37b5e7ac163bddec2aebcfb973308a895e26d1fcdda0db7
7
- data.tar.gz: 246966257694d98680ee4cb821dbc190c6f55833fe980901eb5467552744cd209e5a1198c935d064d233e5c402cbbcb2cbfc4bc62d4146182afb02bfce7b27dd
6
+ metadata.gz: 546abf23314d14cb70e6e07c0ab8ec98843e3da35f691fbc936e2b0090ca1c4b06b1ec8bf97f1eab958991400b6b1eeee601896f812f1c00c804ccb39e9b7402
7
+ data.tar.gz: 54c2a8ffe5eb1cec83378cd36f3cdf4c0fd9bda51ce6c22f417f897df32684d2bab9e67855fc46295d0d35d8ef0994346aae107ccb4540f68a6f3b831da590c3
@@ -42,4 +42,6 @@ Gem::Specification.new do |spec|
42
42
 
43
43
  spec.add_development_dependency "bundler", "~> 2.0"
44
44
  spec.add_development_dependency "rake", "~> 10.0"
45
+ spec.add_development_dependency "rspec"
46
+ spec.add_development_dependency "faker"
45
47
  end
@@ -0,0 +1,34 @@
1
+ module Keycloak
2
+ module API
3
+ module RealmResources
4
+ extend ActiveSupport::Concern
5
+ include Concerns::APIUtil
6
+
7
+ # @param realm_rep [Keycloak::Model::RealmRepresentation] realm representation
8
+ def create_realm(realm_rep)
9
+ post("#{@auth_server_url}/admin/realms/", realm_rep.to_json, headers: {content_type: :json})
10
+ end
11
+
12
+ # @param realm [String] realm name
13
+ def delete_realm(realm)
14
+ url = "#{@auth_server_url}/admin/realms/#{realm}"
15
+ delete(url)
16
+ end
17
+
18
+ # @param realm [String] realm name
19
+ # @param realm_rep [Keycloak::Model::RealmRepresentation] realm representation
20
+ def update_realm(realm, realm_rep)
21
+ url = "#{@auth_server_url}/admin/realms/#{realm}"
22
+ put(url, realm_rep.to_json, headers: {content_type: :json})
23
+ end
24
+
25
+ # @param realm [String] realm name
26
+ # @return [Keycloak::Model::RealmRepresentation] realm representation
27
+ def find_realm(realm)
28
+ url = "#{@auth_server_url}/admin/realms/#{realm}"
29
+ Keycloak::Model::RealmRepresentation.new JSON.parse(get(url))
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -29,6 +29,11 @@ module Keycloak
29
29
  Model::UserRepresentation.new JSON.parse(get("#{user_resources_url}/#{id}"))
30
30
  end
31
31
 
32
+ # @param id [String] user id
33
+ def update_user(id, user_rep)
34
+ put("#{user_resources_url}/#{id}", user_rep.to_json, headers: {content_type: :json})
35
+ end
36
+
32
37
  # see https://www.keycloak.org/docs-api/6.0/rest-api/index.html#_users_resource for params details
33
38
  #
34
39
  # @return [Keycloak::Utils::RepresentationIterator] iterator of users
data/lib/keycloak/api.rb CHANGED
@@ -3,3 +3,4 @@ require 'keycloak/api/role_resources'
3
3
  require 'keycloak/api/user_resources'
4
4
  require 'keycloak/api/client_resources'
5
5
  require 'keycloak/api/client_role_resources'
6
+ require 'keycloak/api/realm_resources'
@@ -1,3 +1,5 @@
1
+ require 'rest_client'
2
+
1
3
  module Keycloak
2
4
  class Client
3
5
  include API::UserResources
@@ -5,6 +7,7 @@ module Keycloak
5
7
  include API::ProtectionResources
6
8
  include API::ClientResources
7
9
  include API::ClientRoleResources
10
+ include API::RealmResources
8
11
 
9
12
  attr_reader :auth_server_url, :realm
10
13
 
@@ -108,7 +111,17 @@ module Keycloak
108
111
  headers: {
109
112
  authorization: "Bearer #{@access_token}",
110
113
  accept: "application/json"
111
- }.merge(headers))
114
+ }.merge(headers)
115
+ )
116
+ end
117
+
118
+ def put(url, payload, headers: {}, try_refresh_token: true)
119
+ try_refresh_token! if try_refresh_token
120
+
121
+ RestClient.put(url, payload, {
122
+ authorization: "Bearer #{@access_token}",
123
+ accept: "application/json"
124
+ }.merge(headers))
112
125
  end
113
126
  end
114
127
  end
@@ -22,6 +22,10 @@ module Keycloak
22
22
  def delete(url, headers: {}, payload: nil, try_refresh_token: true)
23
23
  raise NotImplementedError
24
24
  end
25
+
26
+ def put(url, payload, headers: {}, try_refresh_token: true)
27
+ raise NotImplementedError
28
+ end
25
29
  end
26
30
  end
27
31
  end
@@ -0,0 +1,30 @@
1
+ module Keycloak
2
+ module Model
3
+ class RealmRepresentation < BaseRepresentation
4
+ fields :accessCodeLifespan, :accessCodeLifespanLogin, :accessCodeLifespanUserAction,
5
+ :accessTokenLifespan, :accessTokenLifespanForImplicitFlow, :accountTheme,
6
+ :actionTokenGeneratedByAdminLifespan, :actionTokenGeneratedByUserLifespan,
7
+ :adminEventsDetailsEnabled, :adminEventsEnabled, :adminTheme, :attributes,
8
+ :authenticationFlows, :authenticatorConfig, :browserFlow, :browserSecurityHeaders,
9
+ :bruteForceProtected, :clientAuthenticationFlow, :clientScopeMappings, :clientScopes,
10
+ :clients, :components, :defaultDefaultClientScopes, :defaultGroups, :defaultLocale,
11
+ :defaultOptionalClientScopes, :defaultRoles, :defaultSignatureAlgorithm, :directGrantFlow,
12
+ :displayName, :displayNameHtml, :dockerAuthenticationFlow, :duplicateEmailsAllowed,
13
+ :editUsernameAllowed, :emailTheme, :enabled, :enabledEventTypes, :eventsEnabled,
14
+ :eventsExpiration, :eventsListeners, :failureFactor, :federatedUsers, :groups, :id,
15
+ :identityProviderMappers, :identityProviders, :internationalizationEnabled,
16
+ :keycloakVersion, :loginTheme, :loginWithEmailAllowed, :maxDeltaTimeSeconds,
17
+ :maxFailureWaitSeconds, :minimumQuickLoginWaitSeconds, :notBefore, :offlineSessionIdleTimeout,
18
+ :offlineSessionMaxLifespan, :offlineSessionMaxLifespanEnabled, :otpPolicyAlgorithm,
19
+ :otpPolicyDigits, :otpPolicyInitialCounter, :otpPolicyLookAheadWindow, :otpPolicyPeriod,
20
+ :otpPolicyType, :otpSupportedApplications, :passwordPolicy, :permanentLockout,
21
+ :protocolMappers, :quickLoginCheckMilliSeconds, :realm, :refreshTokenMaxReuse,
22
+ :registrationAllowed, :registrationEmailAsUsername, :registrationFlow, :rememberMe,
23
+ :requiredActions, :resetCredentialsFlow, :resetPasswordAllowed, :revokeRefreshToken,
24
+ :roles, :scopeMappings, :smtpServer, :sslRequired, :ssoSessionIdleTimeout,
25
+ :ssoSessionIdleTimeoutRememberMe, :ssoSessionMaxLifespan, :ssoSessionMaxLifespanRememberMe,
26
+ :supportedLocales, :userFederationMappers, :userFederationProviders, :userManagedAccessAllowed,
27
+ :users, :verifyEmail, :waitIncrementSeconds
28
+ end
29
+ end
30
+ end
@@ -2,4 +2,5 @@ require 'keycloak/model/base_representation'
2
2
  require 'keycloak/model/credential_representation'
3
3
  require 'keycloak/model/role_representation'
4
4
  require 'keycloak/model/user_representation'
5
- require 'keycloak/model/client_representation'
5
+ require 'keycloak/model/client_representation'
6
+ require 'keycloak/model/realm_representation'
@@ -1,3 +1,3 @@
1
1
  module Keycloak
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
data/lib/keycloak.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'rails'
2
+
1
3
  require_relative 'keycloak/version'
2
4
  require_relative 'keycloak/concerns'
3
5
  require_relative 'keycloak/access_token'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keycloak-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fuxin Hao
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-28 00:00:00.000000000 Z
11
+ date: 2019-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -80,6 +80,34 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: faker
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
83
111
  description: Keycloak ruby client
84
112
  email:
85
113
  - haofxpro@gmail.com
@@ -102,6 +130,7 @@ files:
102
130
  - lib/keycloak/api/client_resources.rb
103
131
  - lib/keycloak/api/client_role_resources.rb
104
132
  - lib/keycloak/api/protection_resources.rb
133
+ - lib/keycloak/api/realm_resources.rb
105
134
  - lib/keycloak/api/role_resources.rb
106
135
  - lib/keycloak/api/user_resources.rb
107
136
  - lib/keycloak/client.rb
@@ -111,6 +140,7 @@ files:
111
140
  - lib/keycloak/model/base_representation.rb
112
141
  - lib/keycloak/model/client_representation.rb
113
142
  - lib/keycloak/model/credential_representation.rb
143
+ - lib/keycloak/model/realm_representation.rb
114
144
  - lib/keycloak/model/role_representation.rb
115
145
  - lib/keycloak/model/user_representation.rb
116
146
  - lib/keycloak/realm.rb