Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Azure single-tenant application support, using the Graph API #6728

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: add AZURE_TENANT_ID, to support single tenant microsoft applicat…
…ions
  • Loading branch information
moxvallix committed Mar 15, 2023
commit e3086402b069ad62167279288b52b2a8948625e3
8 changes: 6 additions & 2 deletions app/controllers/concerns/microsoft_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ def microsoft_client
::OAuth2::Client.new(ENV.fetch('AZURE_APP_ID', nil), ENV.fetch('AZURE_APP_SECRET', nil),
{
site: 'https://login.microsoftonline.com',
authorize_url: 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize',
token_url: 'https://login.microsoftonline.com/common/oauth2/v2.0/token'
authorize_url: "https://login.microsoftonline.com/#{azure_tenant_id}/oauth2/v2.0/authorize",
moxvallix marked this conversation as resolved.
Show resolved Hide resolved
token_url: "https://login.microsoftonline.com/#{azure_tenant_id}/oauth2/v2.0/token"
})
end

Expand All @@ -19,4 +19,8 @@ def parsed_body
def base_url
ENV.fetch('FRONTEND_URL', 'http://localhost:3000')
end

def azure_tenant_id
MicrosoftGraphAuth.azure_tenant_id
end
end
16 changes: 14 additions & 2 deletions lib/microsoft_graph_auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,27 @@
# Implements an OmniAuth strategy to get a Microsoft Graph
# compatible token from Azure AD
class MicrosoftGraphAuth < OmniAuth::Strategies::OAuth2
# Microsoft Azure Tenant
# For single tenant applications, meant to be used by
# organisations for their own apps, the 'common' endpoint is not allowed.
# If the environment variable 'AZURE_TENANT_ID' is set,
# this will return it's value, otherwise, it will default to 'common'.
#
# The tenant id for your Azure organization can be obtained by
# by accessing 'Tenant properties' from the Azure portal.
def self.azure_tenant_id
ENV.fetch('AZURE_TENANT_ID', 'common')
end

option :name, :microsoft_graph_auth

DEFAULT_SCOPE = 'offline_access https://outlook.office.com/IMAP.AccessAsUser.All https://outlook.office.com/SMTP.Send'

# Configure the Microsoft identity platform endpoints
option :client_options,
site: 'https://login.microsoftonline.com',
authorize_url: '/common/oauth2/v2.0/authorize',
token_url: '/common/oauth2/v2.0/token'
authorize_url: "/#{azure_tenant_id}/oauth2/v2.0/authorize",
token_url: "/#{azure_tenant_id}/oauth2/v2.0/token"

option :pcke, true
# Send the scope parameter during authorize
Expand Down