omniauth-azure-activedirectory-v2-2.4.0/0000755000004100000410000000000014712443624020247 5ustar www-datawww-dataomniauth-azure-activedirectory-v2-2.4.0/bin/0000755000004100000410000000000014712443624021017 5ustar www-datawww-dataomniauth-azure-activedirectory-v2-2.4.0/bin/setup0000755000004100000410000000020314712443624022100 0ustar www-datawww-data#!/usr/bin/env bash set -euo pipefail IFS=$'\n\t' set -vx bundle install # Do any other automated setup that you need to do here omniauth-azure-activedirectory-v2-2.4.0/bin/console0000755000004100000410000000056014712443624022410 0ustar www-datawww-data#!/usr/bin/env ruby require "bundler/setup" require "omniauth/azure/activedirectory/v2" # You can add fixtures and/or initialization code here to make experimenting # with your gem easier. You can also use a different console, if you like. # (If you use this, don't forget to add pry to your Gemfile!) # require "pry" # Pry.start require "irb" IRB.start(__FILE__) omniauth-azure-activedirectory-v2-2.4.0/lib/0000755000004100000410000000000014712443624021015 5ustar www-datawww-dataomniauth-azure-activedirectory-v2-2.4.0/lib/omniauth-azure-activedirectory-v2.rb0000644000004100000410000000007214712443624030034 0ustar www-datawww-datarequire File.join('omniauth', 'azure_activedirectory_v2') omniauth-azure-activedirectory-v2-2.4.0/lib/omniauth/0000755000004100000410000000000014712443624022641 5ustar www-datawww-dataomniauth-azure-activedirectory-v2-2.4.0/lib/omniauth/azure_activedirectory_v2.rb0000644000004100000410000000045714712443624030211 0ustar www-datawww-datawarn "[DEPRECATION] This gem has been renamed to 'omniauth-entra-id' and will no longer be supported. Please switch to 'omniauth-entra-id' as soon as possible." require File.join('omniauth', 'azure_activedirectory_v2', 'version') require File.join('omniauth', 'strategies', 'azure_activedirectory_v2') omniauth-azure-activedirectory-v2-2.4.0/lib/omniauth/azure_activedirectory_v2/0000755000004100000410000000000014712443624027656 5ustar www-datawww-dataomniauth-azure-activedirectory-v2-2.4.0/lib/omniauth/azure_activedirectory_v2/version.rb0000644000004100000410000000023714712443624031672 0ustar www-datawww-datamodule OmniAuth module Azure module Activedirectory module V2 VERSION = "2.4.0" DATE = "2024-10-17" end end end end omniauth-azure-activedirectory-v2-2.4.0/lib/omniauth/strategies/0000755000004100000410000000000014712443624025013 5ustar www-datawww-dataomniauth-azure-activedirectory-v2-2.4.0/lib/omniauth/strategies/azure_activedirectory_v2.rb0000644000004100000410000000725114712443624032362 0ustar www-datawww-data# frozen_string_literal: true require 'omniauth-oauth2' module OmniAuth module Strategies class AzureActivedirectoryV2 < OmniAuth::Strategies::OAuth2 BASE_AZURE_URL = 'https://login.microsoftonline.com' option :name, 'azure_activedirectory_v2' option :tenant_provider, nil DEFAULT_SCOPE = 'openid profile email' # tenant_provider must return client_id, client_secret and optionally tenant_id and base_azure_url args [:tenant_provider] def client provider = if options.tenant_provider options.tenant_provider.new(self) else options end options.client_id = provider.client_id options.client_secret = provider.client_secret options.tenant_id = provider.respond_to?(:tenant_id) ? provider.tenant_id : 'common' options.base_azure_url = provider.respond_to?(:base_azure_url) ? provider.base_azure_url : BASE_AZURE_URL if provider.respond_to?(:authorize_params) options.authorize_params = provider.authorize_params end if provider.respond_to?(:domain_hint) && provider.domain_hint options.authorize_params.domain_hint = provider.domain_hint end if defined?(request) && request.params['prompt'] options.authorize_params.prompt = request.params['prompt'] end options.authorize_params.scope = if defined?(request) && request.params['scope'] request.params['scope'] elsif provider.respond_to?(:scope) && provider.scope provider.scope else DEFAULT_SCOPE end options.custom_policy = provider.respond_to?(:custom_policy) ? provider.custom_policy : nil oauth2 = provider.respond_to?(:adfs?) && provider.adfs? ? 'oauth2' : 'oauth2/v2.0' options.client_options.authorize_url = "#{options.base_azure_url}/#{options.tenant_id}/#{oauth2}/authorize" options.client_options.token_url = if options.custom_policy "#{options.base_azure_url}/#{options.tenant_id}/#{options.custom_policy}/#{oauth2}/token" else "#{options.base_azure_url}/#{options.tenant_id}/#{oauth2}/token" end super end uid { raw_info['oid'] } info do { name: raw_info['name'], email: raw_info['email'] || raw_info['upn'], nickname: raw_info['unique_name'], first_name: raw_info['given_name'], last_name: raw_info['family_name'] } end extra do { raw_info: raw_info } end def callback_url full_host + callback_path end # https://docs.microsoft.com/en-us/azure/active-directory/develop/id-tokens # # Some account types from Microsoft seem to only have a decodable ID token, # with JWT unable to decode the access token. Information is limited in those # cases. Other account types provide an expanded set of data inside the auth # token, which does decode as a JWT. # # Merge the two, allowing the expanded auth token data to overwrite the ID # token data if keys collide, and use this as raw info. # def raw_info if @raw_info.nil? id_token_data = begin ::JWT.decode(access_token.params['id_token'], nil, false).first rescue StandardError {} end auth_token_data = begin ::JWT.decode(access_token.token, nil, false).first rescue StandardError {} end id_token_data.merge!(auth_token_data) @raw_info = id_token_data end @raw_info end end end end omniauth-azure-activedirectory-v2-2.4.0/LICENSE.txt0000644000004100000410000000207014712443624022071 0ustar www-datawww-dataThe MIT License (MIT) Copyright (c) 2020 Jesse Whitham Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. omniauth-azure-activedirectory-v2-2.4.0/CODE_OF_CONDUCT.md0000644000004100000410000000623514712443624023054 0ustar www-datawww-data# Contributor Covenant Code of Conduct ## Our Pledge In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. ## Our Standards Examples of behavior that contributes to creating a positive environment include: * Using welcoming and inclusive language * Being respectful of differing viewpoints and experiences * Gracefully accepting constructive criticism * Focusing on what is best for the community * Showing empathy towards other community members Examples of unacceptable behavior by participants include: * The use of sexualized language or imagery and unwelcome sexual attention or advances * Trolling, insulting/derogatory comments, and personal or political attacks * Public or private harassment * Publishing others' private information, such as a physical or electronic address, without explicit permission * Other conduct which could reasonably be considered inappropriate in a professional setting ## Our Responsibilities Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. ## Scope This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at dev@ripaglobal.com. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. ## Attribution This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [https://contributor-covenant.org/version/1/4][version] [homepage]: https://contributor-covenant.org [version]: https://contributor-covenant.org/version/1/4/ omniauth-azure-activedirectory-v2-2.4.0/omniauth-azure-activedirectory-v2.gemspec0000644000004100000410000000425514712443624030315 0ustar www-datawww-data# -*- encoding: utf-8 -*- # frozen_string_literal: true # stub: omniauth-azure-activedirectory-v2 1.0.0 ruby lib $:.push File.expand_path( '../lib', __FILE__ ) require 'omniauth/azure_activedirectory_v2/version' # https://guides.rubygems.org/specification-reference/ # Gem::Specification.new do |s| s.post_install_message = <<-MESSAGE ! The 'omniauth-azure-activedirectory-v2' gem has been deprecated and is ! replaced by 'omniauth-entra-id'. ! ! See: https://rubygems.org/gems/omniauth-entra-id ! And: https://github.com/RIPAGlobal/omniauth-entra-id MESSAGE s.name = 'omniauth-azure-activedirectory-v2' s.version = OmniAuth::Azure::Activedirectory::V2::VERSION s.date = OmniAuth::Azure::Activedirectory::V2::DATE s.summary = 'OAuth 2 authentication with the Azure ActiveDirectory V2 API.' s.authors = [ 'RIPA Global' ] s.email = [ 'dev@ripaglobal.com' ] s.licenses = [ 'MIT' ] s.homepage = 'https://github.com/RIPAGlobal/omniauth-azure-activedirectory-v2' s.required_ruby_version = Gem::Requirement.new('>= 2.3.0') s.require_paths = ['lib'] s.bindir = 'exe' s.files = %w{ README.md CHANGELOG.md CODE_OF_CONDUCT.md LICENSE.txt Gemfile bin/console bin/setup lib/omniauth-azure-activedirectory-v2.rb lib/omniauth/azure_activedirectory_v2.rb lib/omniauth/azure_activedirectory_v2/version.rb lib/omniauth/strategies/azure_activedirectory_v2.rb omniauth-azure-activedirectory-v2.gemspec } s.metadata = { 'homepage_uri' => 'https://www.ripaglobal.com/', 'bug_tracker_uri' => 'https://github.com/RIPAGlobal/omniauth-azure-activedirectory-v2/issues/', 'changelog_uri' => 'https://github.com/RIPAGlobal/omniauth-azure-activedirectory-v2/blob/master/CHANGELOG.md', 'source_code_uri' => 'https://github.com/RIPAGlobal/omniauth-azure-activedirectory-v2' } s.add_runtime_dependency('omniauth-oauth2', '~> 1.8') s.add_development_dependency('rake', '~> 13.2 ') s.add_development_dependency('rspec', '~> 3.13') end omniauth-azure-activedirectory-v2-2.4.0/Gemfile0000644000004100000410000000017014712443624021540 0ustar www-datawww-datasource "https://rubygems.org" # Specify your gem's dependencies in omniauth-azure-activedirectory-v2.gemspec # gemspec omniauth-azure-activedirectory-v2-2.4.0/README.md0000644000004100000410000002515714712443624021540 0ustar www-datawww-data# OmniAuth::Azure::Activedirectory::V2 [![Gem Version](https://badge.fury.io/rb/omniauth-azure-activedirectory-v2.svg)](https://rubygems.org/gems/omniauth-azure-activedirectory-v2) [![Build Status](https://github.com/RIPAGlobal/omniauth-azure-activedirectory-v2/actions/workflows/master.yml/badge.svg)](https://github.com/RIPAGlobal/omniauth-azure-activedirectory-v2/actions) [![License](https://img.shields.io/github/license/RIPAGlobal/omniauth-azure-activedirectory-v2.svg)](LICENSE.txt) **IMPORTANT: V2 is end-of-life** and superseded by a renamed gem, since Microsoft in their "wisdom" renamed Azure AD to Entra ID. A gem using the old name will become increasingly hard for people to 'discover'. The major version bump provides an opportunity to fix a few things via breaking changes, too. Please switch to `omniauth-entra-id`. OAuth 2 authentication with [Azure ActiveDirectory's V2 API](https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-overview). Rationale: * https://github.com/marknadig/omniauth-azure-oauth2 is no longer maintained. * https://github.com/marknadig/omniauth-azure-oauth2/pull/29 contains important additions. This gem combines the two and makes some changes to support the full V2 API. The ActiveDirectory V1 auth API used OpenID Connect. If you need this, a gem from Microsoft [is available here](https://github.com/AzureAD/omniauth-azure-activedirectory), but seems to be abandoned. ## Installation Add this line to your application's Gemfile: ```ruby gem 'omniauth-azure-activedirectory-v2' ``` And then execute: ```shell $ bundle install ``` Or install it yourself as: ```shell $ gem install omniauth-azure-activedirectory-v2 ``` ## Usage Please start by reading https://github.com/marknadig/omniauth-azure-oauth2 for basic configuration and background information. Note that with this gem, you must use strategy name `azure_activedirectory_v2` rather than `azure_oauth2`. Additional configuration information is given below. ### Configuration #### With `OmniAuth::Builder` You can do something like this for a static / fixed configuration: ```ruby use OmniAuth::Builder do provider( :azure_activedirectory_v2, { client_id: ENV['AZURE_CLIENT_ID'], client_secret: ENV['AZURE_CLIENT_SECRET'] } ) end ``` ...or, if using a custom provider class (called `YouTenantProvider` in this example): ```ruby use OmniAuth::Builder do provider( :azure_activedirectory_v2, YouTenantProvider ) end ``` #### With Devise In your `config/initializers/devise.rb` file you can do something like this for a static / fixed configuration: ```ruby config.omniauth( :azure_activedirectory_v2, { client_id: ENV['AZURE_CLIENT_ID'], client_secret: ENV['AZURE_CLIENT_SECRET'] } ) ``` ...or, if using a custom provider class (called `YouTenantProvider` in this example): ```ruby config.omniauth( :azure_activedirectory_v2, YouTenantProvider ) ``` ### Configuration options 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). | Option | Use | | ------ | --- | | `client_id` | **Mandatory.** Client ID for the 'application' (integration) configured on the Azure side. Found via the Azure UI. | | `client_secret` | **Mandatory.** Client secret for the 'application' (integration) configured on the Azure side. Found via the Azure UI. | | `base_azure_url` | Location of Azure login page, for specialised requirements; default is `OmniAuth::Strategies::AzureActivedirectoryV2::BASE_AZURE_URL` (at the time of writing, this is `https://login.microsoftonline.com`). | | `tenant_id` | _Azure_ tenant ID for multi-tenanted use. Default is `common`. Forms part of the Azure OAuth URL - `{base}/{tenant_id}/oauth2/v2.0/...` | | `custom_policy` | _Azure_ custom policy. Default is nil. Forms part of the Azure Token URL - `{base}/{tenant_id}/{custom_policy}/oauth2/v2.0/...` | | `authorize_params` | Additional parameters passed as URL query data in the initial OAuth redirection to Microsoft. See below for more. Empty Hash default. | | `domain_hint` | If defined, sets (overwriting, if already present) `domain_hint` inside `authorize_params`. Default `nil` / none. | | `scope` | If defined, sets (overwriting, if already present) `scope` inside `authorize_params`. Default is `OmniAuth::Strategies::AzureActivedirectoryV2::DEFAULT_SCOPE` (at the time of writing, this is `'openid profile email'`). | | `adfs` | If defined, modifies the URLs so they work with an on premise ADFS server. In order to use this you also need to set the `base_azure_url` correctly and fill the `tenant_id` with `'adfs'`. | In addition, as a special case, if the request URL contains a query parameter `prompt`, then this will be written into `authorize_params` under that key, overwriting if present any other value there. Note that this comes from the current request URL at the time OAuth flow is commencing, _not_ via static options Hash data or via a custom provider class - but you _could_ just as easily set `scope` inside a custom `authorize_params` returned from a provider class, as shown in an example later; the request URL query mechanism is just another way of doing the same thing. #### Explaining `custom_policy` In the documentation for [requesting a token](https://learn.microsoft.com/en-us/azure/active-directory-b2c/access-tokens#request-a-token), Microsoft indicate that they want the name of custom policies to be given in the URL rather than in the body of the request: ``` POST .b2clogin.com/.onmicrosoft.com//oauth2/v2.0/token ``` When the underlying `oath2` gem creates the request for getting a token via POST, it places all `params` (which would include anything you've provided in the normal configuration to name your custom policy) in the `body` of the request. Unfortunately, Microsoft ignores custom policies in the body and only looks for them in the URL. If you set a `custom_policy` in your configuration, it will be included in the URL between the `tenant_id` and the remaining parts of the path (`/oauth2/v2.0/token`). #### Explaining `authorize_params` The `authorize_params` hash-like object contains key-value pairs which are transformed into URL query string data and added to existing standard OAuth query data in the URL used for the initial redirection from your web site, to the Microsoft Azure AD login page, at the start of OAuth flow. You can find these listed some way down the table just below an OAuth URL example at: * https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow#code-try-1 ...looking for in particular items from `prompt` onwards. #### Dynamic options via a custom provider class Documentation mentioned earlier at https://github.com/marknadig/omniauth-azure-oauth2#usage gives an example of setting tenant ID dynamically via a custom provider class. We can also use that class in other ways. For example, let's rewrite it thus: ```ruby class YouTenantProvider def initialize(strategy) @strategy = strategy end def client_id ENV['AZURE_CLIENT_ID'] end def client_secret ENV['AZURE_CLIENT_SECRET'] end def authorize_params ap = {} if @strategy.request && @strategy.request.params['login_hint'] ap['login_hint'] = @strategy.request.params['login_hint'] end return ap end end ``` In this example, we're providing custom `authorize_params`. You can just return a standard Ruby Hash here, using lower case String or Symbol keys. The `strategy` value given to the initializer is an instance of [`OmniAuth::StrategiesAzureActivedirectoryV2`](https://github.com/RIPAGlobal/omniauth-azure-activedirectory-v2/blob/master/lib/omniauth/strategies/azure_activedirectory_v2.rb) which is a subclass of [`OmniAuth::Strategies::OAuth2`](https://www.rubydoc.info/gems/omniauth-oauth2/1.8.0/OmniAuth/Strategies/OAuth2), but that's not all that helpful! What's more useful is to know that **the Rails `request` object is available via `@strategy.request` and, likewise, the session store via `@strategy.session`**. This gives you a lot of flexibility for responding to an inbound request or user session, varying the parameters used for the Azure OAuth flow. In method `#authorize_params` above, the request object is used to look for a `login_hint` query string entry, set in whichever view(s) is/are presented by your application for use when your users need to be redirected to the OmniAuth controller in order to kick off OAuth with Azure. The value is copied into the `authorize_params` Hash. Earlier, it was mentioned that there was a special case of `prompt` being pulled from the request URL query data, but that this could also be done via a custom provider - here, you can see how; just check `@strategy.request.params['prompt']` and copy that into `authorize_params` if preset. > **NB:** Naming things is hard! The predecessor gem used the name `YouTenantProvider` since it was focused on custom tenant provision, but if using this in a more generic way, perhaps consider a more generic name such as, say, `CustomOmniAuthAzureProvider`. #### Special case scope override If required and more convenient, you can specify a custom `scope` value via generation of an authorisation URL including that required `scope`, rather than by using a custom provider class with `def scope...end` method. Include the `scope` value in your call to generate the URL thus: ```ruby omniauth_authorize_url('resource_name_eg_user', 'azure_activedirectory_v2', scope: '...') ``` ## Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/RIPAGlobal/omniauth-azure-activedirectory-v2. This project is intended to be a safe, welcoming space for collaboration so contributors must adhere to the [code of conduct](https://github.com/RIPAGlobal/omniauth-azure-activedirectory-v2/blob/master/CODE_OF_CONDUCT.md). ### Getting running * Fork the repository * Check out your fork * `cd` into the repository * `bin/setup` * `bundle exec rspec` to make sure all the tests run ### Making changes * Make your change * Add tests and check that `bundle exec rspec` still runs successfully * For new features (rather than bug fixes), update `README.md` with details ## License The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). ## Code of Conduct Everyone interacting in this project's codebases, issue trackers, chat rooms and mailing lists must follow the [code of conduct](https://github.com/RIPAGlobal/omniauth-azure-activedirectory-v2/blob/master/CODE_OF_CONDUCT.md). omniauth-azure-activedirectory-v2-2.4.0/CHANGELOG.md0000644000004100000410000000460714712443624022067 0ustar www-datawww-data# Change Log ## v2.4.0 (2024-10-17) Deprecation warnings for end-of-life of the gem under this name. No other changes. The GitHub repository is to be renamed and the gem released (starting at major version 3) as `omniauth-entra-id`, with some breaking changes but details of how to update will be provided in the new gem via an `UPGRADING.md` document. ## v2.3.0 (2024-07-16) [Implements](https://github.com/RIPAGlobal/omniauth-azure-activedirectory-v2/pull/29) support for on-premise Active Directory installations via the `adfs` option; see `README.md` for details - thanks @frenkel! ## v2.2.0 (2024-07-09) [Implements](https://github.com/RIPAGlobal/omniauth-azure-activedirectory-v2/pull/26) support for specifying `scope` via the authorisation URL, in addition to the prior support for static configuration or configuration via a custom provider class - thanks @nbgoodall! ## v2.1.0 (2023-09-16) [Implements](https://github.com/RIPAGlobal/omniauth-azure-activedirectory-v2/pull/19) support for custom policies when using Microsoft Azure AD - thanks @stevenchanin! ## v2.0.2 (2023-03-31) [Fixes](https://github.com/RIPAGlobal/omniauth-azure-activedirectory-v2/pull/16) inability to override prompt in authorisation parameters - thanks @lamroger! ## v2.0.1 (2023-01-11) Renames: * RIPGlobal -> RIPAGlobal * Omniauth -> OmniAuth _No functional change._ ## v2.0.0 (2022-09-14) Makes compatible with OmniAuth 2 and requires it. Note: https://github.com/RIPAGlobal/omniauth-azure-activedirectory-v2/pull/6 for reasoning - Thanks @jessieay _Major version bump as no longer supports OmniAuth 1._ ## v1.0.0 (2020-09-25) Removes use of the https://graph.microsoft.com/v1.0/me API. * One of the key differences for the V2 API vs V1 is the differences between who can sign with the addition of Personal Accounts - see: https://nicolgit.github.io/AzureAD-Endopoint-V1-vs-V2-comparison/ - In testing we found that these accounts may not have access to this endpoint - All the data provided in `info` exists in the JWT anyway, so this cuts down on API calls * Conforms to the OmniAuth Auth Hash Schema (1.0 and later) - see: https://github.com/omniauth/omniauth/wiki/Auth-Hash-Schema - Expose `raw_info` - Remove `id` from `info` - *NB: This could be a breaking change for some, but most will already be using the correct property name of `uid`.* ## v0.1.1 (2020-09-23) - First release.