New upstream version 0.0.10

parent b419fe76
# Version 0.0.9
* Expand JWT dep. Thanks @ronaldsalas
# Version 0.0.9 # Version 0.0.9
* Added support for dynamic tenant urls. Thanks @marcus-fellinger-esc * Added support for dynamic tenant urls. Thanks @marcus-fellinger-esc
......
module OmniAuth module OmniAuth
module AzureOauth2 module AzureOauth2
VERSION = "0.0.9" VERSION = "0.0.10"
end end
end end
...@@ -27,15 +27,14 @@ module OmniAuth ...@@ -27,15 +27,14 @@ module OmniAuth
options.client_secret = provider.client_secret options.client_secret = provider.client_secret
options.tenant_id = options.tenant_id =
provider.respond_to?(:tenant_id) ? provider.tenant_id : 'common' provider.respond_to?(:tenant_id) ? provider.tenant_id : 'common'
options.base_azure_url = options.base_azure_url =
provider.respond_to?(:base_azure_url) ? provider.base_azure_url : 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.domain_hint = provider.domain_hint if provider.respond_to?(:domain_hint) && provider.domain_hint
options.authorize_params.prompt = request.params['prompt'] if request.params['prompt'] options.authorize_params.prompt = request.params['prompt'] if request.params['prompt']
options.client_options.authorize_url = "#{options.base_azure_url}/#{options.tenant_id}/oauth2/authorize" options.client_options.authorize_url = "#{options.base_azure_url}/#{options.tenant_id}/oauth2/authorize"
options.client_options.token_url = "#{options.base_azure_url}/#{options.tenant_id}/oauth2/token" options.client_options.token_url = "#{options.base_azure_url}/#{options.tenant_id}/oauth2/token"
options.token_params.resource = options.resource
super super
end end
...@@ -55,6 +54,11 @@ module OmniAuth ...@@ -55,6 +54,11 @@ module OmniAuth
} }
end end
def token_params
azure_resource = request.env['omniauth.params'] && request.env['omniauth.params']['azure_resource']
super.merge(resource: azure_resource || options.resource)
end
def callback_url def callback_url
full_host + script_name + callback_path full_host + script_name + callback_path
end end
......
...@@ -17,7 +17,7 @@ Gem::Specification.new do |gem| ...@@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
gem.license = "MIT" gem.license = "MIT"
gem.add_dependency 'omniauth', '~> 1.0' gem.add_dependency 'omniauth', '~> 1.0'
gem.add_dependency 'jwt', '~> 1.0' gem.add_dependency 'jwt', ['>= 1.0', '< 3.0']
gem.add_runtime_dependency 'omniauth-oauth2', '~> 1.4' gem.add_runtime_dependency 'omniauth-oauth2', '~> 1.4'
......
...@@ -46,12 +46,6 @@ describe OmniAuth::Strategies::AzureOauth2 do ...@@ -46,12 +46,6 @@ describe OmniAuth::Strategies::AzureOauth2 do
expect(subject.client.options[:token_url]).to eql('https://login.microsoftonline.com/tenant/oauth2/token') expect(subject.client.options[:token_url]).to eql('https://login.microsoftonline.com/tenant/oauth2/token')
end end
it 'has correct token params' do
allow(subject).to receive(:request) { request }
subject.client
expect(subject.token_params[:resource]).to eql('00000002-0000-0000-c000-000000000000')
end
describe "overrides" do describe "overrides" do
it 'should override domain_hint' do it 'should override domain_hint' do
@options = {domain_hint: 'hint'} @options = {domain_hint: 'hint'}
...@@ -69,30 +63,30 @@ describe OmniAuth::Strategies::AzureOauth2 do ...@@ -69,30 +63,30 @@ describe OmniAuth::Strategies::AzureOauth2 do
subject do subject do
OmniAuth::Strategies::AzureOauth2.new(app, {client_id: 'id', client_secret: 'secret', tenant_id: 'tenant', base_azure_url: 'https://login.microsoftonline.de'}.merge(options)) OmniAuth::Strategies::AzureOauth2.new(app, {client_id: 'id', client_secret: 'secret', tenant_id: 'tenant', base_azure_url: 'https://login.microsoftonline.de'}.merge(options))
end end
describe '#client' do describe '#client' do
it 'has correct authorize url' do it 'has correct authorize url' do
allow(subject).to receive(:request) { request } allow(subject).to receive(:request) { request }
expect(subject.client.options[:authorize_url]).to eql('https://login.microsoftonline.de/tenant/oauth2/authorize') expect(subject.client.options[:authorize_url]).to eql('https://login.microsoftonline.de/tenant/oauth2/authorize')
end end
it 'has correct authorize params' do it 'has correct authorize params' do
allow(subject).to receive(:request) { request } allow(subject).to receive(:request) { request }
subject.client subject.client
expect(subject.authorize_params[:domain_hint]).to be_nil expect(subject.authorize_params[:domain_hint]).to be_nil
end end
it 'has correct token url' do it 'has correct token url' do
allow(subject).to receive(:request) { request } allow(subject).to receive(:request) { request }
expect(subject.client.options[:token_url]).to eql('https://login.microsoftonline.de/tenant/oauth2/token') expect(subject.client.options[:token_url]).to eql('https://login.microsoftonline.de/tenant/oauth2/token')
end end
it 'has correct token params' do it 'has correct token params' do
allow(subject).to receive(:request) { request } allow(subject).to receive(:request) { request }
subject.client subject.client
expect(subject.token_params[:resource]).to eql('00000002-0000-0000-c000-000000000000') expect(subject.token_params[:resource]).to eql('00000002-0000-0000-c000-000000000000')
end end
describe "overrides" do describe "overrides" do
it 'should override domain_hint' do it 'should override domain_hint' do
@options = {domain_hint: 'hint'} @options = {domain_hint: 'hint'}
...@@ -103,7 +97,7 @@ describe OmniAuth::Strategies::AzureOauth2 do ...@@ -103,7 +97,7 @@ describe OmniAuth::Strategies::AzureOauth2 do
end end
end end
end end
describe 'static common configuration' do describe 'static common configuration' do
let(:options) { @options || {} } let(:options) { @options || {} }
subject do subject do
...@@ -143,6 +137,9 @@ describe OmniAuth::Strategies::AzureOauth2 do ...@@ -143,6 +137,9 @@ describe OmniAuth::Strategies::AzureOauth2 do
'tenant' 'tenant'
end end
def authorize_params
{ custom_option: 'value' }
end
} }
} }
...@@ -162,6 +159,7 @@ describe OmniAuth::Strategies::AzureOauth2 do ...@@ -162,6 +159,7 @@ describe OmniAuth::Strategies::AzureOauth2 do
it 'has correct authorize params' do it 'has correct authorize params' do
subject.client subject.client
expect(subject.authorize_params[:domain_hint]).to be_nil expect(subject.authorize_params[:domain_hint]).to be_nil
expect(subject.authorize_params[:custom_option]).to eql('value')
end end
it 'has correct token url' do it 'has correct token url' do
...@@ -190,52 +188,52 @@ describe OmniAuth::Strategies::AzureOauth2 do ...@@ -190,52 +188,52 @@ describe OmniAuth::Strategies::AzureOauth2 do
Class.new { Class.new {
def initialize(strategy) def initialize(strategy)
end end
def client_id def client_id
'id' 'id'
end end
def client_secret def client_secret
'secret' 'secret'
end end
def tenant_id def tenant_id
'tenant' 'tenant'
end end
def base_azure_url def base_azure_url
'https://login.microsoftonline.de' 'https://login.microsoftonline.de'
end end
} }
} }
subject do subject do
OmniAuth::Strategies::AzureOauth2.new(app, provider_klass) OmniAuth::Strategies::AzureOauth2.new(app, provider_klass)
end end
before do before do
allow(subject).to receive(:request) { request } allow(subject).to receive(:request) { request }
end end
describe '#client' do describe '#client' do
it 'has correct authorize url' do it 'has correct authorize url' do
expect(subject.client.options[:authorize_url]).to eql('https://login.microsoftonline.de/tenant/oauth2/authorize') expect(subject.client.options[:authorize_url]).to eql('https://login.microsoftonline.de/tenant/oauth2/authorize')
end end
it 'has correct authorize params' do it 'has correct authorize params' do
subject.client subject.client
expect(subject.authorize_params[:domain_hint]).to be_nil expect(subject.authorize_params[:domain_hint]).to be_nil
end end
it 'has correct token url' do it 'has correct token url' do
expect(subject.client.options[:token_url]).to eql('https://login.microsoftonline.de/tenant/oauth2/token') expect(subject.client.options[:token_url]).to eql('https://login.microsoftonline.de/tenant/oauth2/token')
end end
it 'has correct token params' do it 'has correct token params' do
subject.client subject.client
expect(subject.token_params[:resource]).to eql('00000002-0000-0000-c000-000000000000') expect(subject.token_params[:resource]).to eql('00000002-0000-0000-c000-000000000000')
end end
# todo: how to get this working? # todo: how to get this working?
# describe "overrides" do # describe "overrides" do
# it 'should override domain_hint' do # it 'should override domain_hint' do
...@@ -245,7 +243,7 @@ describe OmniAuth::Strategies::AzureOauth2 do ...@@ -245,7 +243,7 @@ describe OmniAuth::Strategies::AzureOauth2 do
# end # end
# end # end
end end
end end
describe 'dynamic common configuration' do describe 'dynamic common configuration' do
...@@ -307,4 +305,28 @@ describe OmniAuth::Strategies::AzureOauth2 do ...@@ -307,4 +305,28 @@ describe OmniAuth::Strategies::AzureOauth2 do
end.to_not raise_error end.to_not raise_error
end end
end end
describe 'token_params' do
let(:strategy) { OmniAuth::Strategies::AzureOauth2.new(app, client_id: 'id', client_secret: 'secret') }
let(:request) { double('Request', env: env) }
let(:env) { {} }
subject { strategy.token_params }
before { allow(strategy).to receive(:request).and_return request }
it { is_expected.to be_a OmniAuth::Strategy::Options }
it 'has default resource' do
expect(subject.resource).to eq '00000002-0000-0000-c000-000000000000'
end
context 'when custom crm url' do
let(:crm_url) { 'https://mydomain.crm.dynamics.com/' }
let(:env) { { 'omniauth.params' => { 'azure_resource' => crm_url } } }
it 'has resource from url params' do
expect(subject.resource).to eq crm_url
end
end
end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment