omniauth-ssoprovider 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/.github/workflows/ci.yml +48 -0
- data/.rspec_status +11 -0
- data/.rubocop.yml +47 -0
- data/CHANGELOG.md +49 -0
- data/CONTRIBUTING.md +72 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +89 -0
- data/LICENSE.txt +21 -0
- data/README.md +95 -0
- data/Rakefile +21 -0
- data/lib/omniauth/ssoprovider/version.rb +7 -0
- data/lib/omniauth/ssoprovider.rb +14 -0
- data/lib/omniauth/strategies/ssoprovider.rb +65 -0
- metadata +159 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 9b057e5924990828f4c0143a620276511ede35d8a589b4eb48f41d6aeb95af88
|
|
4
|
+
data.tar.gz: 19d2eecb3f54e842a66b71794820a45b63da82ea35d646b8f9ccd7f938ac1a6e
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 5f78b9a949e4da4ca7a0eea01e781239f9a389738504e925befd69911b8c207bbdb9fd5b99d122a42a363abe4b6995d7107fb1d3378694fc23291d7945fb0022
|
|
7
|
+
data.tar.gz: d17ce1e3170be06069d72346fd6512b691967d1086e93f4b359b88f11e5b34a0fa1f01c4202e42c24fbe8d40acdec1aded9180bf0a6ac523dba422a64194ba9d
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
name: OmniAuth Strategy CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ "main" ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ "main" ]
|
|
8
|
+
# Allows manual runs
|
|
9
|
+
workflow_dispatch:
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
build-and-test:
|
|
13
|
+
# Use standard Ubuntu runner
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
|
|
16
|
+
# Test against multiple common Ruby versions
|
|
17
|
+
strategy:
|
|
18
|
+
matrix:
|
|
19
|
+
ruby-version: [ '3.1', '3.2', '3.3' ]
|
|
20
|
+
|
|
21
|
+
steps:
|
|
22
|
+
- name: Checkout Repository
|
|
23
|
+
uses: actions/checkout@v4
|
|
24
|
+
|
|
25
|
+
- name: Set up Ruby ${{ matrix.ruby-version }}
|
|
26
|
+
uses: ruby/setup-ruby@v1
|
|
27
|
+
with:
|
|
28
|
+
ruby-version: ${{ matrix.ruby-version }}
|
|
29
|
+
# Cache gems to speed up subsequent runs
|
|
30
|
+
bundler-cache: true
|
|
31
|
+
|
|
32
|
+
- name: Install Dependencies
|
|
33
|
+
# Uses bundler-cache above, so we just check for errors
|
|
34
|
+
run: bundle check || bundle install
|
|
35
|
+
|
|
36
|
+
- name: Run Tests (RSpec/Minitest)
|
|
37
|
+
# Assuming your OmniAuth strategy uses RSpec or Minitest, typically run via Rake
|
|
38
|
+
run: bundle exec rake spec
|
|
39
|
+
# If you use a different command, replace 'bundle exec rake spec' with it (e.g., 'bundle exec rspec')
|
|
40
|
+
env:
|
|
41
|
+
# Define necessary environment variables for test execution, like mock API credentials
|
|
42
|
+
# Replace these placeholders with actual test variables if your tests need them.
|
|
43
|
+
OMNIAUTH_TEST_CLIENT_ID: ${{ secrets.OMNIAUTH_TEST_CLIENT_ID }}
|
|
44
|
+
OMNIAUTH_TEST_CLIENT_SECRET: ${{ secrets.OMNIAUTH_TEST_CLIENT_SECRET }}
|
|
45
|
+
|
|
46
|
+
- name: Check Gem Specification
|
|
47
|
+
# Ensures the .gemspec file is valid and the gem can be packaged
|
|
48
|
+
run: gem build *.gemspec
|
data/.rspec_status
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
example_id | status | run_time |
|
|
2
|
+
----------------------------------------------------- | ------ | --------------- |
|
|
3
|
+
./spec/omniauth/strategies/ssoprovider_spec.rb[1:1:1] | passed | 0.00046 seconds |
|
|
4
|
+
./spec/omniauth/strategies/ssoprovider_spec.rb[1:1:2] | passed | 0.00013 seconds |
|
|
5
|
+
./spec/omniauth/strategies/ssoprovider_spec.rb[1:1:3] | passed | 0.00013 seconds |
|
|
6
|
+
./spec/omniauth/strategies/ssoprovider_spec.rb[1:2:1] | passed | 0.00454 seconds |
|
|
7
|
+
./spec/omniauth/strategies/ssoprovider_spec.rb[1:2:2] | passed | 0.00071 seconds |
|
|
8
|
+
./spec/omniauth/strategies/ssoprovider_spec.rb[1:3:1] | passed | 0.00084 seconds |
|
|
9
|
+
./spec/omniauth/strategies/ssoprovider_spec.rb[1:3:2] | passed | 0.00075 seconds |
|
|
10
|
+
./spec/omniauth/strategies/ssoprovider_spec.rb[1:3:3] | passed | 0.00076 seconds |
|
|
11
|
+
./spec/omniauth/strategies/ssoprovider_spec.rb[1:3:4] | passed | 0.00085 seconds |
|
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require:
|
|
4
|
+
- rubocop-rspec
|
|
5
|
+
|
|
6
|
+
AllCops:
|
|
7
|
+
TargetRubyVersion: 2.6
|
|
8
|
+
NewCops: enable
|
|
9
|
+
Exclude:
|
|
10
|
+
- 'bin/**/*'
|
|
11
|
+
- 'db/**/*'
|
|
12
|
+
- 'vendor/**/*'
|
|
13
|
+
- 'spec/fixtures/**/*'
|
|
14
|
+
- 'tmp/**/*'
|
|
15
|
+
- 'Rakefile' # Exclude if you want less strict Rakefile checks
|
|
16
|
+
|
|
17
|
+
# --- Common Cops ---
|
|
18
|
+
|
|
19
|
+
# Enforce the use of frozen_string_literal comment
|
|
20
|
+
Style/FrozenStringLiteralComment:
|
|
21
|
+
Enabled: true
|
|
22
|
+
|
|
23
|
+
# Use `foo.freeze` instead of `FOO = 'bar'.freeze`
|
|
24
|
+
Style/MutableConstant:
|
|
25
|
+
Enabled: false
|
|
26
|
+
|
|
27
|
+
# Max line length for consistency
|
|
28
|
+
Layout/LineLength:
|
|
29
|
+
Max: 120
|
|
30
|
+
|
|
31
|
+
# --- RSpec Cops ---
|
|
32
|
+
|
|
33
|
+
# Relax block length rules for RSpec `describe` blocks
|
|
34
|
+
RSpec/ExampleGroup:
|
|
35
|
+
Max: 6
|
|
36
|
+
|
|
37
|
+
RSpec/MultipleExpectations:
|
|
38
|
+
Max: 3
|
|
39
|
+
|
|
40
|
+
# Allow using `is_expected.to` when appropriate
|
|
41
|
+
RSpec/MessageChain:
|
|
42
|
+
Enabled: false
|
|
43
|
+
|
|
44
|
+
# Allow stubbing methods like `env` that are difficult to inject
|
|
45
|
+
RSpec/UnspecifiedKeywordArgument:
|
|
46
|
+
Enabled: false
|
|
47
|
+
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
Changelog for omniauth-ssoprovider
|
|
2
|
+
==================================
|
|
3
|
+
|
|
4
|
+
All notable changes to this project will be documented in this file.
|
|
5
|
+
|
|
6
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
\[Unreleased\]
|
|
9
|
+
--------------
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
* Placeholder for new features currently under development.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
* Placeholder for modifications to existing functionality.
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Fixed
|
|
22
|
+
|
|
23
|
+
* Placeholder for resolved bugs or issues.
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
\[0.1.0\] - 2025-10-23
|
|
27
|
+
----------------------
|
|
28
|
+
|
|
29
|
+
### Added
|
|
30
|
+
|
|
31
|
+
* **Initial proof-of-concept release** of the omniauth-ssoprovider gem.
|
|
32
|
+
|
|
33
|
+
* Core implementation of the OmniAuth strategy for SSO Provider.
|
|
34
|
+
|
|
35
|
+
* Support for the **OAuth 2.0 Authorization Code Flow** (handling the request and callback phases).
|
|
36
|
+
|
|
37
|
+
* Basic configuration options for client\_id, client\_secret, and provider URLs.
|
|
38
|
+
|
|
39
|
+
* Initial extraction of the **UID**, info hash (name, email), and credentials (access token).
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
### Changed
|
|
43
|
+
|
|
44
|
+
* None (First release)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
### Fixed
|
|
48
|
+
|
|
49
|
+
* None (First release)
|
data/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
Contributing to omniauth-ssoprovider
|
|
2
|
+
====================================
|
|
3
|
+
|
|
4
|
+
We welcome contributions to the omniauth-ssoprovider gem! Whether you're fixing bugs, adding new features, improving documentation, or just refining code quality, your help is appreciated.
|
|
5
|
+
|
|
6
|
+
Please follow these guidelines to make the contribution process smooth and effective for everyone.
|
|
7
|
+
|
|
8
|
+
🚀 How to Contribute
|
|
9
|
+
--------------------
|
|
10
|
+
|
|
11
|
+
The contribution flow generally follows the **Fork and Pull Request** model.
|
|
12
|
+
|
|
13
|
+
1. **Fork** the repository on GitHub.
|
|
14
|
+
|
|
15
|
+
2. git clone git@github.com:/omniauth-ssoprovider.gitcd omniauth-ssoprovider
|
|
16
|
+
|
|
17
|
+
3. git checkout -b your-feature-branch
|
|
18
|
+
|
|
19
|
+
4. **Make your changes.** Be sure to follow the **Coding Standards** below.
|
|
20
|
+
|
|
21
|
+
5. **Write Tests.** All new features or bug fixes must be accompanied by corresponding tests. The project uses **RSpec**.
|
|
22
|
+
|
|
23
|
+
6. bundle installbundle exec rspec
|
|
24
|
+
|
|
25
|
+
7. git commit -m "feat: Add support for custom callback path"
|
|
26
|
+
|
|
27
|
+
8. git push origin your-feature-branch
|
|
28
|
+
|
|
29
|
+
9. **Open a Pull Request (PR)** against the main branch of the original omniauth-ssoprovider repository. Provide a clear description of your changes and why they are needed.
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
🛠 Coding Standards
|
|
33
|
+
-------------------
|
|
34
|
+
|
|
35
|
+
To maintain consistency and readability across the project, please adhere to these standards:
|
|
36
|
+
|
|
37
|
+
### Ruby & Gem Specifics
|
|
38
|
+
|
|
39
|
+
* **Ruby Style:** Follow standard Ruby conventions and use the [**RuboCop**](https://docs.rubocop.org/) configuration provided in the repository. Running tests will usually check this automatically.
|
|
40
|
+
|
|
41
|
+
* **OmniAuth Conventions:** Ensure the strategy adheres to the established OmniAuth pattern, particularly how the uid, info hash, and credentials are formatted and returned.
|
|
42
|
+
|
|
43
|
+
* **Dependencies:** Only introduce new dependencies if absolutely necessary. If you do, update the \*.gemspec file and ensure the dependencies are well-maintained.
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
### Documentation
|
|
47
|
+
|
|
48
|
+
* **Inline Comments:** Use comments sparingly to explain non-obvious code.
|
|
49
|
+
|
|
50
|
+
* **Documentation Updates:** If you change any public API or configuration options, please update the **README.md** and the **CHANGELOG.md** files in your pull request.
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
🚨 Reporting Bugs
|
|
54
|
+
-----------------
|
|
55
|
+
|
|
56
|
+
If you find a bug, please check the existing \[Issues\] section to see if it has already been reported. If not, open a new issue and include the following details:
|
|
57
|
+
|
|
58
|
+
1. **Version of the gem** you are using (e.g., 0.1.0).
|
|
59
|
+
|
|
60
|
+
2. **Steps to reproduce** the bug.
|
|
61
|
+
|
|
62
|
+
3. **Expected behavior** vs. **actual behavior**.
|
|
63
|
+
|
|
64
|
+
4. Any relevant **stack traces** or error messages.
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
✨ Suggesting Enhancements
|
|
68
|
+
-------------------------
|
|
69
|
+
|
|
70
|
+
We love new ideas! If you have a suggestion for a new feature or an improvement to existing functionality, please open an issue first to discuss the idea before starting work. This helps ensure that the feature aligns with the project's goals and avoids duplicate efforts.
|
|
71
|
+
|
|
72
|
+
Thank you for your interest in making omniauth-ssoprovider better!
|
data/Gemfile
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
source "https://rubygems.org"
|
|
4
|
+
|
|
5
|
+
# Runtime dependencies (defined in gemspec)
|
|
6
|
+
gemspec
|
|
7
|
+
|
|
8
|
+
# Development dependencies (for testing and building)
|
|
9
|
+
group :development, :test do
|
|
10
|
+
gem "rake", "~> 13.0"
|
|
11
|
+
gem "rspec", "~> 3.12"
|
|
12
|
+
gem "webmock", "~> 3.18"
|
|
13
|
+
# This gem contains the necessary testing helpers
|
|
14
|
+
gem "omniauth-test", "~> 0.0.11"
|
|
15
|
+
end
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
omniauth-ssoprovider (0.1.0)
|
|
5
|
+
omniauth (~> 2.1)
|
|
6
|
+
omniauth-oauth2 (~> 1.8)
|
|
7
|
+
|
|
8
|
+
GEM
|
|
9
|
+
remote: https://rubygems.org/
|
|
10
|
+
specs:
|
|
11
|
+
addressable (2.8.7)
|
|
12
|
+
public_suffix (>= 2.0.2, < 7.0)
|
|
13
|
+
base64 (0.3.0)
|
|
14
|
+
bigdecimal (3.3.1)
|
|
15
|
+
crack (1.0.1)
|
|
16
|
+
bigdecimal
|
|
17
|
+
rexml
|
|
18
|
+
diff-lcs (1.6.2)
|
|
19
|
+
faraday (2.8.1)
|
|
20
|
+
base64
|
|
21
|
+
faraday-net_http (>= 2.0, < 3.1)
|
|
22
|
+
ruby2_keywords (>= 0.0.4)
|
|
23
|
+
faraday-net_http (3.0.2)
|
|
24
|
+
hashdiff (1.2.1)
|
|
25
|
+
hashie (5.0.0)
|
|
26
|
+
jwt (3.1.2)
|
|
27
|
+
base64
|
|
28
|
+
logger (1.7.0)
|
|
29
|
+
multi_xml (0.6.0)
|
|
30
|
+
oauth2 (2.0.17)
|
|
31
|
+
faraday (>= 0.17.3, < 4.0)
|
|
32
|
+
jwt (>= 1.0, < 4.0)
|
|
33
|
+
logger (~> 1.2)
|
|
34
|
+
multi_xml (~> 0.5)
|
|
35
|
+
rack (>= 1.2, < 4)
|
|
36
|
+
snaky_hash (~> 2.0, >= 2.0.3)
|
|
37
|
+
version_gem (~> 1.1, >= 1.1.9)
|
|
38
|
+
omniauth (2.1.4)
|
|
39
|
+
hashie (>= 3.4.6)
|
|
40
|
+
logger
|
|
41
|
+
rack (>= 2.2.3)
|
|
42
|
+
rack-protection
|
|
43
|
+
omniauth-oauth2 (1.8.0)
|
|
44
|
+
oauth2 (>= 1.4, < 3)
|
|
45
|
+
omniauth (~> 2.0)
|
|
46
|
+
omniauth-test (0.0.11)
|
|
47
|
+
omniauth-oauth2 (~> 1.2)
|
|
48
|
+
public_suffix (5.1.1)
|
|
49
|
+
rack (3.2.3)
|
|
50
|
+
rack-protection (3.0.6)
|
|
51
|
+
rack
|
|
52
|
+
rake (13.3.0)
|
|
53
|
+
rexml (3.4.4)
|
|
54
|
+
rspec (3.13.2)
|
|
55
|
+
rspec-core (~> 3.13.0)
|
|
56
|
+
rspec-expectations (~> 3.13.0)
|
|
57
|
+
rspec-mocks (~> 3.13.0)
|
|
58
|
+
rspec-core (3.13.6)
|
|
59
|
+
rspec-support (~> 3.13.0)
|
|
60
|
+
rspec-expectations (3.13.5)
|
|
61
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
62
|
+
rspec-support (~> 3.13.0)
|
|
63
|
+
rspec-mocks (3.13.6)
|
|
64
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
65
|
+
rspec-support (~> 3.13.0)
|
|
66
|
+
rspec-support (3.13.6)
|
|
67
|
+
ruby2_keywords (0.0.5)
|
|
68
|
+
snaky_hash (2.0.3)
|
|
69
|
+
hashie (>= 0.1.0, < 6)
|
|
70
|
+
version_gem (>= 1.1.8, < 3)
|
|
71
|
+
version_gem (1.1.9)
|
|
72
|
+
webmock (3.25.1)
|
|
73
|
+
addressable (>= 2.8.0)
|
|
74
|
+
crack (>= 0.3.2)
|
|
75
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
|
76
|
+
|
|
77
|
+
PLATFORMS
|
|
78
|
+
x86_64-linux
|
|
79
|
+
|
|
80
|
+
DEPENDENCIES
|
|
81
|
+
bundler (~> 2.0)
|
|
82
|
+
omniauth-ssoprovider!
|
|
83
|
+
omniauth-test (~> 0.0.11)
|
|
84
|
+
rake (~> 13.0)
|
|
85
|
+
rspec (~> 3.12)
|
|
86
|
+
webmock (~> 3.18)
|
|
87
|
+
|
|
88
|
+
BUNDLED WITH
|
|
89
|
+
2.4.22
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Daniele Frisanco
|
|
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,95 @@
|
|
|
1
|
+
OmniAuth SSOProvider Strategy
|
|
2
|
+
=============================
|
|
3
|
+
|
|
4
|
+
A generic, customizable OmniAuth strategy for integrating with any OAuth 2.0 Single Sign-On (SSO) provider, typically used for custom or internal identity management systems.
|
|
5
|
+
|
|
6
|
+
This strategy is built on top of `omniauth-oauth2` and provides a mechanism to fetch user details and, critically, retrieve the raw **Access Token (JWT)** for use in downstream API calls.
|
|
7
|
+
|
|
8
|
+
🚀 Installation
|
|
9
|
+
---------------
|
|
10
|
+
|
|
11
|
+
Add this gem and its dependency, `omniauth-oauth2`, to your application's `Gemfile`:
|
|
12
|
+
|
|
13
|
+
```ruby
|
|
14
|
+
gem 'omniauth-oauth2'
|
|
15
|
+
gem 'omniauth-ssoprovider', require: 'omniauth/strategies/ssoprovider'
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Then run `bundle install`.
|
|
19
|
+
|
|
20
|
+
🛠 Usage and Configuration
|
|
21
|
+
--------------------------
|
|
22
|
+
|
|
23
|
+
The strategy is configured like any standard OmniAuth OAuth2 strategy, but it requires you to set the specific URLs for your SSO provider.
|
|
24
|
+
|
|
25
|
+
### Rails Setup
|
|
26
|
+
|
|
27
|
+
Create an initializer file, typically located at `config/initializers/omniauth.rb`:
|
|
28
|
+
|
|
29
|
+
```ruby
|
|
30
|
+
# config/initializers/omniauth.rb
|
|
31
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
|
32
|
+
provider :ssoprovider, ENV['SSO_CLIENT_ID'], ENV['SSO_CLIENT_SECRET'],
|
|
33
|
+
# Client Options - Override the defaults for your specific SSO provider
|
|
34
|
+
client_options: {
|
|
35
|
+
site: '[https://api.your-sso-host.com](https://api.your-sso-host.com)', # Base URL of the SSO provide (REQUIRED)
|
|
36
|
+
authorize_url: '/oauth/authorize', # Authorization endpoint path (Default: '/oauth/authorize')
|
|
37
|
+
token_url: '/oauth/token' # Token exchange endpoint path (Default: '/oauth/token')
|
|
38
|
+
},
|
|
39
|
+
# Strategy Options - Specific to fetching user details
|
|
40
|
+
user_info_url: '/api/v1/userinfo', # Endpoint to fetch the user's details post-token exchange (REQUIRED)
|
|
41
|
+
scope: 'read_profile read_email' # Optional: Define the OAuth scopes
|
|
42
|
+
end
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Required Environment Variables
|
|
46
|
+
|
|
47
|
+
For security, ensure you set your credentials using environment variables:
|
|
48
|
+
|
|
49
|
+
| Variable | Description |
|
|
50
|
+
| - | - |
|
|
51
|
+
| `SSO_CLIENT_ID` | The public identifier for your application, provided by the SSO service. |
|
|
52
|
+
| `SSO_CLIENT_SECRET` | The secret key for your application, provided by the SSO service. |
|
|
53
|
+
|
|
54
|
+
⚙️ Strategy Configuration Options
|
|
55
|
+
---------------------------------
|
|
56
|
+
|
|
57
|
+
The following options can be customized when configuring the provider:
|
|
58
|
+
|
|
59
|
+
| Option | Default Value | Description |
|
|
60
|
+
| - | - | - |
|
|
61
|
+
| `site` | `https://sso.example.com` | The **base URL** of your SSO service (e.g., `https://auth.company.com`). |
|
|
62
|
+
| `authorize_url` | `/oauth/authorize` | Path to the authorization code endpoint. |
|
|
63
|
+
| `token_url` | `/oauth/token` | Path to the token exchange endpoint. |
|
|
64
|
+
| `user_info_url` | `/api/v1/userinfo` | **Crucial:** The API endpoint used to fetch the user's data after the token is obtained. |
|
|
65
|
+
| `scope` | (none) | Optional OAuth scope string (e.g., `'openid email profile'`). |
|
|
66
|
+
|
|
67
|
+
🔑 The Authentication Hash (Auth Hash)
|
|
68
|
+
--------------------------------------
|
|
69
|
+
|
|
70
|
+
Upon a successful callback, OmniAuth stores the user details in the `env['omniauth.auth']` hash.
|
|
71
|
+
|
|
72
|
+
This strategy populates the hash as follows:
|
|
73
|
+
|
|
74
|
+
| Section | Key | Value | Description |
|
|
75
|
+
| - | - | - | - |
|
|
76
|
+
| `uid` | `auth['uid']` | `raw_info['id']` | The unique identifier of the user (extracted from the raw info endpoint). |
|
|
77
|
+
| `info` | `auth['info']['name']` | `raw_info['name']` | The user's full name. |
|
|
78
|
+
| `info` | `auth['info']['email']` | `raw_info['email']` | The user's email address. |
|
|
79
|
+
| `extra` | `auth['extra']['raw_info']` | `{...}` | The full JSON response from the `user_info_url` endpoint. |
|
|
80
|
+
| `extra` | `auth['extra']['access_token']` | `'<JWT String>'` | **The raw access token string.** This is the token your application will use to make subsequent authenticated requests to your SSO API. |
|
|
81
|
+
|
|
82
|
+
### Accessing the Token
|
|
83
|
+
|
|
84
|
+
The primary feature of this strategy is securely exposing the raw JWT string for subsequent API usage. You can access it in your callback controller like this:
|
|
85
|
+
|
|
86
|
+
```ruby
|
|
87
|
+
def omniauth_callback
|
|
88
|
+
auth_hash = request.env['omniauth.auth']
|
|
89
|
+
# The token required for API calls
|
|
90
|
+
access_token = auth_hash['extra']['access_token']
|
|
91
|
+
# The unique user ID
|
|
92
|
+
user_id = auth_hash['uid']
|
|
93
|
+
# ... proceed with sign-in logic
|
|
94
|
+
end
|
|
95
|
+
```
|
data/Rakefile
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "bundler/gem_tasks"
|
|
4
|
+
require "rake/testtask"
|
|
5
|
+
require "rspec/core/rake_task"
|
|
6
|
+
|
|
7
|
+
# --- Testing Tasks ---
|
|
8
|
+
|
|
9
|
+
# Define the RSpec task
|
|
10
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
11
|
+
|
|
12
|
+
# Define the default task to run tests
|
|
13
|
+
task default: :spec
|
|
14
|
+
|
|
15
|
+
# --- Build and Install Tasks ---
|
|
16
|
+
|
|
17
|
+
# Rake task to install the gem locally (for testing the packaging)
|
|
18
|
+
desc "Install the gem locally"
|
|
19
|
+
task :install do
|
|
20
|
+
system "gem install pkg/*.gem"
|
|
21
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Load the version file
|
|
4
|
+
require_relative "ssoprovider/version"
|
|
5
|
+
# Load the core strategy class
|
|
6
|
+
require_relative "strategies/ssoprovider"
|
|
7
|
+
|
|
8
|
+
# Add the strategy to OmniAuth's list of available strategies
|
|
9
|
+
module OmniAuth
|
|
10
|
+
def self.ssoprovider_strategy
|
|
11
|
+
# Ensure the strategy is registered under the expected name in OmniAuth
|
|
12
|
+
Strategies::SSOProvider
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'omniauth-oauth2'
|
|
4
|
+
|
|
5
|
+
module OmniAuth
|
|
6
|
+
module Strategies
|
|
7
|
+
# OmniAuth Strategy for a generic SSO Provider using OAuth 2.0.
|
|
8
|
+
# This class handles the standard OAuth flow:
|
|
9
|
+
# 1. Redirect to the authorization endpoint.
|
|
10
|
+
# 2. Exchange the authorization code for an access token.
|
|
11
|
+
# 3. Fetch user information (the "info" hash) using the access token.
|
|
12
|
+
class SSOProvider < OmniAuth::Strategies::OAuth2
|
|
13
|
+
# The default strategy name for usage (e.g., /auth/sso_provider)
|
|
14
|
+
option :name, :ssoprovider
|
|
15
|
+
|
|
16
|
+
# Options for the OAuth 2.0 client
|
|
17
|
+
# The URLs must be configured by the user during initialization
|
|
18
|
+
option :client_options, {
|
|
19
|
+
site: 'https://sso.example.com', # Base URL of the SSO Provider
|
|
20
|
+
authorize_url: '/oauth/authorize', # Path for authorization code request
|
|
21
|
+
token_url: '/oauth/token' # Path for token exchange
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
# Options to customize the 'info' hash extraction from the raw user data
|
|
25
|
+
option :user_info_url, '/api/v1/userinfo' # Default endpoint to fetch user data
|
|
26
|
+
|
|
27
|
+
# --- Override required OmniAuth methods ---
|
|
28
|
+
|
|
29
|
+
# The 'uid' is the unique identifier for the user in the SSO system.
|
|
30
|
+
# OmniAuth requires this method to be implemented.
|
|
31
|
+
uid { raw_info['id'].to_s }
|
|
32
|
+
|
|
33
|
+
# The 'info' hash provides normalized user data (name, email, etc.).
|
|
34
|
+
# OmniAuth requires this method to be implemented.
|
|
35
|
+
info do
|
|
36
|
+
{
|
|
37
|
+
name: raw_info['name'],
|
|
38
|
+
email: raw_info['email'],
|
|
39
|
+
# Add more claims here (e.g., 'nickname', 'first_name', 'last_name')
|
|
40
|
+
}
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# The 'extra' hash is used to pass raw provider data, including the JWT payload.
|
|
44
|
+
# This is crucial for passing the access token (JWT) to the consuming application.
|
|
45
|
+
extra do
|
|
46
|
+
{
|
|
47
|
+
'raw_info' => raw_info,
|
|
48
|
+
# The access token is the verified JWT you'll use in the other gem
|
|
49
|
+
'access_token' => access_token.token
|
|
50
|
+
}
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# --- Custom method to fetch user information ---
|
|
54
|
+
|
|
55
|
+
# This method is called after the token exchange is successful.
|
|
56
|
+
# It uses the access token to call the SSO's user info API.
|
|
57
|
+
def raw_info
|
|
58
|
+
@raw_info ||= access_token.get(options.user_info_url).parsed || {}
|
|
59
|
+
rescue ::OAuth2::Error => e
|
|
60
|
+
# Raise an error if fetching user info fails (e.g., expired token, 401 response)
|
|
61
|
+
raise e
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: omniauth-ssoprovider
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Daniele Frisanco
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2025-10-22 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: '2.1'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '2.1'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: omniauth-oauth2
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '1.8'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1.8'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: bundler
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '2.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '2.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rake
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '13.0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '13.0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rspec
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '3.10'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '3.10'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: webmock
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '3.0'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '3.0'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: omniauth-test
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - "~>"
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: 0.0.11
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - "~>"
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: 0.0.11
|
|
111
|
+
description: Simplifies the integration of a custom, standards-compliant SSO service
|
|
112
|
+
into any Rack-based application (like Rails or Sinatra) using the OmniAuth framework.
|
|
113
|
+
email:
|
|
114
|
+
- daniele.frisanco@gmail.com
|
|
115
|
+
executables: []
|
|
116
|
+
extensions: []
|
|
117
|
+
extra_rdoc_files: []
|
|
118
|
+
files:
|
|
119
|
+
- ".github/workflows/ci.yml"
|
|
120
|
+
- ".rspec_status"
|
|
121
|
+
- ".rubocop.yml"
|
|
122
|
+
- CHANGELOG.md
|
|
123
|
+
- CONTRIBUTING.md
|
|
124
|
+
- Gemfile
|
|
125
|
+
- Gemfile.lock
|
|
126
|
+
- LICENSE.txt
|
|
127
|
+
- README.md
|
|
128
|
+
- Rakefile
|
|
129
|
+
- lib/omniauth/ssoprovider.rb
|
|
130
|
+
- lib/omniauth/ssoprovider/version.rb
|
|
131
|
+
- lib/omniauth/strategies/ssoprovider.rb
|
|
132
|
+
homepage: https://github.com/danielefrisanco/omniauth-ssoprovider
|
|
133
|
+
licenses:
|
|
134
|
+
- MIT
|
|
135
|
+
metadata:
|
|
136
|
+
homepage_uri: https://github.com/danielefrisanco/omniauth-ssoprovider
|
|
137
|
+
source_code_uri: https://github.com/danielefrisanco/omniauth-ssoprovider
|
|
138
|
+
changelog_uri: https://github.com/danielefrisanco/omniauth-ssoprovider/CHANGELOG.md
|
|
139
|
+
issue_tracker_uri: https://github.com/danielefrisanco/omniauth-ssoprovider/issues
|
|
140
|
+
post_install_message:
|
|
141
|
+
rdoc_options: []
|
|
142
|
+
require_paths:
|
|
143
|
+
- lib
|
|
144
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
145
|
+
requirements:
|
|
146
|
+
- - "~>"
|
|
147
|
+
- !ruby/object:Gem::Version
|
|
148
|
+
version: '2.6'
|
|
149
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
|
+
requirements:
|
|
151
|
+
- - ">="
|
|
152
|
+
- !ruby/object:Gem::Version
|
|
153
|
+
version: '0'
|
|
154
|
+
requirements: []
|
|
155
|
+
rubygems_version: 3.2.3
|
|
156
|
+
signing_key:
|
|
157
|
+
specification_version: 4
|
|
158
|
+
summary: An OmniAuth strategy for integrating with a generic OAuth 2.0 based SSO provider.
|
|
159
|
+
test_files: []
|