ripple_keycloak 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/.rubocop.yml +29 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +21 -0
- data/README.md +44 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/ripple_keycloak.rb +22 -0
- data/lib/ripple_keycloak/base_model.rb +45 -0
- data/lib/ripple_keycloak/client.rb +166 -0
- data/lib/ripple_keycloak/configuration.rb +10 -0
- data/lib/ripple_keycloak/error_handler.rb +32 -0
- data/lib/ripple_keycloak/group.rb +42 -0
- data/lib/ripple_keycloak/role.rb +17 -0
- data/lib/ripple_keycloak/user.rb +46 -0
- data/lib/ripple_keycloak/version.rb +5 -0
- data/ripple_keycloak.gemspec +30 -0
- metadata +93 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0c695a14343b4ad57269888035cff4e7f1cf6c358a265cc21bc730b0a3356f86
|
4
|
+
data.tar.gz: 467cd8d7424584d050c1ff9cbc3a2156cf71556e5b8e454994d522375666f51d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1b3184c41d29d70f9b7b4ac59a2d45bdb949108ba74cc4169400dc80fe4821f1b2cbaab331584507cfac8cf7ecbd8aa3875768daf68e790894353baf1f1e2e74
|
7
|
+
data.tar.gz: e9a2534b9e40c6043679720b6f039a37994cb555252d74c86b5aa375269e7b6f13e4088459f095158d2a2b0e8df162c07dbf1dd7c9a83c8cf5c623ef51b48802
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
Layout/EmptyLinesAroundAttributeAccessor:
|
2
|
+
Enabled: true
|
3
|
+
Layout/SpaceAroundMethodCallOperator:
|
4
|
+
Enabled: true
|
5
|
+
Lint/DeprecatedOpenSSLConstant:
|
6
|
+
Enabled: true
|
7
|
+
Lint/MixedRegexpCaptureTypes:
|
8
|
+
Enabled: true
|
9
|
+
Lint/RaiseException:
|
10
|
+
Enabled: true
|
11
|
+
Lint/StructNewOverride:
|
12
|
+
Enabled: true
|
13
|
+
Style/ExponentialNotation:
|
14
|
+
Enabled: true
|
15
|
+
Style/HashEachMethods:
|
16
|
+
Enabled: true
|
17
|
+
Style/HashTransformKeys:
|
18
|
+
Enabled: true
|
19
|
+
Style/HashTransformValues:
|
20
|
+
Enabled: true
|
21
|
+
Style/RedundantRegexpCharacterClass:
|
22
|
+
Enabled: true
|
23
|
+
Style/RedundantRegexpEscape:
|
24
|
+
Enabled: true
|
25
|
+
Style/SlicingWithRange:
|
26
|
+
Enabled: true
|
27
|
+
|
28
|
+
Style/Documentation:
|
29
|
+
Enabled: false
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at ollie@nyemail.co.uk. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Ollie Nye
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# RippleKeycloak
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ripple_keycloak`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'ripple_keycloak'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install ripple_keycloak
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ripple_keycloak. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/ripple_keycloak/blob/master/CODE_OF_CONDUCT.md).
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
41
|
+
|
42
|
+
## Code of Conduct
|
43
|
+
|
44
|
+
Everyone interacting in the RippleKeycloak project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/ripple_keycloak/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'ripple_keycloak'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ripple_keycloak/version'
|
4
|
+
require 'ripple_keycloak/client'
|
5
|
+
require 'ripple_keycloak/base_model'
|
6
|
+
require 'ripple_keycloak/group'
|
7
|
+
require 'ripple_keycloak/role'
|
8
|
+
require 'ripple_keycloak/user'
|
9
|
+
|
10
|
+
module RippleKeycloak
|
11
|
+
class Error < StandardError; end
|
12
|
+
class UnauthorizedClientError < Error; end
|
13
|
+
class UnauthorizedError < Error; end
|
14
|
+
class RealmDoesNotExistError < Error; end
|
15
|
+
class GroupNotFoundError < Error; end
|
16
|
+
class RoleNotFoundError < Error; end
|
17
|
+
class UserNotFoundError < Error; end
|
18
|
+
class MissingPropertyError < Error; end
|
19
|
+
class NotFoundError < Error; end
|
20
|
+
|
21
|
+
class ConflictError < Error; end
|
22
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RippleKeycloak
|
4
|
+
class BaseModel
|
5
|
+
class << self
|
6
|
+
delegate :get, :post, to: :client
|
7
|
+
|
8
|
+
def object_type(object_type)
|
9
|
+
@object_type = object_type
|
10
|
+
end
|
11
|
+
|
12
|
+
def search(value)
|
13
|
+
client.search(@object_type, value)
|
14
|
+
end
|
15
|
+
|
16
|
+
def all(first: nil, max: nil)
|
17
|
+
url = "#{@object_type}?"
|
18
|
+
url += "first=#{first}" if first
|
19
|
+
url += "max=#{max}" if max
|
20
|
+
|
21
|
+
client.get(url)
|
22
|
+
end
|
23
|
+
|
24
|
+
def find(id)
|
25
|
+
client.get("#{@object_type}/#{id}")
|
26
|
+
end
|
27
|
+
|
28
|
+
def find_by(field:, value:)
|
29
|
+
client.find_by(@object_type, field, value)
|
30
|
+
end
|
31
|
+
|
32
|
+
def delete(id)
|
33
|
+
client.delete("#{@object_type}/#{id}")
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def client
|
39
|
+
RippleKeycloak::Client.new
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
delegate :base_model, to: :class
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,166 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'httparty'
|
4
|
+
require 'active_support/core_ext/module/delegation'
|
5
|
+
|
6
|
+
require 'ripple_keycloak/error_handler'
|
7
|
+
require 'ripple_keycloak/configuration'
|
8
|
+
|
9
|
+
module RippleKeycloak
|
10
|
+
class Client
|
11
|
+
include HTTParty
|
12
|
+
# debug_output $stdout
|
13
|
+
|
14
|
+
class << self
|
15
|
+
def configure
|
16
|
+
@configuration = Configuration.new
|
17
|
+
yield(configuration)
|
18
|
+
auth
|
19
|
+
'Authenticated successfully'
|
20
|
+
end
|
21
|
+
|
22
|
+
def post_formatted(resource, json: true, authed: true, **options)
|
23
|
+
if authed
|
24
|
+
options = add_auth_header(options)
|
25
|
+
resource = "admin/realms/#{realm}/" + resource
|
26
|
+
end
|
27
|
+
if json
|
28
|
+
options = add_header(options, 'Content-Type', 'application/json')
|
29
|
+
options[:body] = options[:body].to_json
|
30
|
+
end
|
31
|
+
|
32
|
+
return_or_raise post("#{base_uri}/#{resource}", options)
|
33
|
+
end
|
34
|
+
|
35
|
+
def put_formatted(resource, json: true, authed: true, **options)
|
36
|
+
if authed
|
37
|
+
options = add_auth_header(options)
|
38
|
+
resource = "admin/realms/#{realm}/" + resource
|
39
|
+
end
|
40
|
+
if json
|
41
|
+
options = add_header(options, 'Content-Type', 'application/json')
|
42
|
+
options[:body] = options[:body].to_json
|
43
|
+
end
|
44
|
+
|
45
|
+
return_or_raise put("#{base_uri}/#{resource}", options)
|
46
|
+
end
|
47
|
+
|
48
|
+
def get_formatted(resource, authed: true, **options)
|
49
|
+
if authed
|
50
|
+
options = add_auth_header(options)
|
51
|
+
resource = "admin/realms/#{realm}/" + resource
|
52
|
+
end
|
53
|
+
|
54
|
+
return_or_raise get("#{base_uri}/#{resource}", options)
|
55
|
+
end
|
56
|
+
|
57
|
+
def delete_formatted(resource, json: true, authed: true, **options)
|
58
|
+
if authed
|
59
|
+
options = add_auth_header(options)
|
60
|
+
resource = "admin/realms/#{realm}/" + resource
|
61
|
+
end
|
62
|
+
if json
|
63
|
+
options = add_header(options, 'Content-Type', 'application/json')
|
64
|
+
options[:body] = options[:body].to_json
|
65
|
+
end
|
66
|
+
|
67
|
+
return_or_raise delete("#{base_uri}/#{resource}", options)
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
attr_accessor :configuration,
|
73
|
+
:access_token,
|
74
|
+
:access_token_expiry
|
75
|
+
|
76
|
+
delegate :base_url,
|
77
|
+
:realm,
|
78
|
+
:client_id,
|
79
|
+
:client_secret,
|
80
|
+
to: :configuration
|
81
|
+
|
82
|
+
delegate :raise_error, to: :error_handler
|
83
|
+
|
84
|
+
def return_or_raise(response)
|
85
|
+
if [200, 201, 204].include? response.code
|
86
|
+
response
|
87
|
+
else
|
88
|
+
raise_error response
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def auth
|
93
|
+
response = post_formatted("realms/#{realm}/protocol/openid-connect/token",
|
94
|
+
body: {
|
95
|
+
grant_type: 'client_credentials',
|
96
|
+
client_id: client_id,
|
97
|
+
client_secret: client_secret
|
98
|
+
}, json: false, authed: false)
|
99
|
+
update_token_fields response
|
100
|
+
access_token
|
101
|
+
end
|
102
|
+
|
103
|
+
def update_token_fields(response)
|
104
|
+
@access_token = response['access_token']
|
105
|
+
@access_token_expiry = Time.now + response['expires_in']
|
106
|
+
end
|
107
|
+
|
108
|
+
def base_uri
|
109
|
+
"#{base_url}/auth"
|
110
|
+
end
|
111
|
+
|
112
|
+
def error_handler
|
113
|
+
ErrorHandler
|
114
|
+
end
|
115
|
+
|
116
|
+
def token
|
117
|
+
now = Time.now
|
118
|
+
if access_token_expiry < now
|
119
|
+
auth
|
120
|
+
else
|
121
|
+
access_token
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def add_auth_header(options)
|
126
|
+
add_header(options, 'Authorization', "Bearer #{token}")
|
127
|
+
end
|
128
|
+
|
129
|
+
def add_header(options, header, value)
|
130
|
+
options[:headers] ||= {}
|
131
|
+
options[:headers] = options[:headers].merge({ "#{header}": value })
|
132
|
+
options
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def post(resource, body)
|
137
|
+
self.class.post_formatted(resource, body: body)
|
138
|
+
end
|
139
|
+
|
140
|
+
def put(resource, body)
|
141
|
+
self.class.put_formatted(resource, body: body)
|
142
|
+
end
|
143
|
+
|
144
|
+
def get(resource)
|
145
|
+
self.class.get_formatted(resource)
|
146
|
+
end
|
147
|
+
|
148
|
+
def delete(resource, body = {})
|
149
|
+
self.class.delete_formatted(resource, body: body)
|
150
|
+
end
|
151
|
+
|
152
|
+
def search(type, value)
|
153
|
+
get("#{type}?search=#{value}")
|
154
|
+
end
|
155
|
+
|
156
|
+
def find_by(type, field, value)
|
157
|
+
results = search(type, value).parsed_response
|
158
|
+
if results.is_a? Array
|
159
|
+
results.each do |instance|
|
160
|
+
return instance if instance[field] == value
|
161
|
+
end
|
162
|
+
end
|
163
|
+
raise NotFoundError, "Object type: #{type}, field: #{field}, value: #{value}"
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RippleKeycloak
|
4
|
+
class ErrorHandler
|
5
|
+
class << self
|
6
|
+
def error_map
|
7
|
+
{
|
8
|
+
'Realm does not exist' => RealmDoesNotExistError,
|
9
|
+
'unauthorized_client' => UnauthorizedClientError,
|
10
|
+
'HTTP 401 Unauthorized' => UnauthorizedError,
|
11
|
+
'Could not find role' => RoleNotFoundError,
|
12
|
+
'User not found' => UserNotFoundError
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
def raise_error(response)
|
17
|
+
formatted_error = {
|
18
|
+
code: response.code,
|
19
|
+
body: response.parsed_response
|
20
|
+
}
|
21
|
+
|
22
|
+
raise RippleKeycloak::ConflictError, formatted_error if response.code == 409
|
23
|
+
|
24
|
+
raise RippleKeycloak::Error, formatted_error unless response.key? 'error'
|
25
|
+
|
26
|
+
error_class = error_map[response['error']]
|
27
|
+
|
28
|
+
raise error_class, formatted_error
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RippleKeycloak
|
4
|
+
class Group < BaseModel
|
5
|
+
object_type 'groups'
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def create(name:, parent: false)
|
9
|
+
payload = { name: name }
|
10
|
+
path = create_path(parent)
|
11
|
+
response = client.post(path, payload)
|
12
|
+
group_id = response.headers['location'].split('/').last
|
13
|
+
|
14
|
+
group_id
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_role(group_id, role_name)
|
18
|
+
role = RippleKeycloak::Role.find_by(field: 'name', value: role_name)
|
19
|
+
client.post("groups/#{group_id}/role-mappings/realm", [role])
|
20
|
+
end
|
21
|
+
|
22
|
+
def remove_role(group_id, role_name)
|
23
|
+
role = RippleKeycloak::Role.find_by(field: 'name', value: role_name)
|
24
|
+
client.delete("groups/#{group_id}/role-mappings/realm", [role])
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def create_path(parent)
|
30
|
+
if parent
|
31
|
+
parent_group = find_by(field: 'name', value: parent)
|
32
|
+
raise GroupNotFoundError, parent unless parent_group
|
33
|
+
|
34
|
+
path = "groups/#{parent_group['id']}/children"
|
35
|
+
else
|
36
|
+
path = 'groups'
|
37
|
+
end
|
38
|
+
path
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RippleKeycloak
|
4
|
+
class Role < BaseModel
|
5
|
+
object_type 'roles'
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def create(name:)
|
9
|
+
payload = { name: name }
|
10
|
+
response = client.post('roles', payload)
|
11
|
+
role_id = response.headers['location'].split('/').last
|
12
|
+
|
13
|
+
role_id
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RippleKeycloak
|
4
|
+
class User < BaseModel
|
5
|
+
object_type 'users'
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def create(payload)
|
9
|
+
response = client.post('users', payload)
|
10
|
+
user_id = response.headers['location'].split('/').last
|
11
|
+
|
12
|
+
user_id
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_to_group(user_id, group_id)
|
16
|
+
client.put("users/#{user_id}/groups/#{group_id}", {
|
17
|
+
groupId: group_id,
|
18
|
+
userId: user_id
|
19
|
+
})
|
20
|
+
end
|
21
|
+
|
22
|
+
def remove_from_group(user_id, group_id)
|
23
|
+
client.delete("users/#{user_id}/groups/#{group_id}")
|
24
|
+
end
|
25
|
+
|
26
|
+
def add_role(user_id, role_name)
|
27
|
+
role = RippleKeycloak::Role.find_by(field: 'name', value: role_name)
|
28
|
+
client.post("users/#{user_id}/role-mappings/realm", [role])
|
29
|
+
end
|
30
|
+
|
31
|
+
def remove_role(user_id, role_name)
|
32
|
+
role = RippleKeycloak::Role.find_by(field: 'name', value: role_name)
|
33
|
+
client.delete("users/#{user_id}/role-mappings/realm", [role])
|
34
|
+
end
|
35
|
+
|
36
|
+
def send_email(user_id, actions, lifespan: 86400, client_id: false, redirect_uri: false)
|
37
|
+
url = "users/#{user_id}/execute-actions-email?"
|
38
|
+
url += "?lifespan=#{lifespan}"
|
39
|
+
url += "&client_id=#{client_id}" if client_id
|
40
|
+
url += "&redirect_uri=#{redirect_uri}" if redirect_uri
|
41
|
+
|
42
|
+
client.put(url, actions)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/ripple_keycloak/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'ripple_keycloak'
|
7
|
+
spec.version = RippleKeycloak::VERSION
|
8
|
+
spec.authors = ['Hex Event Solutions Limited']
|
9
|
+
spec.email = ['ruby@hexes.co.uk']
|
10
|
+
|
11
|
+
spec.summary = "Ruby interface to Keycloak's admin API"
|
12
|
+
spec.homepage = 'https://rubygems.org/gems/ripple_keycloak'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.7.0')
|
15
|
+
|
16
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
17
|
+
spec.metadata['source_code_uri'] = 'https://github.com/hex-event-solutions/ripple_keycloak'
|
18
|
+
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
|
+
end
|
24
|
+
spec.bindir = 'exe'
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ['lib']
|
27
|
+
|
28
|
+
spec.add_dependency('activesupport', '6.0.3.1')
|
29
|
+
spec.add_dependency('httparty', '0.18.0')
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ripple_keycloak
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hex Event Solutions Limited
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-06-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 6.0.3.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 6.0.3.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: httparty
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.18.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.18.0
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- ruby@hexes.co.uk
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".rspec"
|
50
|
+
- ".rubocop.yml"
|
51
|
+
- CODE_OF_CONDUCT.md
|
52
|
+
- Gemfile
|
53
|
+
- LICENSE.txt
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- bin/console
|
57
|
+
- bin/setup
|
58
|
+
- lib/ripple_keycloak.rb
|
59
|
+
- lib/ripple_keycloak/base_model.rb
|
60
|
+
- lib/ripple_keycloak/client.rb
|
61
|
+
- lib/ripple_keycloak/configuration.rb
|
62
|
+
- lib/ripple_keycloak/error_handler.rb
|
63
|
+
- lib/ripple_keycloak/group.rb
|
64
|
+
- lib/ripple_keycloak/role.rb
|
65
|
+
- lib/ripple_keycloak/user.rb
|
66
|
+
- lib/ripple_keycloak/version.rb
|
67
|
+
- ripple_keycloak.gemspec
|
68
|
+
homepage: https://rubygems.org/gems/ripple_keycloak
|
69
|
+
licenses:
|
70
|
+
- MIT
|
71
|
+
metadata:
|
72
|
+
homepage_uri: https://rubygems.org/gems/ripple_keycloak
|
73
|
+
source_code_uri: https://github.com/hex-event-solutions/ripple_keycloak
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.7.0
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubygems_version: 3.1.2
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: Ruby interface to Keycloak's admin API
|
93
|
+
test_files: []
|