omniauth-entra_id_jwt 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/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +252 -0
- data/Rakefile +12 -0
- data/coverage/.last_run.json +5 -0
- data/coverage/.resultset.json +155 -0
- data/coverage/.resultset.json.lock +0 -0
- data/coverage/assets/0.13.1/DataTables-1.10.20/images/sort_asc.png +0 -0
- data/coverage/assets/0.13.1/DataTables-1.10.20/images/sort_asc_disabled.png +0 -0
- data/coverage/assets/0.13.1/DataTables-1.10.20/images/sort_both.png +0 -0
- data/coverage/assets/0.13.1/DataTables-1.10.20/images/sort_desc.png +0 -0
- data/coverage/assets/0.13.1/DataTables-1.10.20/images/sort_desc_disabled.png +0 -0
- data/coverage/assets/0.13.1/application.css +1 -0
- data/coverage/assets/0.13.1/application.js +7 -0
- data/coverage/assets/0.13.1/colorbox/border.png +0 -0
- data/coverage/assets/0.13.1/colorbox/controls.png +0 -0
- data/coverage/assets/0.13.1/colorbox/loading.gif +0 -0
- data/coverage/assets/0.13.1/colorbox/loading_background.png +0 -0
- data/coverage/assets/0.13.1/favicon_green.png +0 -0
- data/coverage/assets/0.13.1/favicon_red.png +0 -0
- data/coverage/assets/0.13.1/favicon_yellow.png +0 -0
- data/coverage/assets/0.13.1/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/coverage/assets/0.13.1/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/coverage/assets/0.13.1/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/coverage/assets/0.13.1/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/coverage/assets/0.13.1/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/coverage/assets/0.13.1/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/coverage/assets/0.13.1/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/coverage/assets/0.13.1/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/coverage/assets/0.13.1/images/ui-icons_222222_256x240.png +0 -0
- data/coverage/assets/0.13.1/images/ui-icons_2e83ff_256x240.png +0 -0
- data/coverage/assets/0.13.1/images/ui-icons_454545_256x240.png +0 -0
- data/coverage/assets/0.13.1/images/ui-icons_888888_256x240.png +0 -0
- data/coverage/assets/0.13.1/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/coverage/assets/0.13.1/loading.gif +0 -0
- data/coverage/assets/0.13.1/magnify.png +0 -0
- data/coverage/index.html +1700 -0
- data/lib/omniauth/entra_id_jwt/version.rb +11 -0
- data/lib/omniauth/entra_id_jwt.rb +2 -0
- data/lib/omniauth/strategies/entra_id_jwt.rb +138 -0
- data/lib/omniauth-entra_id_jwt.rb +1 -0
- data/sig/omniauth/entra/id/jwt.rbs +10 -0
- metadata +157 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8864bca7676bb8175472b16a52a5c6e31eeb9567f1ea2d269e0632be8138c69a
|
4
|
+
data.tar.gz: 066d87a184e3e68e9918b059326d027f8b6e9a9f1026b94145b173ee7a651b45
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 40467da993f4669256ab1687c300dfacdb03f8333ab63aeb2d1730decc7d12e9cb97f407d6fff8372808461a75bc3f826edcae5fe4efdfc722936a58f2fcd6e1
|
7
|
+
data.tar.gz: 3d3852311ccb992378c8bcce5a7d6887895aac890c04c7dd895c85a81b366f78d52479d4a42731b05d4e798e0cf05f357ad0635fd9a757369e312c6c96ab1de0
|
data/CHANGELOG.md
ADDED
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
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 collabital
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 Benjamin Elias
|
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,252 @@
|
|
1
|
+
# OmniAuth::Entra::Id::JWT
|
2
|
+
|
3
|
+
OAuth 2 authentication with [Entra ID API](https://learn.microsoft.com/en-us/entra/identity-platform/v2-overview) using the [JWT Bearer flow](https://oauth.net/2/jwt/). In Microsoft Entra, this is referred to as the [On Behalf Of](https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-on-behalf-of-flow) flow.i
|
4
|
+
|
5
|
+
The rationale for this gem is:
|
6
|
+
|
7
|
+
* Several Entra ID gems are no longer supported
|
8
|
+
* None of these gems support the JWT Bearer flow
|
9
|
+
|
10
|
+
The JWT Bearer flow can be used to share credentials between front-end and back-end systems. This allows your application to initially authenticate a user using front-end flows (e.g. Javascript browser or SPA). Completing a JWT Bearer flow then allows a Rails server to make API calls under the user's identity with its own back-end token.
|
11
|
+
|
12
|
+
Before using this gem, ensure you can successfully receive a JWT token through your front-end. This can be done using the [Microsoft Authentication Library](https://learn.microsoft.com/en-us/entra/identity-platform/msal-overview) implementation applicable to your front-end framework.
|
13
|
+
|
14
|
+
This gem does **not** support more common OAuth2.0 authentication flows, such as [Authorization Code flow](https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-auth-code-flow) or [Client Credentials flow](https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-client-creds-grant-flow). **If you do not need to share credentials between the front-end and back-end systems, use another gem such as [omniauth-entra-id](https://github.com/pond/omniauth-entra-id) or [omniauth-oauth2-generic](https://github.com/omniauth/omniauth-oauth2-generic).**
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
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.
|
19
|
+
|
20
|
+
Add this line to your application's Gemfile:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
gem UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
24
|
+
```
|
25
|
+
|
26
|
+
And then execute:
|
27
|
+
|
28
|
+
```bash
|
29
|
+
bundle install
|
30
|
+
```
|
31
|
+
|
32
|
+
Or install it yourself as:
|
33
|
+
|
34
|
+
```bash
|
35
|
+
gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
36
|
+
```
|
37
|
+
|
38
|
+
## Usage
|
39
|
+
|
40
|
+
Start by reading OmniAuth documentation on a more generic authentication strategy, for example [OAuth2 Generic](https://github.com/omniauth/omniauth-oauth2-generic). Background information can be found at [OmniAuth#Getting-Started](https://github.com/omniauth/omniauth#getting-started).
|
41
|
+
|
42
|
+
This gem implements an OmniAuth strategy, and more information can be found at [Using Devise with OmniAuth](https://github.com/heartcombo/devise/wiki/OmniAuth:-Overview).
|
43
|
+
|
44
|
+
> **Note**: Given the POST request to `user_entra_id_jwt_omniauth_token` is made by a front-end script, there is no use for the 'authorize' route (`user_entra_id_jwt_omniauth_authorize`) that is generated automatically by OmniAuth.
|
45
|
+
|
46
|
+
### Configuration Storage
|
47
|
+
|
48
|
+
You will probably want to store your `client_id` as an environment variable, so that it can be shared between the front-end and back-end parts of your application. You can then store `client_secret` as a [Rails Credential](https://guides.rubyonrails.org/security.html#custom-credentials), as it is only required on the server.
|
49
|
+
|
50
|
+
### TL;DR Version
|
51
|
+
|
52
|
+
After the gem is installed, the TLDR version using Devise is as follows.
|
53
|
+
|
54
|
+
Add OmniAuth fields to your User model:
|
55
|
+
|
56
|
+
```bash
|
57
|
+
rails g migration AddOmniauthToUsers provider:string uid:string
|
58
|
+
rake db:migrate
|
59
|
+
```
|
60
|
+
|
61
|
+
Configure Devise to use the `entra_id_jwt` strategy:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
# config/initializers/devise.rb
|
65
|
+
|
66
|
+
Devise.setup do |config|
|
67
|
+
...
|
68
|
+
config.omniauth(
|
69
|
+
:entra_id_jwt,
|
70
|
+
{
|
71
|
+
client_id: ENV['ENTRA_CLIENT_ID'],
|
72
|
+
client_secret: Rails.application.credentials.entra_client_secret
|
73
|
+
}
|
74
|
+
)
|
75
|
+
...
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
Enable this strategy for your User model:
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
# app/models/user.rb
|
83
|
+
|
84
|
+
class User < ApplicationRecord
|
85
|
+
...
|
86
|
+
devise :omniauthable, omniauth_providers: %i[entra_id_jwt]
|
87
|
+
...
|
88
|
+
end
|
89
|
+
```
|
90
|
+
|
91
|
+
Configure a route for the controller:
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
# config/routes.rb
|
95
|
+
|
96
|
+
Rails.application.routes.draw do
|
97
|
+
...
|
98
|
+
devise_for :users, controllers: { omniauth_callbacks: 'users/omniauth_callbacks' }
|
99
|
+
...
|
100
|
+
end
|
101
|
+
```
|
102
|
+
|
103
|
+
Create a controller to receive the route (the code below assumes all content is rendered in Rails, not client-side):
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
# app/controllers/users/omniauth_callbacks_controller.rb
|
107
|
+
|
108
|
+
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
109
|
+
# See https://github.com/omniauth/omniauth/wiki/FAQ#rails-session-is-clobbered-after-callback-on-developer-strategy
|
110
|
+
skip_before_action :verify_authenticity_token, only: :entra_id_jwt
|
111
|
+
|
112
|
+
def entra_id_jwt
|
113
|
+
# You need to implement the method below in your model (e.g. app/models/user.rb)
|
114
|
+
@user = User.from_omniauth(request.env["omniauth.auth"])
|
115
|
+
|
116
|
+
if @user.persisted?
|
117
|
+
sign_in_and_redirect @user, event: :authentication # this will throw if @user is not activated
|
118
|
+
set_flash_message(:notice, :success, kind: "Entra") if is_navigational_format?
|
119
|
+
else
|
120
|
+
session["devise.entra_data"] = request.env["omniauth.auth"].except(:extra) # Removing extra as it can overflow some session stores
|
121
|
+
redirect_to new_user_registration_url
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def failure
|
126
|
+
redirect_to root_path
|
127
|
+
end
|
128
|
+
end
|
129
|
+
```
|
130
|
+
|
131
|
+
Add a `#from_omniauth` method to your User:
|
132
|
+
|
133
|
+
```ruby
|
134
|
+
# app/models/user.rb
|
135
|
+
|
136
|
+
class User < ApplicationRecord
|
137
|
+
...
|
138
|
+
def self.from_omniauth(auth)
|
139
|
+
find_or_create_by(provider: auth.provider, uid: auth.uid) do |user|
|
140
|
+
user.email = auth.info.email
|
141
|
+
user.password = Devise.friendly_token[0, 20]
|
142
|
+
user.name = auth.info.name # assuming the user model has a name
|
143
|
+
# If you are using confirmable and the provider(s) you use validate emails,
|
144
|
+
# uncomment the line below to skip the confirmation emails.
|
145
|
+
# user.skip_confirmation!
|
146
|
+
end
|
147
|
+
end
|
148
|
+
...
|
149
|
+
end
|
150
|
+
```
|
151
|
+
|
152
|
+
Test your application, with some helpful hints in [OmniAuth Integration Testing](https://github.com/omniauth/omniauth/wiki/Integration-Testing).
|
153
|
+
|
154
|
+
#### Front End Configuration
|
155
|
+
|
156
|
+
Your front-end will need to submit a POST request to the `user_entra_id_jwt_omniauth_callback` route, which is probably something like `/users/auth/entra_id_jwt/callback` unless you have customized this as a Devise route.
|
157
|
+
|
158
|
+
The POST request needs to include at least a `code` parameter.
|
159
|
+
|
160
|
+
### Configuration options
|
161
|
+
|
162
|
+
All of the items listed below are optional, unless noted otherwise. They can be provided either in a static configuration Hash as shown in examples above, or via *read accessor instance methods* in a provider class (more on this later).
|
163
|
+
|
164
|
+
| Option | Use |
|
165
|
+
| ------ | --- |
|
166
|
+
| `client_id` | **Mandatory.** Client ID for the 'application' (integration) configured on the Entra side. Found via the Entra UI. |
|
167
|
+
| `client_secret` | **Mandatory.** Client secret for the 'application' (integration) configured on the Entra side. Found via the Entra UI. Don't give this if using client assertion flow. |
|
168
|
+
| `tenant_id` | Entra Tenant ID for multi-tenanted use. Default is `common`. Forms part of the Entra OAuth URL - `{base}/{tenant_id}/oauth2/v2.0/...` |
|
169
|
+
| `base_url` | Location of Entra login page, for specialised requirements; default is `OmniAuth::Strategies::EntraId::BASE_URL` (at the time of writing, this is `https://login.microsoftonline.com`). |
|
170
|
+
| `authorize_params` | Additional parameters passed as URL query data in the initial OAuth redirection to Microsoft. See below for more. Empty Hash default. |
|
171
|
+
| `scope` | If defined, sets (overwriting, if already present) `scope` inside `authorize_params`. Default is `OmniAuth::Strategies::EntraId::DEFAULT_SCOPE` (at the time of writing, this is `'openid profile email'`). |
|
172
|
+
| `grant_type` | If defined, sets (overwriting, if already present) `grant_type` inside `authorize_params`. Default is `urn:ietf:params:oauth:grant-type:jwt-bearer`. |
|
173
|
+
| `requested_token_use` | If defined, sets (overwriting, if already present) `requested_token_use` inside `authorize_params`. Default is `on_behalf_of`. |
|
174
|
+
|
175
|
+
These can be added to the existing configuration:
|
176
|
+
|
177
|
+
```ruby
|
178
|
+
# config/initializers/devise.rb
|
179
|
+
|
180
|
+
Devise.setup do |config|
|
181
|
+
...
|
182
|
+
config.omniauth(
|
183
|
+
:entra_id_jwt,
|
184
|
+
{
|
185
|
+
client_id: ENV['ENTRA_CLIENT_ID'],
|
186
|
+
client_secret: Rails.application.credentials.entr_client_secret,
|
187
|
+
scope: 'openid profile email offline_access'
|
188
|
+
}
|
189
|
+
)
|
190
|
+
...
|
191
|
+
end
|
192
|
+
```
|
193
|
+
|
194
|
+
### Dynamic options via a custom provider class
|
195
|
+
|
196
|
+
Similar to [OmniAuth::Entra::Id](https://github.com/pond/omniauth-entra-id/tree/master?tab=readme-ov-file#dynamic-options-via-a-custom-provider-class), the options can be made dynamic by implementing a provider class.
|
197
|
+
|
198
|
+
```ruby
|
199
|
+
# config/initializers/devise.rb
|
200
|
+
|
201
|
+
Devise.setup do |config|
|
202
|
+
...
|
203
|
+
config.omniauth(:entra_id_jwt, EntraIdProvider)
|
204
|
+
...
|
205
|
+
end
|
206
|
+
```
|
207
|
+
|
208
|
+
and then creating an appropriate provider (here the `scope` is dependent on a request variable):
|
209
|
+
|
210
|
+
```ruby
|
211
|
+
class EntraIdProvider
|
212
|
+
def initialize(strategy)
|
213
|
+
@strategy = strategy
|
214
|
+
end
|
215
|
+
|
216
|
+
def client_id
|
217
|
+
ENV['ENTRA_CLIENT_ID']
|
218
|
+
end
|
219
|
+
|
220
|
+
def client_secret
|
221
|
+
Rails.application.credentials.entra_client_secret
|
222
|
+
end
|
223
|
+
|
224
|
+
def scope
|
225
|
+
return 'openid profile email offline_access' if @strategy.request.params['offline']
|
226
|
+
'openid profile email'
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
```
|
231
|
+
|
232
|
+
### Authorize URL
|
233
|
+
|
234
|
+
Given the JWT token is already available, there is no use for the `user_entra_id_jwt_omniauth_authorize` route that is generated automatically by OmniAuth. Attempting to access this route will raise a `NotImplementedError`, which you can rescue from if you wish.
|
235
|
+
|
236
|
+
## Development
|
237
|
+
|
238
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
239
|
+
|
240
|
+
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).
|
241
|
+
|
242
|
+
## Contributing
|
243
|
+
|
244
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/omniauth-entra_id_jwt. 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]/omniauth-entra_id_jwt/blob/main/CODE_OF_CONDUCT.md).
|
245
|
+
|
246
|
+
## License
|
247
|
+
|
248
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
249
|
+
|
250
|
+
## Code of Conduct
|
251
|
+
|
252
|
+
Everyone interacting in the OmniAuth::Entra::Id::JWT project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/omniauth-entra_id_jwt/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
{
|
2
|
+
"RSpec": {
|
3
|
+
"coverage": {
|
4
|
+
"/home/benny/omniauth-entra_id_jwt/lib/omniauth/entra_id_jwt.rb": {
|
5
|
+
"lines": [
|
6
|
+
1,
|
7
|
+
1
|
8
|
+
]
|
9
|
+
},
|
10
|
+
"/home/benny/omniauth-entra_id_jwt/lib/omniauth/strategies/entra_id_jwt.rb": {
|
11
|
+
"lines": [
|
12
|
+
null,
|
13
|
+
null,
|
14
|
+
1,
|
15
|
+
null,
|
16
|
+
1,
|
17
|
+
1,
|
18
|
+
1,
|
19
|
+
1,
|
20
|
+
null,
|
21
|
+
1,
|
22
|
+
1,
|
23
|
+
null,
|
24
|
+
1,
|
25
|
+
1,
|
26
|
+
null,
|
27
|
+
null,
|
28
|
+
null,
|
29
|
+
null,
|
30
|
+
1,
|
31
|
+
null,
|
32
|
+
1,
|
33
|
+
63,
|
34
|
+
63,
|
35
|
+
null,
|
36
|
+
63,
|
37
|
+
1,
|
38
|
+
null,
|
39
|
+
null,
|
40
|
+
62,
|
41
|
+
null,
|
42
|
+
62,
|
43
|
+
62,
|
44
|
+
null,
|
45
|
+
62,
|
46
|
+
62,
|
47
|
+
1,
|
48
|
+
61,
|
49
|
+
29,
|
50
|
+
null,
|
51
|
+
32,
|
52
|
+
null,
|
53
|
+
62,
|
54
|
+
null,
|
55
|
+
62,
|
56
|
+
null,
|
57
|
+
62,
|
58
|
+
62,
|
59
|
+
null,
|
60
|
+
null,
|
61
|
+
null,
|
62
|
+
62,
|
63
|
+
29,
|
64
|
+
null,
|
65
|
+
33,
|
66
|
+
null,
|
67
|
+
null,
|
68
|
+
null,
|
69
|
+
null,
|
70
|
+
62,
|
71
|
+
29,
|
72
|
+
null,
|
73
|
+
33,
|
74
|
+
null,
|
75
|
+
null,
|
76
|
+
62,
|
77
|
+
null,
|
78
|
+
null,
|
79
|
+
1,
|
80
|
+
44,
|
81
|
+
null,
|
82
|
+
null,
|
83
|
+
null,
|
84
|
+
null,
|
85
|
+
1,
|
86
|
+
null,
|
87
|
+
52,
|
88
|
+
null,
|
89
|
+
null,
|
90
|
+
null,
|
91
|
+
null,
|
92
|
+
null,
|
93
|
+
null,
|
94
|
+
null,
|
95
|
+
null,
|
96
|
+
null,
|
97
|
+
null,
|
98
|
+
null,
|
99
|
+
null,
|
100
|
+
1,
|
101
|
+
null,
|
102
|
+
62,
|
103
|
+
null,
|
104
|
+
null,
|
105
|
+
null,
|
106
|
+
null,
|
107
|
+
null,
|
108
|
+
null,
|
109
|
+
1,
|
110
|
+
1,
|
111
|
+
null,
|
112
|
+
null,
|
113
|
+
1,
|
114
|
+
470,
|
115
|
+
470,
|
116
|
+
null,
|
117
|
+
null,
|
118
|
+
1,
|
119
|
+
44,
|
120
|
+
44,
|
121
|
+
null,
|
122
|
+
null,
|
123
|
+
1,
|
124
|
+
null,
|
125
|
+
1,
|
126
|
+
33,
|
127
|
+
null,
|
128
|
+
null,
|
129
|
+
1,
|
130
|
+
33,
|
131
|
+
null,
|
132
|
+
null,
|
133
|
+
null,
|
134
|
+
null,
|
135
|
+
1,
|
136
|
+
44,
|
137
|
+
43,
|
138
|
+
null,
|
139
|
+
null,
|
140
|
+
null,
|
141
|
+
43,
|
142
|
+
null,
|
143
|
+
42,
|
144
|
+
null,
|
145
|
+
null,
|
146
|
+
null,
|
147
|
+
null,
|
148
|
+
null,
|
149
|
+
1
|
150
|
+
]
|
151
|
+
}
|
152
|
+
},
|
153
|
+
"timestamp": 1750382784
|
154
|
+
}
|
155
|
+
}
|
File without changes
|
Binary file
|
Binary file
|
Binary file
|