openid_backchannel_logout 0.1.0
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/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +4 -0
- data/lib/generators/openid_backchannel_logout/install/install_generator.rb +52 -0
- data/lib/generators/openid_backchannel_logout/templates/backchannel_logouts_controller.rb +19 -0
- data/lib/generators/openid_backchannel_logout/templates/initializer.rb +6 -0
- data/lib/openid_backchannel_logout/configuration.rb +14 -0
- data/lib/openid_backchannel_logout/error.rb +55 -0
- data/lib/openid_backchannel_logout/executor.rb +55 -0
- data/lib/openid_backchannel_logout/token_validator.rb +92 -0
- data/lib/openid_backchannel_logout/version.rb +5 -0
- data/lib/openid_backchannel_logout.rb +17 -0
- data/sig/openid_backchannel_logout.rbs +4 -0
- metadata +75 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 763a37be3d48c7a97844aac81708338c7ed7611aaa45d9bda3f4dc9ee2de5999
|
4
|
+
data.tar.gz: 17b07998e9ed65452a81b931dff14d8c3a1606ce9ac34eedfb085228245af16e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 181bf76cf0cd74622e4dc302072e8887ccab1dbe1f4fcf88b2ae978308a24d42789b3498d691ba4fe120c8b69d1c37171d1e58cd4070f33fc6e61240e15361b4
|
7
|
+
data.tar.gz: e414c4f742bc57cda4777b52028f4c8b413e9de27b7d4b597e3c5d77d0ec7ece2b2835a413eb3940b93c74ce06040a735982ec25f9766d644086d912434cb3fb
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
10
|
+
identity and orientation.
|
11
|
+
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
13
|
+
diverse, inclusive, and healthy community.
|
14
|
+
|
15
|
+
## Our Standards
|
16
|
+
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
18
|
+
community include:
|
19
|
+
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
24
|
+
and learning from the experience
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
26
|
+
community
|
27
|
+
|
28
|
+
Examples of unacceptable behavior include:
|
29
|
+
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
31
|
+
any kind
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
33
|
+
* Public or private harassment
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
35
|
+
without their explicit permission
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
37
|
+
professional setting
|
38
|
+
|
39
|
+
## Enforcement Responsibilities
|
40
|
+
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
44
|
+
or harmful.
|
45
|
+
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
49
|
+
decisions when appropriate.
|
50
|
+
|
51
|
+
## Scope
|
52
|
+
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
54
|
+
an individual is officially representing the community in public spaces.
|
55
|
+
Examples of representing our community include using an official email address,
|
56
|
+
posting via an official social media account, or acting as an appointed
|
57
|
+
representative at an online or offline event.
|
58
|
+
|
59
|
+
## Enforcement
|
60
|
+
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
62
|
+
reported to the community leaders responsible for enforcement at
|
63
|
+
[INSERT CONTACT METHOD].
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
65
|
+
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
67
|
+
reporter of any incident.
|
68
|
+
|
69
|
+
## Enforcement Guidelines
|
70
|
+
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
73
|
+
|
74
|
+
### 1. Correction
|
75
|
+
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
77
|
+
unprofessional or unwelcome in the community.
|
78
|
+
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
82
|
+
|
83
|
+
### 2. Warning
|
84
|
+
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
86
|
+
actions.
|
87
|
+
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
93
|
+
ban.
|
94
|
+
|
95
|
+
### 3. Temporary Ban
|
96
|
+
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
98
|
+
sustained inappropriate behavior.
|
99
|
+
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
101
|
+
communication with the community for a specified period of time. No public or
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
104
|
+
Violating these terms may lead to a permanent ban.
|
105
|
+
|
106
|
+
### 4. Permanent Ban
|
107
|
+
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
111
|
+
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
113
|
+
community.
|
114
|
+
|
115
|
+
## Attribution
|
116
|
+
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
118
|
+
version 2.1, available at
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
120
|
+
|
121
|
+
Community Impact Guidelines were inspired by
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
123
|
+
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
127
|
+
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Nguyen Ngoc Hai
|
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,43 @@
|
|
1
|
+
# OpenidBackchannelLogout
|
2
|
+
|
3
|
+
TODO: Delete this and the text below, and describe your gem
|
4
|
+
|
5
|
+
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/openid_backchannel_logout`. To experiment with that code, run `bin/console` for an interactive prompt.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
10
|
+
|
11
|
+
Install the gem and add to the application's Gemfile by executing:
|
12
|
+
|
13
|
+
```bash
|
14
|
+
bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
15
|
+
```
|
16
|
+
|
17
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
18
|
+
|
19
|
+
```bash
|
20
|
+
gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
21
|
+
```
|
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. 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 the created tag, 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]/openid_backchannel_logout. 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]/openid_backchannel_logout/blob/master/CODE_OF_CONDUCT.md).
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
+
|
41
|
+
## Code of Conduct
|
42
|
+
|
43
|
+
Everyone interacting in the OpenidBackchannelLogout project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/openid_backchannel_logout/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators'
|
4
|
+
|
5
|
+
module OpenidBackchannelLogout
|
6
|
+
module Generators
|
7
|
+
class InstallGenerator < Rails::Generators::Base
|
8
|
+
source_root File.expand_path('../templates', __dir__)
|
9
|
+
|
10
|
+
def create_initializer
|
11
|
+
copy_file 'initializer.rb', 'config/initializers/openid_backchannel_logout.rb'
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_controller
|
15
|
+
template 'backchannel_logouts_controller.rb', 'app/controllers/api/internal/backchannel_logouts_controller.rb'
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_routes
|
19
|
+
routes_file = File.join('config', 'routes.rb')
|
20
|
+
route_to_add = "resource :backchannel_logout, only: :create\n"
|
21
|
+
|
22
|
+
if File.readlines(routes_file).grep(/resource :backchannel_logout/).any?
|
23
|
+
say_status('skipped', 'Routes for backchannel_logout already exist, skipping.', :yellow)
|
24
|
+
else
|
25
|
+
content = File.read(routes_file)
|
26
|
+
|
27
|
+
if content.match?(/namespace :internal(,.*)? do/)
|
28
|
+
# Inject into the existing `namespace :internal` block
|
29
|
+
inject_into_file routes_file, " #{route_to_add}", after: /namespace :internal(,.*)? do\n/
|
30
|
+
say_status('added', 'Route added to existing namespace :internal.', :green)
|
31
|
+
elsif content.match?(/namespace :api(,.*)? do/)
|
32
|
+
inject_into_file routes_file, <<-RUBY, after: /namespace :api(,.*)? do\n/
|
33
|
+
namespace :internal do
|
34
|
+
#{route_to_add.strip}
|
35
|
+
end
|
36
|
+
RUBY
|
37
|
+
say_status('added', 'Namespace :internal created and route added.', :green)
|
38
|
+
else
|
39
|
+
inject_into_file routes_file, <<-RUBY, after: /Rails.application.routes.draw(,.*)? do\n/
|
40
|
+
namespace :api, defaults: { format: 'json' } do
|
41
|
+
namespace :internal do
|
42
|
+
#{route_to_add.strip}
|
43
|
+
end
|
44
|
+
end
|
45
|
+
RUBY
|
46
|
+
say_status('added', 'Namespace :api and :internal created, and route added.', :green)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Api
|
4
|
+
module Internal
|
5
|
+
class BackchannelLogoutsController < ActionController::API
|
6
|
+
def create
|
7
|
+
OpenidBackchannelLogout::Executor.new.call(request) do |sub, sid|
|
8
|
+
Rails.logger.info("Logging out user with sub: #{sub}, sid: #{sid}")
|
9
|
+
# TODO: Implement the logic to logout the user
|
10
|
+
end
|
11
|
+
|
12
|
+
render plain: 'Logout successful', status: :ok
|
13
|
+
rescue StandardError => e
|
14
|
+
Rails.logger.error("Backchannel logout error: #{e.message}")
|
15
|
+
render plain: e.message, status: :bad_request
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'error'
|
4
|
+
|
5
|
+
module OpenidBackchannelLogout
|
6
|
+
class Configuration
|
7
|
+
attr_accessor :issuer, :audience
|
8
|
+
|
9
|
+
def validate!
|
10
|
+
raise Error::IssuerNotConfiguredError unless issuer.present?
|
11
|
+
raise Error::AudienceNotConfiguredError unless audience.present?
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenidBackchannelLogout
|
4
|
+
module Error
|
5
|
+
class EncodeError < StandardError; end
|
6
|
+
class DecodeError < StandardError; end
|
7
|
+
class MissingLogoutTokenError < StandardError; end
|
8
|
+
class InvalidLogoutTokenError < DecodeError; end
|
9
|
+
|
10
|
+
class MissingRequiredClaimError < DecodeError
|
11
|
+
def initialize(claim)
|
12
|
+
super("Missing #{claim} claim")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class MissingSubOrSidClaimError < DecodeError; end
|
17
|
+
class InvalidAlgorithmError < DecodeError; end
|
18
|
+
class InvalidIatError < DecodeError; end
|
19
|
+
|
20
|
+
class InvalidIssuerError < DecodeError
|
21
|
+
def initialize(expected_issuer, actual_issuer)
|
22
|
+
super("Invalid iss claim. Expected: #{expected_issuer}, but received: #{actual_issuer || '<none>'}")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class InvalidAudError < DecodeError
|
27
|
+
def initialize(expected_audience, actual_audience)
|
28
|
+
super("Invalid aud claim. Expected: #{expected_audience}, but received: #{actual_audience || '<none>'}")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class InvalidEventsError < DecodeError; end
|
33
|
+
class TokenExpiredError < DecodeError; end
|
34
|
+
|
35
|
+
class InvalidNonceError < DecodeError
|
36
|
+
def message
|
37
|
+
'Nonce claim is not allowed in Logout Token'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class IssuerNotConfiguredError < StandardError
|
42
|
+
def message
|
43
|
+
'Issuer must be set in OpenidBackchannelLogout configuration'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class AudienceNotConfiguredError < StandardError
|
48
|
+
def message
|
49
|
+
'Audience (Client ID) must be set in OpenidBackchannelLogout configuration'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class NoBlockProvidedError < StandardError; end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'error'
|
4
|
+
require_relative 'token_validator'
|
5
|
+
|
6
|
+
module OpenidBackchannelLogout
|
7
|
+
class Executor
|
8
|
+
def initialize
|
9
|
+
@expected_issuer = OpenidBackchannelLogout.configuration.issuer
|
10
|
+
@expected_audience = OpenidBackchannelLogout.configuration.audience
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(request)
|
14
|
+
logout_token = extract_token(request)
|
15
|
+
raise Error::MissingLogoutTokenError unless logout_token
|
16
|
+
|
17
|
+
jwks_uri = fetch_jwks_uri
|
18
|
+
|
19
|
+
validator = TokenValidator.new(
|
20
|
+
logout_token,
|
21
|
+
jwks_uri,
|
22
|
+
@expected_issuer,
|
23
|
+
@expected_audience
|
24
|
+
)
|
25
|
+
|
26
|
+
validator.valid!
|
27
|
+
|
28
|
+
payload = validator.decoded_token.first
|
29
|
+
sub = payload['sub']
|
30
|
+
sid = payload['sid']
|
31
|
+
|
32
|
+
raise Error::NoBlockProvidedError, 'No block provided for handling sub and sid' unless block_given?
|
33
|
+
|
34
|
+
yield(sub, sid)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def extract_token(request)
|
40
|
+
request.params[:logout_token]
|
41
|
+
end
|
42
|
+
|
43
|
+
def fetch_jwks_uri
|
44
|
+
discovery_url = "#{@expected_issuer}/.well-known/openid-configuration"
|
45
|
+
response = Net::HTTP.get(URI(discovery_url))
|
46
|
+
discovery_data = JSON.parse(response)
|
47
|
+
|
48
|
+
discovery_data['jwks_uri'] || raise(Error::DecodeError, 'JWKS URI not found in discovery document')
|
49
|
+
rescue JSON::ParserError
|
50
|
+
raise Error::DecodeError, 'Failed to parse OpenID Connect discovery document'
|
51
|
+
rescue StandardError => e
|
52
|
+
raise Error::DecodeError, "Failed to fetch JWKS URI: #{e.message}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'jwt'
|
4
|
+
require 'net/http'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
module OpenidBackchannelLogout
|
8
|
+
class TokenValidator
|
9
|
+
attr_reader :decoded_token
|
10
|
+
|
11
|
+
EVENT_KEY = 'http://schemas.openid.net/event/backchannel-logout'
|
12
|
+
|
13
|
+
def initialize(jwt_token, jwks_uri, expected_issuer, expected_audience, options = {})
|
14
|
+
@jwt_token = jwt_token
|
15
|
+
@jwks_uri = jwks_uri
|
16
|
+
@expected_issuer = expected_issuer
|
17
|
+
@expected_audience = expected_audience
|
18
|
+
|
19
|
+
# TODO: Implement validation for claims that are not required by the spec
|
20
|
+
# https://openid.net/specs/openid-connect-backchannel-1_0.html
|
21
|
+
@options = options
|
22
|
+
end
|
23
|
+
|
24
|
+
def valid!
|
25
|
+
decode_and_validate_token
|
26
|
+
validate_claims
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def decode_and_validate_token
|
32
|
+
header = JWT.decode(@jwt_token, nil, false).last
|
33
|
+
raise Error::InvalidAlgorithmError if header['alg'] == 'none'
|
34
|
+
|
35
|
+
@decoded_token = JWT.decode(@jwt_token, nil, true,
|
36
|
+
algorithms: [header['alg']],
|
37
|
+
jwks: jwks_keys)
|
38
|
+
end
|
39
|
+
|
40
|
+
def jwks_keys
|
41
|
+
@jwks_keys ||= begin
|
42
|
+
response = Net::HTTP.get(URI(@jwks_uri))
|
43
|
+
JSON.parse(response)['keys']
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def validate_claims
|
48
|
+
payload = @decoded_token.first
|
49
|
+
|
50
|
+
validate_required_claims(payload)
|
51
|
+
end
|
52
|
+
|
53
|
+
def validate_required_claims(payload)
|
54
|
+
validate_iss(payload['iss'])
|
55
|
+
validate_aud(payload['aud'])
|
56
|
+
validate_timestamps(payload['iat'], payload['exp'])
|
57
|
+
validate_events(payload['events'])
|
58
|
+
validate_subject_or_session(payload)
|
59
|
+
validate_no_nonce(payload)
|
60
|
+
end
|
61
|
+
|
62
|
+
def validate_iss(iss)
|
63
|
+
raise Error::InvalidIssuerError.new(@expected_issuer, iss) unless iss == @expected_issuer
|
64
|
+
end
|
65
|
+
|
66
|
+
def validate_aud(aud)
|
67
|
+
return if Array(aud).include?(@expected_audience)
|
68
|
+
|
69
|
+
raise Error::InvalidAudError.new(@expected_audience, Array(aud))
|
70
|
+
end
|
71
|
+
|
72
|
+
def validate_timestamps(iat, exp)
|
73
|
+
raise Error::MissingRequiredClaimError, :iat unless iat
|
74
|
+
raise Error::MissingRequiredClaimError, :exp unless exp
|
75
|
+
|
76
|
+
raise Error::TokenExpiredError if Time.now.to_i > exp
|
77
|
+
end
|
78
|
+
|
79
|
+
def validate_events(events)
|
80
|
+
raise Error::MissingRequiredClaimError, :events unless events
|
81
|
+
raise Error::InvalidEventsError unless events.key?(EVENT_KEY)
|
82
|
+
end
|
83
|
+
|
84
|
+
def validate_subject_or_session(payload)
|
85
|
+
raise Error::MissingSubOrSidClaimError unless payload['sub'] || payload['sid']
|
86
|
+
end
|
87
|
+
|
88
|
+
def validate_no_nonce(payload)
|
89
|
+
raise Error::InvalidNonceError if payload.key?('nonce')
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'openid_backchannel_logout/configuration'
|
4
|
+
require 'openid_backchannel_logout/executor'
|
5
|
+
|
6
|
+
module OpenidBackchannelLogout
|
7
|
+
class << self
|
8
|
+
attr_accessor :configuration
|
9
|
+
|
10
|
+
def configure
|
11
|
+
self.configuration ||= Configuration.new
|
12
|
+
yield(configuration)
|
13
|
+
|
14
|
+
configuration.validate!
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: openid_backchannel_logout
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nguyen Ngoc Hai
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-12-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: jwt
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: A Ruby implementation of OpenID Connect Backchannel Logout, as defined
|
28
|
+
in the OpenID Connect Back-Channel Logout 1.0 specification.
|
29
|
+
email:
|
30
|
+
- ngochai220998@gmail.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- CODE_OF_CONDUCT.md
|
36
|
+
- LICENSE.txt
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- lib/generators/openid_backchannel_logout/install/install_generator.rb
|
40
|
+
- lib/generators/openid_backchannel_logout/templates/backchannel_logouts_controller.rb
|
41
|
+
- lib/generators/openid_backchannel_logout/templates/initializer.rb
|
42
|
+
- lib/openid_backchannel_logout.rb
|
43
|
+
- lib/openid_backchannel_logout/configuration.rb
|
44
|
+
- lib/openid_backchannel_logout/error.rb
|
45
|
+
- lib/openid_backchannel_logout/executor.rb
|
46
|
+
- lib/openid_backchannel_logout/token_validator.rb
|
47
|
+
- lib/openid_backchannel_logout/version.rb
|
48
|
+
- sig/openid_backchannel_logout.rbs
|
49
|
+
homepage: https://github.com/NgocHai220998/openid_backchannel_logout.git
|
50
|
+
licenses:
|
51
|
+
- MIT
|
52
|
+
metadata:
|
53
|
+
homepage_uri: https://github.com/NgocHai220998/openid_backchannel_logout.git
|
54
|
+
source_code_uri: https://github.com/NgocHai220998/openid_backchannel_logout.git
|
55
|
+
changelog_uri: https://github.com/NgocHai220998/openid_backchannel_logout.git
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 3.0.0
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubygems_version: 3.5.22
|
72
|
+
signing_key:
|
73
|
+
specification_version: 4
|
74
|
+
summary: A Ruby implementation of OpenID Connect Backchannel Logout
|
75
|
+
test_files: []
|