Skip to content

Commit

Permalink
Take the pr from the deprecated omniauth-azure-oauth2
Browse files Browse the repository at this point in the history
* Support for Oauth2 v2.0 marknadig/omniauth-azure-oauth2#29
* Make it work with this new gem
  • Loading branch information
whithajess committed Sep 14, 2020
1 parent 310cc17 commit eaa7d69
Show file tree
Hide file tree
Showing 9 changed files with 403 additions and 29 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@

# rspec failure tracking
.rspec_status

# ide
.idea
12 changes: 0 additions & 12 deletions lib/omniauth/azure/activedirectory/v2.rb

This file was deleted.

1 change: 1 addition & 0 deletions lib/omniauth/azure_activedirectory_v2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require File.join('omniauth', 'strategies', 'azure_activedirectory_v2.rb')
66 changes: 66 additions & 0 deletions lib/omniauth/strategies/azure_activedirectory_v2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
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'
USER_INFO_URL = 'https://graph.microsoft.com/v1.0/me'

# tenant_provider must return client_id, client_secret and optionally tenant_id and base_azure_url
args [:tenant_provider]

def client
if options.tenant_provider
provider = options.tenant_provider.new(self)
else
provider = options # if pass has to config, get mapped right on to 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

options.authorize_params = provider.authorize_params if provider.respond_to?(:authorize_params)
options.authorize_params.domain_hint = provider.domain_hint if provider.respond_to?(:domain_hint) && provider.domain_hint
options.authorize_params.prompt = request.params['prompt'] if defined? request && request.params['prompt']
options.authorize_params.scope = (provider.scope if provider.respond_to?(:scope) && provider.scope) || DEFAULT_SCOPE

options.client_options.authorize_url = "#{options.base_azure_url}/#{options.tenant_id}/oauth2/v2.0/authorize"
options.client_options.token_url = "#{options.base_azure_url}/#{options.tenant_id}/oauth2/v2.0/token"

super
end

uid {
raw_info['id']
}

info do
{
name: raw_info['displayName'],
first_name: raw_info['givenName'],
last_name: raw_info['surname'],
email: raw_info['userPrincipalName'],
id: raw_info['id'],
}
end

def callback_url
full_host + script_name + callback_path
end

def raw_info
@raw_info ||= access_token.get(USER_INFO_URL).parsed
end

end
end
end
14 changes: 8 additions & 6 deletions omniauth-azure-activedirectory-v2.gemspec
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
require_relative 'lib/omniauth/azure/activedirectory/v2/version'
require_relative 'lib/omniauth/azure_activedirectory_v2/version'

Gem::Specification.new do |spec|
spec.name = "omniauth-azure-activedirectory-v2"
spec.version = Omniauth::Azure::Activedirectory::V2::VERSION
spec.authors = ["Jesse Whitham"]
spec.email = ["[email protected]"]

spec.summary = %q{TODO: Write a short summary, because RubyGems requires one.}
spec.description = %q{TODO: Write a longer description or delete this line.}
spec.homepage = "TODO: Put your gem's website or public repo URL here."
spec.summary = %q{Write a short summary, because RubyGems requires one.}
spec.description = %q{Write a longer description or delete this line.}
spec.homepage = "https://github.com/RIPGlobal/omniauth-azure-activedirectory-v2"
spec.license = "MIT"
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")

spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"

spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
spec.metadata["source_code_uri"] = "https://github.com/RIPGlobal/omniauth-azure-activedirectory-v2"
spec.metadata["changelog_uri"] = "https://github.com/RIPGlobal/omniauth-azure-activedirectory-v2"

# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
Expand All @@ -26,4 +26,6 @@ Gem::Specification.new do |spec|
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_dependency 'omniauth-oauth2'
end
9 changes: 0 additions & 9 deletions spec/omniauth/azure/activedirectory/v2_spec.rb

This file was deleted.

Loading

0 comments on commit eaa7d69

Please sign in to comment.