Skip to content

Commit 1ba4714

Browse files
committed
Add azure/microsoft oAuth2
1 parent 6336729 commit 1ba4714

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed

.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ GOOGLE_SECRET=
1515
# Omniauth Facebook oAuth2
1616
FACEBOOK_APP_ID=
1717
FACEBOOK_SECRET=
18+
19+
# Omniauth Microsoft/Azure oAuth2
20+
AZURE_APP_ID=
21+
AZURE_SECRET=

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ gem 'turbolinks'
2424
gem 'omniauth-oauth2'
2525
gem 'omniauth-google-oauth2'
2626
gem 'omniauth-facebook'
27+
gem 'omniauth-microsoft_graph'
2728
# gem 'omniauth-github'
28-
# gem 'omniauth-microsoft_graph'
2929
# gem 'omniauth-twitter'
3030

3131
# Effective Gems

Gemfile.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ GEM
249249
jwt (>= 2.0)
250250
omniauth (>= 1.1.1)
251251
omniauth-oauth2 (>= 1.6)
252+
omniauth-microsoft_graph (0.3.3)
253+
omniauth (~> 1.1, >= 1.1.1)
254+
omniauth-oauth2 (~> 1.6)
252255
omniauth-oauth2 (1.7.0)
253256
oauth2 (~> 1.4)
254257
omniauth (~> 1.9)
@@ -406,6 +409,7 @@ DEPENDENCIES
406409
listen
407410
omniauth-facebook
408411
omniauth-google-oauth2
412+
omniauth-microsoft_graph
409413
omniauth-oauth2
410414
passenger
411415
pg

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,28 @@ GOOGLE_CLIENT_ID=
210210
GOOGLE_SECRET=
211211
```
212212

213+
### Microsoft oAuth2
214+
215+
- Visit https://aad.portal.azure.com/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/Overview
216+
- Find Azure Active Directory
217+
218+
- Click 'App registrations' from left menu
219+
220+
- Click 'New Registration'
221+
- Supported account types: Accounts in any organizational directory (Any Azure AD directory - Multitenant) and personal Microsoft accounts (e.g. Skype, Xbox)
222+
- Redirect URI: Web https://example.herokuapp.com/users/auth/microsoft_graph/callback
223+
224+
- Copy the Application (client) ID into the `.env` file and/or set server production ENV variables
225+
226+
- Click 'Certificates & Secrets'
227+
- Click 'New client secret'
228+
- Copy the Client secret into the `.env` file and/or set server production ENV variables
229+
230+
```
231+
AZURE_APP_ID=
232+
AZURE_SECRET=
233+
```
234+
213235
## License
214236

215237
MIT License. Copyright [Code and Effect Inc.](https://www.codeandeffect.com/)

config/initializers/devise.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,12 @@
316316
}
317317
end
318318

319+
if ENV['AZURE_APP_ID'].present? && defined?(OmniAuth::Strategies::MicrosoftGraph)
320+
config.omniauth :microsoft_graph, ENV.fetch('AZURE_APP_ID'), ENV.fetch('AZURE_SECRET'), {
321+
scope: 'openid profile email offline_access user.read'
322+
}
323+
end
324+
319325
# ==> Warden configuration
320326
# If you want to use other strategies, that are not supported by Devise, or
321327
# change the failure app, you can configure them inside the config.warden block.

0 commit comments

Comments
 (0)