omniauth-keycloak-openid 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +35 -0
- data/lib/omniauth-keycloak-openid.rb +5 -0
- data/lib/omniauth-keycloak-openid/version.rb +5 -0
- data/lib/omniauth/strategies/keycloak-openid.rb +78 -0
- data/omniauth-keycloak-openid.gemspec +29 -0
- metadata +138 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2e4c8ca60a9bacc92dd08c12bd8d96f5b9df0237b87a6f343a0dec89878bfc45
|
4
|
+
data.tar.gz: 8aab3aa10ec9862b607298c53f5147adcd6756f5ceb7c0b323368a3ca7493c4c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9c45cda33a12259125c49838c1f7b3795ee58b6c9591b38080a2dc3860f8915ab08b8287cdd58f2641fa1f0076678da96356d2d321432311d50f7f9092832be7
|
7
|
+
data.tar.gz: 80377082507e28c1957615a96784d2eae0991becf54e7c8ea34ab603d5b5c0d19c124e919fea437ad86c706cfa03cfeccd8bd752834e28918e32cfb6efcfff53
|
data/.gitignore
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Cisco Systems, Inc.
|
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,35 @@
|
|
1
|
+
# OmniAuth::KeycloakOpenID
|
2
|
+
|
3
|
+
This is a custom [OmniAuth](https://github.com/omniauth/omniauth) "provider" gem, which authenticates a user via keycloak OIDC protocol.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```
|
10
|
+
gem 'omniauth-keycloak-openid'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or directly install and add to Gemfile it yourself as:
|
20
|
+
|
21
|
+
```
|
22
|
+
$ bundle add omniauth-keycloak-openid
|
23
|
+
```
|
24
|
+
|
25
|
+
In omniauth.rb file
|
26
|
+
```ruby
|
27
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
28
|
+
provider :keycloak_openid, ENV['CLIENT_ID'], ENV['CLIENT_SECRET'], scope: "openid profile email", redirect_uri: 'http://localhost:3000/auth/keycloak_openid/callback'
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
|
33
|
+
## License
|
34
|
+
|
35
|
+
The gem currently has the [MIT License](http://opensource.org/licenses/MIT) license file included, but todate, has NOT been made available as open source.
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'omniauth-oauth2'
|
2
|
+
|
3
|
+
module OmniAuth
|
4
|
+
module Strategies
|
5
|
+
class KeycloakOpenID < OmniAuth::Strategies::OAuth2
|
6
|
+
DEFAULT_SCOPE = "openid profile email"
|
7
|
+
DEFAULT_RESPONSE_TYPE = "code"
|
8
|
+
|
9
|
+
option :name, 'keycloak_openid'
|
10
|
+
option :client_options, site: 'http://localhost:8080'
|
11
|
+
|
12
|
+
option :authorize_options, %i[scope response_type redirect_uri]
|
13
|
+
option :provider_ignores_state, true
|
14
|
+
|
15
|
+
uid { raw_info['user'] }
|
16
|
+
|
17
|
+
info do
|
18
|
+
{
|
19
|
+
name: raw_info['name'] || "#{raw_info['given_name']} #{raw_info['family_name']}",
|
20
|
+
email: raw_info['email'],
|
21
|
+
first_name: raw_info['given_name'],
|
22
|
+
last_name: raw_info['family_name'],
|
23
|
+
phone: raw_info['phone_number']
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
extra do
|
28
|
+
prune!('raw_info' => raw_info)
|
29
|
+
end
|
30
|
+
|
31
|
+
def callback_url
|
32
|
+
options[:redirect_uri] || (full_host + script_name + callback_path)
|
33
|
+
end
|
34
|
+
|
35
|
+
def raw_info
|
36
|
+
@raw_info ||= load_identity
|
37
|
+
end
|
38
|
+
|
39
|
+
def authorize_params
|
40
|
+
super.tap do |params|
|
41
|
+
params[:scope] ||= DEFAULT_SCOPE
|
42
|
+
params[:response_type] ||= DEFAULT_RESPONSE_TYPE
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def build_access_token
|
47
|
+
if options[:grant_type] == 'auth_code'
|
48
|
+
verifier = request.params['code']
|
49
|
+
client.auth_code.get_token(verifier, get_token_options(callback_url), deep_symbolize(options.auth_token_params))
|
50
|
+
else
|
51
|
+
client.password.get_token(request.params[:username],
|
52
|
+
request.params[:password],
|
53
|
+
scope: DEFAULT_SCOPE)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def load_identity
|
60
|
+
access_token.options[:mode] = :header
|
61
|
+
access_token.options[:param_name] = :access_token
|
62
|
+
access_token.options[:grant_type] = :authorization_code
|
63
|
+
access_token.get(options[:userinfo_url]).parsed || {}
|
64
|
+
end
|
65
|
+
|
66
|
+
def get_token_options(redirect_uri)
|
67
|
+
{ redirect_uri: redirect_uri }.merge(token_params.to_hash(symbolize_keys: true))
|
68
|
+
end
|
69
|
+
|
70
|
+
def prune!(hash)
|
71
|
+
hash.delete_if do |_, value|
|
72
|
+
prune!(value) if value.is_a?(Hash)
|
73
|
+
value.nil? || (value.respond_to?(:empty?) && value.empty?)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'omniauth-keycloak-openid/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "omniauth-keycloak-openid"
|
8
|
+
spec.version = OmniAuth::KeycloakOpenID::VERSION
|
9
|
+
spec.authors = ["Dinesh Budhayer"]
|
10
|
+
spec.email = ["budhayer96d@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Keycloak OpenID Connect supporting strategy for Omniauth.}
|
13
|
+
spec.description = %q{This gem authenticates a user by Keycloak OpenID connect protocol.}
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.homepage = "https://github.com/ayerdines/omniauth-keycloak-openid"
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_runtime_dependency 'omniauth', '~> 1.1', '>= 1.1.1'
|
24
|
+
spec.add_runtime_dependency 'omniauth-oauth2', '~> 1.3', '>= 1.3.1'
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
27
|
+
spec.add_development_dependency "rake", '~> 12.3', '>= 12.3.3'
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-keycloak-openid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dinesh Budhayer
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-01-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: omniauth
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.1'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.1.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.1'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.1.1
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: omniauth-oauth2
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.3'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 1.3.1
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '1.3'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 1.3.1
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: bundler
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '1.13'
|
60
|
+
type: :development
|
61
|
+
prerelease: false
|
62
|
+
version_requirements: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - "~>"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '1.13'
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: rake
|
69
|
+
requirement: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - "~>"
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '12.3'
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 12.3.3
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '12.3'
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 12.3.3
|
87
|
+
- !ruby/object:Gem::Dependency
|
88
|
+
name: rspec
|
89
|
+
requirement: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - "~>"
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '3.0'
|
94
|
+
type: :development
|
95
|
+
prerelease: false
|
96
|
+
version_requirements: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - "~>"
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '3.0'
|
101
|
+
description: This gem authenticates a user by Keycloak OpenID connect protocol.
|
102
|
+
email:
|
103
|
+
- budhayer96d@gmail.com
|
104
|
+
executables: []
|
105
|
+
extensions: []
|
106
|
+
extra_rdoc_files: []
|
107
|
+
files:
|
108
|
+
- ".gitignore"
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- lib/omniauth-keycloak-openid.rb
|
112
|
+
- lib/omniauth-keycloak-openid/version.rb
|
113
|
+
- lib/omniauth/strategies/keycloak-openid.rb
|
114
|
+
- omniauth-keycloak-openid.gemspec
|
115
|
+
homepage: https://github.com/ayerdines/omniauth-keycloak-openid
|
116
|
+
licenses:
|
117
|
+
- MIT
|
118
|
+
metadata: {}
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options: []
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
requirements: []
|
134
|
+
rubygems_version: 3.2.3
|
135
|
+
signing_key:
|
136
|
+
specification_version: 4
|
137
|
+
summary: Keycloak OpenID Connect supporting strategy for Omniauth.
|
138
|
+
test_files: []
|