Azure Active Directory (Azure AD) is Microsoft’s multi-tenant cloud based directory and identity management service. This documentation describes steps to setup & test Azure AD based single sign-on facility on Learnexa.
Assumption: The working assumption is that the learning site will operate in “Private” mode, which will immediately force the Azure AD login page to appear for any unauthenticated visit.
OAuth 2.0 is one among the authentication protocols supported by Azure AD. Since we already use OAuth2 in Google apps SSO, we can integrate Azure AD inline to existing Google OAuth2 implementation.
In the process of authentication, Azure AD acts as an identity provider, responsible for verifying the identity of users and applications that exist in an organization’s directory. An application that wants to outsource authentication to Azure AD must be registered in Azure AD.
Like Google sign on, user clicks on 'Sing in with Azure' and get redirected to Azure AD for authentication.
Invoking subsite URL, will lead to landing/home page and auto redirects to Azure AD for authentication.
In a few seconds auto redirect to Azure AD for authentication:
User creation flow is very much similar to Google Apps.
This implementation is based on gem 'omniauth-azure-oauth2'- https://github.com/KonaTeam/omniauth-azure-oauth2
Using OmniAuth, add Azure AD as a new provider to Learnexa's OmniAuth::Builder. The provider requires the Azure AD client id and the Azure AD tenant.
Add the configuration in config/initializers/omniauth.rb
ActionController::Dispatcher.middleware.use OmniAuth::Builder do provider :azure_activedirectory, ENV['AAD_CLIENT_ID'], ENV['AAD_TENANT'] ...
In Sign-in page have an additional option 'Sign in with Azure AD'
While authenticating user, simply redirect to /auth/azureactivedirectory. From there, OmniAuth will take over. Once the user authenticates (or fails to authenticate), they will be redirected to /auth/azureactivedirectory/callback or /auth/azureactivedirectory/failure. The authentication result is available in request.env['omniauth.auth'].
Add routes
%w(get post).each do |method|
send(method, '/auth/:provider/callback') do
auth = request.env['omniauth.auth']
Make use of the existing tables. This can have multiple entries for the same company but with different domains.
oauth_sso_settings
| ID | integer |
| company_id | integer |
| client_id | string |
| tenant_id | string |
| client_secret | string |
| provider | string |
| callback_url | string |
| created_at | date |
| updated_at | date |
users
| created_source | string |
companies
| azure_sso_enabled | boolean |
https://account.windowsazure.com/organization to sign up for Azure with a new organization. Once you've completed the process, you will have your very own Azure AD tenant with the domain name you chose during sign up. In the Azure Portal, you can find your tenant by navigating to “Azure Active Directory” in the left-hand navigation.
A quick way to get the Tenant Id for your Office 365 / Azure AD tenant is to login to the Azure AD Portal, drill down to the directory and copy the ID from the URL.
https://manage.windowsazure.com/learnexa.onmicrosoft.com#Workspaces/ActiveDirectoryExtension/Directory/<Tenant Id>/directoryQuickStart
https://github.com/KonaTeam/omniauth-azure-oauth2
https://github.com/AzureAD/omniauth-azure-activedirectory
https://docs.microsoft.com/en-gb/azure/active-directory/active-directory-integrating-applications
https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-developers-guide