Skip to content

Commit 8a61500

Browse files
committed
Configure Omniauth [wip]
1 parent c62c5f6 commit 8a61500

File tree

7 files changed

+23
-19
lines changed

7 files changed

+23
-19
lines changed

Gemfile

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# frozen_string_literal: true
22

33
source "https://rubygems.org"
4-
ruby File.read(File.expand_path(".ruby-version", __dir__)).strip
4+
ruby file: ".ruby-version"
55

6-
gem "omniauth-azure-activedirectory-v2", "~> 2.1.0"
76
gem "batch_api"
87
gem "bcrypt", "~> 3.1.7"
98
gem "clockwork"
109
gem "devise"
11-
gem "devise_token_auth"
10+
gem "devise_token_auth", "~> 1.2"
11+
gem "omniauth-azure-activedirectory-v2", "~> 2.1.0"
1212
gem "foundation-rails"
1313
gem "fog-aws"
1414
gem "jquery-rails"

Gemfile.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ GEM
121121
devise_token_auth (1.2.2)
122122
bcrypt (~> 3.0)
123123
devise (> 3.5.2, < 5)
124-
rails (>= 4.2.0, < 7.1)
124+
rails (>= 4.2.0, < 7.2)
125125
diff-lcs (1.5.0)
126126
docile (1.4.0)
127127
dotenv (2.8.1)
@@ -474,7 +474,7 @@ DEPENDENCIES
474474
connection_pool
475475
database_cleaner
476476
devise
477-
devise_token_auth
477+
devise_token_auth (~> 1.2)
478478
dotenv-rails
479479
factory_bot_rails (~> 6.0)
480480
faker

app/controllers/application_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class ApplicationController < ActionController::Base
44
include DeviseTokenAuth::Concerns::SetUserByToken
5-
include Pundit
5+
include Pundit::Authorization
66
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
77

88
protect_from_forgery with: :exception

app/models/user.rb

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
# frozen_string_literal: true
22

33
class User < VersionedRecord
4-
# Include default devise modules.
5-
devise :database_authenticatable, :registerable,
6-
:recoverable, :rememberable, :trackable, :validatable
7-
include DeviseTokenAuth::Concerns::User
8-
has_paper_trail ignore: [:tokens, :updated_at]
9-
104
# Include default devise modules. Others available are:
115
# :confirmable, :lockable, :timeoutable and :omniauthable
126
devise :database_authenticatable, :registerable,
137
:recoverable, :rememberable, :trackable, :validatable
8+
# :omniauthable
9+
include DeviseTokenAuth::Concerns::User
10+
has_paper_trail ignore: [:tokens, :updated_at]
1411

1512
has_many :user_roles, dependent: :destroy
1613
has_many :roles, through: :user_roles

config/initializers/devise.rb

-6
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,6 @@
247247
# Add a new OmniAuth provider. Check the wiki for more information on setting
248248
# up on your models and hooks.
249249
# config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'
250-
config.omniauth :azure_activedirectory_v2, {
251-
client_id: ENV["AZURE_CLIENT_ID"],
252-
client_secret: ENV["AZURE_CLIENT_SECRET"],
253-
provider_ignores_state: ENV.fetch("AZURE_PROVIDER_IGNORES_STATE", "false") == "true",
254-
tenant_id: ENV["AZURE_TENANT_ID"]
255-
}
256250

257251
# ==> Warden configuration
258252
# If you want to use other strategies, that are not supported by Devise, or

config/initializers/devise_token_auth.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# This route will be the prefix for all oauth2 redirect callbacks. For
2323
# example, using the default '/omniauth', the github oauth2 provider will
2424
# redirect successful authentications to '/omniauth/github/callback'
25-
# config.omniauth_prefix = "/omniauth"
25+
config.omniauth_prefix = "/auth"
2626

2727
# By default sending current password is not needed for the password update.
2828
# Uncomment to enforce current_password param to be checked before all

config/initializers/omniauth.rb

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Rails.application.config.middleware.use OmniAuth::Builder do
2+
provider :azure_activedirectory_v2, {
3+
callback_path: "/auth/azure_oauth2/callback",
4+
client_id: ENV["AZURE_CLIENT_ID"],
5+
client_secret: ENV["AZURE_CLIENT_SECRET"],
6+
provider_ignores_state: ENV.fetch("AZURE_PROVIDER_IGNORES_STATE", "false") == "true",
7+
tenant_id: ENV["AZURE_TENANT_ID"]
8+
}
9+
10+
# By default only POST is supported but, for now, we need GET for our redirect.
11+
OmniAuth.config.allowed_request_methods = %i[get post]
12+
OmniAuth.config.silence_get_warning = true
13+
end

0 commit comments

Comments
 (0)