deda-omniauth-keycloak 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: feb13e5fa04d0b6da319e0c62a1c5354a4ea1df224dfe6f4f9efc19688bd27f0
4
+ data.tar.gz: 7841e254570c27abd5a31ad5e93d97c2155899de4e50ff93f67f5f7b296eb68e
5
+ SHA512:
6
+ metadata.gz: 3784b898f36e7e32873fd6cf416d48c35d3dceeffe53d5bb49789940170d6cd1f20b7478b377b1beb52469fa38d26a0853d737ff9262b62f275850fbfdbfc362
7
+ data.tar.gz: 443bb2d926ad9c717c18b81f9131655741a39ff6a4a2638a2e0012567871736fd8c1532520909369f54967c32841078def4a675d371273c066d3778f5bbca708
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 1.16.5
@@ -0,0 +1,3 @@
1
+ {
2
+ "editor.tabSize": 2
3
+ }
data/CHANGELOG.md ADDED
@@ -0,0 +1,44 @@
1
+ # Changelog
2
+
3
+ ## [v1.2.1](https://github.com/ccrockett/omniauth-keycloak/tree/HEAD)
4
+
5
+ [Full Changelog](https://github.com/ccrockett/omniauth-keycloak/compare/v1.2.0...HEAD)
6
+
7
+ **Closed issues:**
8
+
9
+ - Dynamically load Client and Realm [\#11](https://github.com/ccrockett/omniauth-keycloak/issues/11)
10
+ - cannot load such file -- /Library/Ruby/Gems/2.6.0/gems/omniauth-keycloak-1.2.0/lib/omniauth-keycloak.rb \(LoadError\) [\#8](https://github.com/ccrockett/omniauth-keycloak/issues/8)
11
+ - Release json-jwt version restriction change [\#5](https://github.com/ccrockett/omniauth-keycloak/issues/5)
12
+
13
+ **Merged pull requests:**
14
+
15
+ - Raise errors on setup failure and logging with OmniAuth::Strategy::log method [\#10](https://github.com/ccrockett/omniauth-keycloak/pull/10) ([alexpetrov](https://github.com/alexpetrov))
16
+ - Bump json from 2.1.0 to 2.3.1 [\#9](https://github.com/ccrockett/omniauth-keycloak/pull/9) ([dependabot[bot]](https://github.com/apps/dependabot))
17
+ - Bump rack from 2.2.2 to 2.2.3 [\#7](https://github.com/ccrockett/omniauth-keycloak/pull/7) ([dependabot[bot]](https://github.com/apps/dependabot))
18
+
19
+ ## [v1.2.0](https://github.com/ccrockett/omniauth-keycloak/tree/v1.2.0) (2020-05-28)
20
+
21
+ [Full Changelog](https://github.com/ccrockett/omniauth-keycloak/compare/v1.1.0...v1.2.0)
22
+
23
+ **Merged pull requests:**
24
+
25
+ - Bump activesupport from 6.0.1 to 6.0.3.1 [\#6](https://github.com/ccrockett/omniauth-keycloak/pull/6) ([dependabot[bot]](https://github.com/apps/dependabot))
26
+ - Update rake requirement from ~\> 10.0 to ~\> 13.0 [\#4](https://github.com/ccrockett/omniauth-keycloak/pull/4) ([dependabot[bot]](https://github.com/apps/dependabot))
27
+ - Bump rack from 2.0.7 to 2.0.8 [\#2](https://github.com/ccrockett/omniauth-keycloak/pull/2) ([dependabot[bot]](https://github.com/apps/dependabot))
28
+ - Adding Devise Documentation [\#1](https://github.com/ccrockett/omniauth-keycloak/pull/1) ([masonhensley](https://github.com/masonhensley))
29
+
30
+ ## [v1.1.0](https://github.com/ccrockett/omniauth-keycloak/tree/v1.1.0) (2018-12-16)
31
+
32
+ [Full Changelog](https://github.com/ccrockett/omniauth-keycloak/compare/v1.0.1...v1.1.0)
33
+
34
+ ## [v1.0.1](https://github.com/ccrockett/omniauth-keycloak/tree/v1.0.1) (2018-12-16)
35
+
36
+ [Full Changelog](https://github.com/ccrockett/omniauth-keycloak/compare/v1.0.0...v1.0.1)
37
+
38
+ ## [v1.0.0](https://github.com/ccrockett/omniauth-keycloak/tree/v1.0.0) (2018-12-16)
39
+
40
+ [Full Changelog](https://github.com/ccrockett/omniauth-keycloak/compare/7877c8a75f9e3f342b49bf808fa69965377d60b5...v1.0.0)
41
+
42
+
43
+
44
+ \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
@@ -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 cameron.crockett@abcorp.com. 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 [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in omniauth-keycloak.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,98 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ omniauth-keycloak (1.2.0)
5
+ json-jwt (~> 1.12)
6
+ omniauth (~> 1.9.0)
7
+ omniauth-oauth2 (~> 1.6.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activesupport (6.0.3.1)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (>= 0.7, < 2)
15
+ minitest (~> 5.1)
16
+ tzinfo (~> 1.1)
17
+ zeitwerk (~> 2.2, >= 2.2.2)
18
+ addressable (2.5.2)
19
+ public_suffix (>= 2.0.2, < 4.0)
20
+ aes_key_wrap (1.0.1)
21
+ bindata (2.4.7)
22
+ concurrent-ruby (1.1.6)
23
+ crack (0.4.3)
24
+ safe_yaml (~> 1.0.0)
25
+ diff-lcs (1.3)
26
+ docile (1.3.1)
27
+ faraday (1.0.1)
28
+ multipart-post (>= 1.2, < 3)
29
+ hashdiff (0.3.7)
30
+ hashie (4.1.0)
31
+ i18n (1.8.2)
32
+ concurrent-ruby (~> 1.0)
33
+ json (2.3.1)
34
+ json-jwt (1.12.0)
35
+ activesupport (>= 4.2)
36
+ aes_key_wrap
37
+ bindata
38
+ jwt (2.2.1)
39
+ minitest (5.14.1)
40
+ multi_json (1.14.1)
41
+ multi_xml (0.6.0)
42
+ multipart-post (2.1.1)
43
+ oauth2 (1.4.4)
44
+ faraday (>= 0.8, < 2.0)
45
+ jwt (>= 1.0, < 3.0)
46
+ multi_json (~> 1.3)
47
+ multi_xml (~> 0.5)
48
+ rack (>= 1.2, < 3)
49
+ omniauth (1.9.1)
50
+ hashie (>= 3.4.6)
51
+ rack (>= 1.6.2, < 3)
52
+ omniauth-oauth2 (1.6.0)
53
+ oauth2 (~> 1.1)
54
+ omniauth (~> 1.9)
55
+ public_suffix (3.0.3)
56
+ rack (2.2.3)
57
+ rake (13.0.1)
58
+ rspec (3.8.0)
59
+ rspec-core (~> 3.8.0)
60
+ rspec-expectations (~> 3.8.0)
61
+ rspec-mocks (~> 3.8.0)
62
+ rspec-core (3.8.0)
63
+ rspec-support (~> 3.8.0)
64
+ rspec-expectations (3.8.1)
65
+ diff-lcs (>= 1.2.0, < 2.0)
66
+ rspec-support (~> 3.8.0)
67
+ rspec-mocks (3.8.0)
68
+ diff-lcs (>= 1.2.0, < 2.0)
69
+ rspec-support (~> 3.8.0)
70
+ rspec-support (3.8.0)
71
+ safe_yaml (1.0.4)
72
+ simplecov (0.16.1)
73
+ docile (~> 1.1)
74
+ json (>= 1.8, < 3)
75
+ simplecov-html (~> 0.10.0)
76
+ simplecov-html (0.10.2)
77
+ thread_safe (0.3.6)
78
+ tzinfo (1.2.7)
79
+ thread_safe (~> 0.1)
80
+ webmock (3.4.2)
81
+ addressable (>= 2.3.6)
82
+ crack (>= 0.3.2)
83
+ hashdiff
84
+ zeitwerk (2.3.0)
85
+
86
+ PLATFORMS
87
+ ruby
88
+
89
+ DEPENDENCIES
90
+ bundler (~> 1.16)
91
+ omniauth-keycloak!
92
+ rake (~> 13.0)
93
+ rspec (~> 3.0)
94
+ simplecov (~> 0.16.1)
95
+ webmock (~> 3.4.2)
96
+
97
+ BUNDLED WITH
98
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Cameron Crockett
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,83 @@
1
+ # Omniauth::Keycloak
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'omniauth-keycloak'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install omniauth-keycloak
18
+
19
+ ## Usage
20
+
21
+ `OmniAuth::Strategies::Keycloak` is simply a Rack middleware. Read the OmniAuth docs for detailed instructions: https://github.com/intridea/omniauth.
22
+
23
+ Here's a quick example, adding the middleware to a Rails app in `config/initializers/omniauth.rb`:
24
+
25
+ ```ruby
26
+ Rails.application.config.middleware.use OmniAuth::Builder do
27
+ provider :keycloak_openid, 'Example-Client', '19cca35f-dddd-473a-bdd5-03f00d61d884',
28
+ client_options: {site: 'https://example.keycloak-url.com', realm: 'example-realm'}
29
+ end
30
+ ```
31
+
32
+ ## Devise Usage
33
+ Adapted from [Devise OmniAuth Instructions](https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview)
34
+
35
+ ```ruby
36
+ # app/models/user.rb
37
+ class User < ApplicationRecord
38
+ #...
39
+ devise :omniauthable, omniauth_providers: %i[keycloakopenid]
40
+ #...
41
+ end
42
+
43
+ # config/initializers/devise.rb
44
+ config.omniauth :keycloak_openid, "Example-Client-Name", "example-secret-if-configured", client_options: { site: "https://example.keycloak-url.com", realm: "example-realm" }, :strategy_class => OmniAuth::Strategies::KeycloakOpenId
45
+
46
+ # Below controller assumes callback route configuration following
47
+ # in config/routes.rb
48
+ Devise.setup do |config|
49
+ # ...
50
+ devise_for :users, controllers: { omniauth_callbacks: 'users/omniauth_callbacks' }
51
+ end
52
+
53
+ # app/controllers/users/omniauth_callbacks_controller.rb
54
+ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
55
+ def keycloakopenid
56
+ Rails.logger.debug(request.env["omniauth.auth"])
57
+ @user = User.from_omniauth(request.env["omniauth.auth"])
58
+ if @user.persisted?
59
+ sign_in_and_redirect @user, event: :authentication
60
+ else
61
+ session["devise.keycloakopenid_data"] = request.env["omniauth.auth"]
62
+ redirect_to new_user_registration_url
63
+ end
64
+ end
65
+
66
+ def failure
67
+ redirect_to root_path
68
+ end
69
+ end
70
+
71
+ ```
72
+
73
+ ## Contributing
74
+
75
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ccrockett/omniauth-keycloak. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
76
+
77
+ ## License
78
+
79
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
80
+
81
+ ## Code of Conduct
82
+
83
+ Everyone interacting in the Omniauth::Keycloak project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ccrockett/omniauth-keycloak/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "omniauth/omniauth-keycloak"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,35 @@
1
+ require File.expand_path("../lib/keycloak/version", __FILE__)
2
+ Gem::Specification.new do |spec|
3
+ spec.name = "deda-omniauth-keycloak"
4
+ spec.version = Omniauth::Keycloak::VERSION
5
+ spec.authors = ["Cameron Crockett","Fabiano Pavan"]
6
+ spec.email = ["cameron.crockett@ccrockett.com"]
7
+
8
+ spec.description = %q{Omniauth strategy for Keycloak}
9
+ spec.summary = spec.description
10
+ spec.homepage = "https://github.com/ccrockett/omniauth-keycloak"
11
+ spec.license = "MIT"
12
+ spec.required_rubygems_version = '>= 1.3.5'
13
+ spec.required_ruby_version = '>= 2.2'
14
+
15
+ # Specify which files should be added to the gem when it is released.
16
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
17
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
18
+ `git ls-files -z`.split("\x0")
19
+ end
20
+
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+
26
+ spec.add_dependency "omniauth", "~> 1.9.0"
27
+ spec.add_dependency "omniauth-oauth2", "~> 1.6.0"
28
+ spec.add_dependency "json-jwt", "~> 1.12"
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.16"
31
+ spec.add_development_dependency "rake", "~> 13.0"
32
+ spec.add_development_dependency "rspec", "~> 3.0"
33
+ spec.add_development_dependency 'simplecov', '~> 0.16.1'
34
+ spec.add_development_dependency 'webmock', '~> 3.4.2'
35
+ end
@@ -0,0 +1,2 @@
1
+ require "keycloak/version"
2
+ require "omniauth/strategies/keycloak-openid"
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module Keycloak
3
+ VERSION = "1.2.1"
4
+ end
5
+ end
@@ -0,0 +1,134 @@
1
+ require 'omniauth'
2
+ require 'omniauth-oauth2'
3
+ require 'json/jwt'
4
+ require 'uri'
5
+
6
+ module OmniAuth
7
+ module Strategies
8
+ class KeycloakOpenId < OmniAuth::Strategies::OAuth2
9
+
10
+ class Error < RuntimeError; end
11
+ class ConfigurationError < Error; end
12
+ class IntegrationError < Error; end
13
+
14
+ attr_reader :authorize_url
15
+ attr_reader :token_url
16
+ attr_reader :cert
17
+
18
+
19
+ def setup_phase
20
+ super
21
+ if @authorize_url.nil? || @token_url.nil?
22
+
23
+ prevent_site_option_mistake
24
+ realm = options.client_options[:realm].nil? ? options.client_id : options.client_options[:realm]
25
+ site = options.client_options[:site]
26
+
27
+ raise_on_failure = options.client_options.fetch(:raise_on_failure, false)
28
+ config_url = URI.join(site, "#{auth_url_base}/realms/#{realm}/.well-known/openid-configuration")
29
+
30
+ log :debug, "Going to get Keycloak configuration. URL: #{config_url}"
31
+ response = Faraday.get config_url
32
+ if (response.status == 200)
33
+ json = MultiJson.load(response.body)
34
+
35
+ @certs_endpoint = json["jwks_uri"]
36
+ @userinfo_endpoint = json["userinfo_endpoint"]
37
+ @authorize_url = URI(json["authorization_endpoint"]).path
38
+ @token_url = URI(json["token_endpoint"]).path
39
+
40
+ log_config(json)
41
+
42
+ options.client_options.merge!({
43
+ authorize_url: @authorize_url,
44
+ token_url: @token_url
45
+ })
46
+ log :debug, "Going to get certificates. URL: #{@certs_endpoint}"
47
+ certs = Faraday.get @certs_endpoint
48
+ if (certs.status == 200)
49
+ json = MultiJson.load(certs.body)
50
+ @cert = json["keys"][0]
51
+ log :debug, "Successfully got certificate. Certificate length: #{@cert.length}"
52
+ else
53
+ message = "Coundn't get certificate. URL: #{@certs_endpoint}"
54
+ log :error, message
55
+ raise IntegrationError, message if raise_on_failure
56
+ end
57
+ else
58
+ message = "Keycloak configuration request failed with status: #{response.status}. " \
59
+ "URL: #{config_url}"
60
+ log :error, message
61
+ raise IntegrationError, message if raise_on_failure
62
+ end
63
+ end
64
+ end
65
+
66
+ def request_phase
67
+ options.authorize_options.each {|key| options[key] = request.params[key.to_s] }
68
+ redirect client.auth_code.authorize_url(authorize_params.merge({:redirect_uri => callback_url}))
69
+ end
70
+
71
+
72
+ def auth_url_base
73
+ return '/auth' unless options.client_options[:base_url]
74
+ base_url = options.client_options[:base_url]
75
+ return base_url if (base_url == '' || base_url[0] == '/')
76
+
77
+ raise ConfigurationError, "Keycloak base_url option should start with '/'. Current value: #{base_url}"
78
+ end
79
+
80
+ def prevent_site_option_mistake
81
+ site = options.client_options[:site]
82
+ return unless site =~ /\/auth$/
83
+
84
+ raise ConfigurationError, "Keycloak site parameter should not include /auth part, only domain. Current value: #{site}"
85
+ end
86
+
87
+ def log_config(config_json)
88
+ log_keycloak_config = options.client_options.fetch(:log_keycloak_config, false)
89
+ log :debug, "Successfully got Keycloak config"
90
+ log :debug, "Keycloak config: #{config_json}" if log_keycloak_config
91
+ log :debug, "Certs endpoint: #{@certs_endpoint}"
92
+ log :debug, "Userinfo endpoint: #{@userinfo_endpoint}"
93
+ log :debug, "Authorize url: #{@authorize_url}"
94
+ log :debug, "Token url: #{@token_url}"
95
+ end
96
+
97
+ #1.5.1
98
+ def build_access_token
99
+ verifier = request.params["code"]
100
+ client.auth_code.get_token(verifier,
101
+ {:redirect_uri => callback_url.gsub(/\?.+\Z/, "")}
102
+ .merge(token_params.to_hash(:symbolize_keys => true)),
103
+ deep_symbolize(options.auth_token_params))
104
+ end
105
+
106
+
107
+ uid{ raw_info['sub'] }
108
+
109
+ info do
110
+ {
111
+ :name => raw_info['name'],
112
+ :email => raw_info['email'],
113
+ :first_name => raw_info['given_name'],
114
+ :last_name => raw_info['family_name']
115
+ }
116
+ end
117
+
118
+ extra do
119
+ {
120
+ 'raw_info' => raw_info
121
+ }
122
+ end
123
+
124
+ def raw_info
125
+ id_token_string = access_token.token
126
+ jwk = JSON::JWK.new(@cert)
127
+ id_token = JSON::JWT.decode id_token_string, jwk
128
+ id_token
129
+ end
130
+
131
+ OmniAuth.config.add_camelization('keycloak_openid', 'KeycloakOpenId')
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,95 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe OmniAuth::Strategies::KeycloakOpenId do
4
+ body = '{"issuer": "http://localhost:8080/auth/realms/example-realm",
5
+ "authorization_endpoint": "http://localhost:8080/auth/realms/example-realm/protocol/openid-connect/auth",
6
+ "token_endpoint": "http://localhost:8080/auth/realms/example-realm/protocol/openid-connect/token",
7
+ "token_introspection_endpoint": "http://localhost:8080/auth/realms/example-realm/protocol/openid-connect/token/introspect",
8
+ "userinfo_endpoint": "http://localhost:8080/auth/realms/example-realm/protocol/openid-connect/userinfo",
9
+ "end_session_endpoint": "http://localhost:8080/auth/realms/example-realm/protocol/openid-connect/logout",
10
+ "jwks_uri": "http://localhost:8080/auth/realms/example-realm/protocol/openid-connect/certs",
11
+ "check_session_iframe": "http://localhost:8080/auth/realms/example-realm/protocol/openid-connect/login-status-iframe.html",
12
+ "grant_types_supported": ["authorization_code", "implicit", "refresh_token", "password", "client_credentials"],
13
+ "response_types_supported": ["code", "none", "id_token", "token", "id_token token", "code id_token", "code token", "code id_token token"],
14
+ "subject_types_supported": ["public", "pairwise"],
15
+ "id_token_signing_alg_values_supported": ["RS256"],
16
+ "userinfo_signing_alg_values_supported": ["RS256"],
17
+ "request_object_signing_alg_values_supported": ["none", "RS256"],
18
+ "response_modes_supported": ["query", "fragment", "form_post"],
19
+ "registration_endpoint": "http://localhost:8080/auth/realms/example-realm/clients-registrations/openid-connect",
20
+ "token_endpoint_auth_methods_supported": ["private_key_jwt", "client_secret_basic", "client_secret_post"],
21
+ "token_endpoint_auth_signing_alg_values_supported": ["RS256"],
22
+ "claims_supported": ["sub", "iss", "auth_time", "name", "given_name", "family_name", "preferred_username", "email"],
23
+ "claim_types_supported": ["normal"],
24
+ "claims_parameter_supported": false,
25
+ "scopes_supported": ["openid", "offline_access"],
26
+ "request_parameter_supported": true,
27
+ "request_uri_parameter_supported": true}'
28
+
29
+ context 'client options' do
30
+ subject do
31
+ stub_request(:get, "http://localhost:8080/auth/realms/example-realm/.well-known/openid-configuration")
32
+ .to_return(status: 200, body: body, headers: {})
33
+ stub_request(:get, "http://localhost:8080/auth/realms/example-realm/protocol/openid-connect/certs")
34
+ .to_return(status: 404, body: "", headers: {})
35
+ OmniAuth::Strategies::KeycloakOpenId.new('keycloak-openid', 'Example-Client', 'b53c572b-9f3b-4e79-bf8b-f03c799ba6ec',
36
+ client_options: {site: 'http://localhost:8080/', realm: 'example-realm'})
37
+ end
38
+
39
+ it 'should have the correct keycloak token url' do
40
+ subject.setup_phase
41
+ expect(subject.token_url).to eq('/auth/realms/example-realm/protocol/openid-connect/token')
42
+ end
43
+
44
+ it 'should have the correct keycloak authorization url' do
45
+ subject.setup_phase
46
+ expect(subject.authorize_url).to eq('/auth/realms/example-realm/protocol/openid-connect/auth')
47
+ end
48
+ end
49
+
50
+ describe 'errors processing' do
51
+ context 'when site contains /auth part' do
52
+ subject do
53
+ OmniAuth::Strategies::KeycloakOpenId.new('keycloak-openid', 'Example-Client', 'b53c572b-9f3b-4e79-bf8b-f03c799ba6ec',
54
+ client_options: {site: 'http://localhost:8080/auth', realm: 'example-realm', raise_on_failure: true})
55
+ end
56
+
57
+ it 'raises Configuration Error' do
58
+ expect{ subject.setup_phase }
59
+ .to raise_error(OmniAuth::Strategies::KeycloakOpenId::ConfigurationError)
60
+ end
61
+ end
62
+
63
+ context 'when raise_on_failure option is true' do
64
+ context 'when openid configuration endpoint returns error response' do
65
+ subject do
66
+ stub_request(:get, "http://localhost:8080/auth/realms/example-realm/.well-known/openid-configuration")
67
+ .to_return(status: 404, body: "", headers: {})
68
+ OmniAuth::Strategies::KeycloakOpenId.new('keycloak-openid', 'Example-Client', 'b53c572b-9f3b-4e79-bf8b-f03c799ba6ec',
69
+ client_options: {site: 'http://localhost:8080', realm: 'example-realm', raise_on_failure: true})
70
+ end
71
+
72
+ it 'raises Integration Error' do
73
+ expect{ subject.setup_phase }
74
+ .to raise_error(OmniAuth::Strategies::KeycloakOpenId::IntegrationError)
75
+ end
76
+ end
77
+
78
+ context 'when certificates endpoint returns error response' do
79
+ subject do
80
+ stub_request(:get, "http://localhost:8080/auth/realms/example-realm/.well-known/openid-configuration")
81
+ .to_return(status: 200, body: body, headers: {})
82
+ stub_request(:get, "http://localhost:8080/auth/realms/example-realm/protocol/openid-connect/certs")
83
+ .to_return(status: 404, body: "", headers: {})
84
+ OmniAuth::Strategies::KeycloakOpenId.new('keycloak-openid', 'Example-Client', 'b53c572b-9f3b-4e79-bf8b-f03c799ba6ec',
85
+ client_options: {site: 'http://localhost:8080', realm: 'example-realm', raise_on_failure: true})
86
+ end
87
+
88
+ it 'raises Integration Error' do
89
+ expect{ subject.setup_phase }
90
+ .to raise_error(OmniAuth::Strategies::KeycloakOpenId::IntegrationError)
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,27 @@
1
+ require "bundler/setup"
2
+ require "omniauth/strategies/keycloak-openid"
3
+ require "webmock/rspec"
4
+
5
+ if RUBY_VERSION >= "1.9"
6
+ require "simplecov"
7
+
8
+ SimpleCov.start do
9
+ minimum_coverage(93.00)
10
+ end
11
+ end
12
+
13
+ require "rspec"
14
+ require "omniauth"
15
+
16
+ RSpec.configure do |config|
17
+ # Enable flags like --only-failures and --next-failure
18
+ config.example_status_persistence_file_path = ".rspec_status"
19
+
20
+ # Disable RSpec exposing methods globally on `Module` and `main`
21
+ config.disable_monkey_patching!
22
+
23
+ config.expect_with :rspec do |c|
24
+ c.syntax = :expect
25
+ end
26
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
27
+ end
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deda-omniauth-keycloak
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Cameron Crockett
8
+ - Fabiano Pavan
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2023-12-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: omniauth
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 1.9.0
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 1.9.0
28
+ - !ruby/object:Gem::Dependency
29
+ name: omniauth-oauth2
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: 1.6.0
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: 1.6.0
42
+ - !ruby/object:Gem::Dependency
43
+ name: json-jwt
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '1.12'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '1.12'
56
+ - !ruby/object:Gem::Dependency
57
+ name: bundler
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '1.16'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.16'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rake
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '13.0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '13.0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rspec
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '3.0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '3.0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: simplecov
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: 0.16.1
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: 0.16.1
112
+ - !ruby/object:Gem::Dependency
113
+ name: webmock
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: 3.4.2
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: 3.4.2
126
+ description: Omniauth strategy for Keycloak
127
+ email:
128
+ - cameron.crockett@ccrockett.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".gitignore"
134
+ - ".rspec"
135
+ - ".travis.yml"
136
+ - ".vscode/settings.json"
137
+ - CHANGELOG.md
138
+ - CODE_OF_CONDUCT.md
139
+ - Gemfile
140
+ - Gemfile.lock
141
+ - LICENSE.txt
142
+ - README.md
143
+ - Rakefile
144
+ - bin/console
145
+ - bin/setup
146
+ - deda-omniauth-keycloak.gemspec
147
+ - lib/deda-omniauth-keycloak.rb
148
+ - lib/keycloak/version.rb
149
+ - lib/omniauth/strategies/keycloak-openid.rb
150
+ - spec/omniauth/strategies/keycloak_spec.rb
151
+ - spec/spec_helper.rb
152
+ homepage: https://github.com/ccrockett/omniauth-keycloak
153
+ licenses:
154
+ - MIT
155
+ metadata: {}
156
+ post_install_message:
157
+ rdoc_options: []
158
+ require_paths:
159
+ - lib
160
+ required_ruby_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: '2.2'
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: 1.3.5
170
+ requirements: []
171
+ rubygems_version: 3.0.8
172
+ signing_key:
173
+ specification_version: 4
174
+ summary: Omniauth strategy for Keycloak
175
+ test_files: []