omniauth-azure-oauth2-v2 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +8 -0
- data/README.md +197 -0
- data/Rakefile +6 -0
- data/examples/sinatra.rb +31 -0
- data/lib/omniauth-azure-oauth2-v2.rb +2 -0
- data/lib/omniauth/azure_auth_request_helper.rb +21 -0
- data/lib/omniauth/azure_oauth2_v2.rb +1 -0
- data/lib/omniauth/azure_oauth2_v2/version.rb +5 -0
- data/lib/omniauth/strategies/azure_oauth2_v2.rb +45 -0
- data/omniauth-azure-oauth2-v2.gemspec +26 -0
- data/spec/omniauth/strategies/azure_oauth2_v2_spec.rb +259 -0
- data/spec/spec_helper.rb +2 -0
- metadata +134 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ee50bf2e30d9a041f75a75a3369ae530c6c9940ea773f95e507f001c80cff54b
|
4
|
+
data.tar.gz: e8b2408c570b9ae4fa2ca29eae5df05d84e46241166b3349ba8793d10dc170bf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 60e6ddd127721e3cf0eed0604b10597e6e677625fcb3183716dbfc3fead4ef36b041db9ed0a19bef0dff1aeec48f84c60d20e54688180ff8f14c0318f58f38cc
|
7
|
+
data.tar.gz: 0e8203fc587fe22b730a2f46a1bbdfc1e679f79314c738f1bac3e387d71b34daa3a4bceba7bcee6d0d654fb919cb769d7e22d29dcd866b31e18aeda0fb890463
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,197 @@
|
|
1
|
+
# OmniAuth V2.0 Windows Azure Active Directory Strategy
|
2
|
+
|
3
|
+
This gem provides a simple way to authenticate to Windows Azure Active Directory (WAAD) over OAuth2 using OmniAuth on specific integrations with Azure `v2.0` Endpoints.
|
4
|
+
|
5
|
+
##### Important:
|
6
|
+
Again: Use this gem only if your single-sign-on endpoints has the Auth2 `v2.0` specified. If don't, take a look at: https://github.com/marknadig/omniauth-azure-oauth2.
|
7
|
+
#### Comments
|
8
|
+
One of the unique challenges of WAAD OAuth is that WAAD is multi tenant. Any given tenant can have multiple active
|
9
|
+
directories. The CLIENT-ID, REPLY-URL and keys will be unique to the tenant/AD/application combination. This gem simply
|
10
|
+
provides hooks for determining those unique values for each call.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'omniauth-azure-oauth2-v2'
|
18
|
+
```
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
First, you will need to add your site as an application in WAAD.:
|
23
|
+
[Adding, Updating, and Removing an Application](https://docs.microsoft.com/en-us/azure/active-directory/develop/)
|
24
|
+
|
25
|
+
Summary:
|
26
|
+
Your provider should pass some infos to you. Name, sign-on url, logo are not important. You will need the CLIENT-ID from the application configuration and your provider will need to generate an Client Secret. REPLY URL is the oauth redirect uri which will be the omniauth callback path https://example.com/users/auth/azure_oauth2/callback. The APP ID UI just needs to be unique to that tenant and identify your site and isn't needed to configure the gem.
|
27
|
+
Permissions need Delegated Permissions to at least have "Enable sign-on and read user's profiles".
|
28
|
+
If you want to change the basic sign-on url, specify the attribute base_azure_url when build the provider.
|
29
|
+
Note: Seems like the terminology is still fluid, so follow the MS guidance (buwahaha) to set this up.
|
30
|
+
|
31
|
+
The TenantInfo information can be a hash or class. It must provide client_id and client_secret.
|
32
|
+
Optionally a domain_hint and tenant_id. For a simple single-tenant app, this could be:
|
33
|
+
( Add this to the ominiauth initializer)
|
34
|
+
```ruby
|
35
|
+
use OmniAuth::Builder do
|
36
|
+
provider :azure_oauth2_v2,
|
37
|
+
{
|
38
|
+
client_id: ENV['AZURE_CLIENT_ID'],
|
39
|
+
client_secret: ENV['AZURE_CLIENT_SECRET'],
|
40
|
+
tenant_id: ENV['AZURE_TENANT_ID']
|
41
|
+
}
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
Next step is create the endpoint in your application that matches to the callback URL and then performs whatever steps are necessary for your application (If you're using devise, this example will work too). Add this line in your routes.rb file:
|
46
|
+
```ruby
|
47
|
+
match '/auth/:provider/callback' => 'sessions#create', via: [:get, :post]
|
48
|
+
````
|
49
|
+
|
50
|
+
if you're using devise, before this you must add:
|
51
|
+
```
|
52
|
+
devise_for :users
|
53
|
+
```
|
54
|
+
|
55
|
+
In some cases for security reasons the provider give acess to specific routes. In this cases, you will need to change your `redirect_uri`:
|
56
|
+
```ruby
|
57
|
+
use OmniAuth::Builder do
|
58
|
+
provider :azure_oauth2_v2,
|
59
|
+
{
|
60
|
+
client_id: ENV['AZURE_CLIENT_ID'],
|
61
|
+
client_secret: ENV['AZURE_CLIENT_SECRET'],
|
62
|
+
tenant_id: ENV['AZURE_TENANT_ID'],
|
63
|
+
redirect_uri: 'http://redirect_path'
|
64
|
+
}
|
65
|
+
end
|
66
|
+
```
|
67
|
+
and add on your routes:
|
68
|
+
```ruby
|
69
|
+
post 'redirect_path': 'sessions#create'
|
70
|
+
```
|
71
|
+
|
72
|
+
After solve the route issues, add `SessionsController` with this code (don't forget to `include AzureAuthRequestHelper and before_action :user_info`)
|
73
|
+
The variable called by `@user_info` will have the response of Azure.
|
74
|
+
|
75
|
+
If `you're not using Devise`:
|
76
|
+
```ruby
|
77
|
+
class SessionsController < ApplicationController
|
78
|
+
include AzureAuthRequestHelper
|
79
|
+
before_action :user_info, only: [:create]
|
80
|
+
def create
|
81
|
+
if @user_info.first == :success
|
82
|
+
@user = User.find_or_create_by(email: @user_info.second['email'].downcase)
|
83
|
+
self.current_user = @user
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
```
|
88
|
+
if `you're using Devise (and needs to sign_in)`, copy this:
|
89
|
+
```ruby
|
90
|
+
class SessionsController < ApplicationController
|
91
|
+
include AzureAuthRequestHelper
|
92
|
+
before_action :user_info, only: [:create]
|
93
|
+
def create
|
94
|
+
if @user_info.first == :success
|
95
|
+
@user = User.find_or_create_by(email: @user_info.second['email'].downcase)
|
96
|
+
sign_in @user
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
```
|
101
|
+
|
102
|
+
For multi-tenant apps where you don't know the tenant_id in advance, simply leave out the tenant_id to use the
|
103
|
+
[common endpoint](http://msdn.microsoft.com/en-us/library/azure/dn645542.aspx).
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
use OmniAuth::Builder do
|
107
|
+
provider :azure_oauth2_v2,
|
108
|
+
{
|
109
|
+
client_id: ENV['AZURE_CLIENT_ID'],
|
110
|
+
client_secret: ENV['AZURE_CLIENT_SECRET']
|
111
|
+
}
|
112
|
+
end
|
113
|
+
```
|
114
|
+
|
115
|
+
For dynamic tenant assignment, pass a class that supports those same attributes and accepts the strategy as a parameter
|
116
|
+
|
117
|
+
```ruby
|
118
|
+
class YouTenantProvider
|
119
|
+
def initialize(strategy)
|
120
|
+
@strategy = strategy
|
121
|
+
end
|
122
|
+
|
123
|
+
def client_id
|
124
|
+
tenant.azure_client_id
|
125
|
+
end
|
126
|
+
|
127
|
+
def client_secret
|
128
|
+
tenant.azure_client_secret
|
129
|
+
end
|
130
|
+
|
131
|
+
def tenant_id
|
132
|
+
tenant.azure_tanant_id
|
133
|
+
end
|
134
|
+
|
135
|
+
def domain_hint
|
136
|
+
tenant.azure_domain_hint
|
137
|
+
end
|
138
|
+
|
139
|
+
private
|
140
|
+
|
141
|
+
def tenant
|
142
|
+
# whatever strategy you want to figure out the right tenant from params/session
|
143
|
+
@tenant ||= Customer.find(@strategy.session[:customer_id])
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
use OmniAuth::Builder do
|
148
|
+
provider :azure_oauth2_v2, YourTenantProvider
|
149
|
+
end
|
150
|
+
```
|
151
|
+
|
152
|
+
The base_azure_url can be overridden in the provider configuration for different locales; e.g. `base_azure_url: "https://login.microsoftonline.de"`
|
153
|
+
|
154
|
+
|
155
|
+
## Auth Hash Schema
|
156
|
+
Hash Schema can be different for differrent scenarios.
|
157
|
+
The following information is provided back to you for the provider (this will set in @user_info):
|
158
|
+
#### Success case
|
159
|
+
```ruby
|
160
|
+
{
|
161
|
+
:sucess,
|
162
|
+
{
|
163
|
+
name: 'some one',
|
164
|
+
first_name: 'some',
|
165
|
+
last_name: 'one',
|
166
|
+
email: 'someone@example.com'
|
167
|
+
}
|
168
|
+
}
|
169
|
+
````
|
170
|
+
#### Error case
|
171
|
+
```ruby
|
172
|
+
{
|
173
|
+
:error,
|
174
|
+
{
|
175
|
+
ErrorHash
|
176
|
+
}
|
177
|
+
}
|
178
|
+
```
|
179
|
+
## Notes
|
180
|
+
|
181
|
+
When you make a request to WAAD you must specify a resource. The gem currently assumes this is the AD identified as '00000002-0000-0000-c000-000000000000'.
|
182
|
+
This can be passed in as part of the config. It currently isn't designed to be dynamic.
|
183
|
+
|
184
|
+
```ruby
|
185
|
+
use OmniAuth::Builder do
|
186
|
+
provider :azure_oauth2_v2, TenantInfo, resource: 'myresource'
|
187
|
+
end
|
188
|
+
```
|
189
|
+
|
190
|
+
## Contributing
|
191
|
+
|
192
|
+
1. Fork it
|
193
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
194
|
+
3. Make your changes, add tests, run tests (`rake`)
|
195
|
+
4. Commit your changes and tests (`git commit -am 'Added some feature'`)
|
196
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
197
|
+
6. Create new Pull Request
|
data/Rakefile
ADDED
data/examples/sinatra.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
$:.push File.dirname(__FILE__) + '/../lib'
|
2
|
+
|
3
|
+
require 'omniauth-azure-oauth2-v3'
|
4
|
+
require 'sinatra'
|
5
|
+
|
6
|
+
class MyAzureProvider
|
7
|
+
def self.client_id
|
8
|
+
ENV['AZURE_CLIENT_ID']
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.client_secret
|
12
|
+
ENV['AZURE_CLIENT_SECRET']
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.tenant_id
|
16
|
+
ENV['AZURE_TENANT_ID']
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
use Rack::Session::Cookie
|
22
|
+
use OmniAuth::Strategies::Azure, MyAzureProvider
|
23
|
+
|
24
|
+
get '/' do
|
25
|
+
"<a href='/auth/azure_oauth2'>Log in with Azure</a>"
|
26
|
+
end
|
27
|
+
|
28
|
+
get '/auth/azure_oauth2/callback' do
|
29
|
+
content_type 'text/plain'
|
30
|
+
request.env['omniauth.auth'].inspect
|
31
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module AzureAuthRequestHelper
|
4
|
+
def user_info
|
5
|
+
host = 'https://graph.microsoft.com/oidc/userinfo'
|
6
|
+
url = URI.parse(host)
|
7
|
+
req = Net::HTTP::Post.new(url.to_s)
|
8
|
+
req['Authorization'] = "Bearer #{params[:access_token]}"
|
9
|
+
response = Net::HTTP.start(url.host, url.port, use_ssl: true) do |http|
|
10
|
+
http.request(req)
|
11
|
+
end
|
12
|
+
@user_info = case response.code
|
13
|
+
when '400'
|
14
|
+
[ :error, JSON.parse(response.body.to_str) ]
|
15
|
+
when '200'
|
16
|
+
[ :success, JSON.parse(response.body.to_str) ]
|
17
|
+
else
|
18
|
+
[:error, "Invalid response #{response.body.to_str} received."]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.join('omniauth', 'strategies', 'azure_oauth2_v2')
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'omniauth/strategies/oauth2'
|
2
|
+
require 'jwt'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
class AzureOauth2V2 < OmniAuth::Strategies::OAuth2
|
7
|
+
BASE_AZURE_URL = 'https://login.microsoftonline.com'
|
8
|
+
option :name, 'azure_oauth2'
|
9
|
+
option :scope, 'openid profile email offline_access https://graph.microsoft.com/mail.read'
|
10
|
+
|
11
|
+
option :tenant_provider, nil
|
12
|
+
|
13
|
+
# AD resource identifier
|
14
|
+
option :resource, '00000002-0000-0000-c000-000000000000'
|
15
|
+
|
16
|
+
# tenant_provider must return client_id, client_secret and optionally tenant_id and base_azure_url
|
17
|
+
args [:tenant_provider]
|
18
|
+
|
19
|
+
def client
|
20
|
+
if options.tenant_provider
|
21
|
+
provider = options.tenant_provider.new(self)
|
22
|
+
else
|
23
|
+
provider = options # if pass has to config, get mapped right on to options
|
24
|
+
end
|
25
|
+
|
26
|
+
options.client_id = provider.client_id
|
27
|
+
options.client_secret = provider.client_secret
|
28
|
+
options.tenant_id =
|
29
|
+
provider.respond_to?(:tenant_id) ? provider.tenant_id : 'common'
|
30
|
+
options.base_azure_url =
|
31
|
+
provider.respond_to?(:base_azure_url) ? provider.base_azure_url : BASE_AZURE_URL
|
32
|
+
options.uid_claim = provider.respond_to?(:uid_claim) ? provider.uid_claim : 'sub'
|
33
|
+
options.authorize_params.scope = 'openid profile email offline_access https://graph.microsoft.com/mail.read'
|
34
|
+
options.authorize_params.redirect_uri = provider.redirect_uri if provider.respond_to?(:redirect_uri)
|
35
|
+
options.authorize_params.response_mode = 'form_post'
|
36
|
+
options.authorize_params.response_type = "token"
|
37
|
+
options.authorize_params = provider.authorize_params if provider.respond_to?(:authorize_params)
|
38
|
+
options.authorize_params.domain_hint = provider.domain_hint if provider.respond_to?(:domain_hint) && provider.domain_hint
|
39
|
+
options.authorize_params.prompt = request.params['prompt'] if defined? request && request.params['prompt']
|
40
|
+
options.client_options.authorize_url = "#{options.base_azure_url}/#{options.tenant_id}/oauth2/v2.0/authorize"
|
41
|
+
super
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path(File.join('..', 'lib', 'omniauth', 'azure_oauth2_v2', 'version'), __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Marcelo Guimarães"]
|
6
|
+
gem.email = ["marceloguimaraesti@gmail.com"]
|
7
|
+
gem.description = %q{An Windows Azure Active Directory OAuth2 2.0v strategy for OmniAuth}
|
8
|
+
gem.summary = %q{An Windows Azure Active Directory OAuth2 2.0v strategy for OmniAuth}
|
9
|
+
gem.homepage = "https://github.com/MarceloAGuimaraes/omniauth-azure-oauth2-v2"
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {spec}/*`.split("\n")
|
14
|
+
gem.name = "omniauth-azure-oauth2-v2"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = OmniAuth::AzureOauth2V2::VERSION
|
17
|
+
gem.license = "MIT"
|
18
|
+
|
19
|
+
gem.add_dependency 'omniauth', '~> 1.0'
|
20
|
+
gem.add_dependency 'jwt', ['>= 1.0', '< 3.0']
|
21
|
+
|
22
|
+
gem.add_runtime_dependency 'omniauth-oauth2', '~> 1.4'
|
23
|
+
|
24
|
+
gem.add_development_dependency 'rspec', '>= 2.14.0'
|
25
|
+
gem.add_development_dependency 'rake'
|
26
|
+
end
|
@@ -0,0 +1,259 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'omniauth-azure-oauth2-v2'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
module JWT; end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe OmniAuth::Strategies::AzureOauth2V2 do
|
11
|
+
let(:request) { double('Request', :params => {}, :cookies => {}, :env => {}) }
|
12
|
+
let(:app) {
|
13
|
+
lambda do
|
14
|
+
[200, {}, ["Hello."]]
|
15
|
+
end
|
16
|
+
}
|
17
|
+
|
18
|
+
before do
|
19
|
+
OmniAuth.config.test_mode = true
|
20
|
+
end
|
21
|
+
|
22
|
+
after do
|
23
|
+
OmniAuth.config.test_mode = false
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'static configuration' do
|
27
|
+
let(:options) { @options || {} }
|
28
|
+
subject do
|
29
|
+
OmniAuth::Strategies::AzureOauth2V2.new(app, {client_id: 'id', client_secret: 'secret', tenant_id: 'tenant'}.merge(options))
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#client' do
|
33
|
+
it 'has correct authorize url' do
|
34
|
+
allow(subject).to receive(:request) { request }
|
35
|
+
expect(subject.client.options[:authorize_url]).to eql('https://login.microsoftonline.com/tenant/oauth2/v2.0/authorize')
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'has correct authorize params' do
|
39
|
+
allow(subject).to receive(:request) { request }
|
40
|
+
subject.client
|
41
|
+
expect(subject.authorize_params[:domain_hint]).to be_nil
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "overrides" do
|
45
|
+
it 'should override domain_hint' do
|
46
|
+
@options = {domain_hint: 'hint'}
|
47
|
+
allow(subject).to receive(:request) { request }
|
48
|
+
subject.client
|
49
|
+
expect(subject.authorize_params[:domain_hint]).to eql('hint')
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
describe 'static configuration - german' do
|
57
|
+
let(:options) { @options || {} }
|
58
|
+
subject do
|
59
|
+
OmniAuth::Strategies::AzureOauth2V2.new(app, {client_id: 'id', client_secret: 'secret', tenant_id: 'tenant', base_azure_url: 'https://login.microsoftonline.de'}.merge(options))
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#client' do
|
63
|
+
it 'has correct authorize url' do
|
64
|
+
allow(subject).to receive(:request) { request }
|
65
|
+
expect(subject.client.options[:authorize_url]).to eql('https://login.microsoftonline.de/tenant/oauth2/v2.0/authorize')
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'has correct authorize params' do
|
69
|
+
allow(subject).to receive(:request) { request }
|
70
|
+
subject.client
|
71
|
+
expect(subject.authorize_params[:domain_hint]).to be_nil
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "overrides" do
|
75
|
+
it 'should override domain_hint' do
|
76
|
+
@options = {domain_hint: 'hint'}
|
77
|
+
allow(subject).to receive(:request) { request }
|
78
|
+
subject.client
|
79
|
+
expect(subject.authorize_params[:domain_hint]).to eql('hint')
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe 'static common configuration' do
|
86
|
+
let(:options) { @options || {} }
|
87
|
+
subject do
|
88
|
+
OmniAuth::Strategies::AzureOauth2V2.new(app, {client_id: 'id', client_secret: 'secret'}.merge(options))
|
89
|
+
end
|
90
|
+
|
91
|
+
before do
|
92
|
+
allow(subject).to receive(:request) { request }
|
93
|
+
end
|
94
|
+
|
95
|
+
describe '#client' do
|
96
|
+
it 'has correct authorize url' do
|
97
|
+
expect(subject.client.options[:authorize_url]).to eql('https://login.microsoftonline.com/common/oauth2/v2.0/authorize')
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe 'dynamic configuration' do
|
103
|
+
let(:provider_klass) {
|
104
|
+
Class.new {
|
105
|
+
def initialize(strategy)
|
106
|
+
end
|
107
|
+
|
108
|
+
def client_id
|
109
|
+
'id'
|
110
|
+
end
|
111
|
+
|
112
|
+
def client_secret
|
113
|
+
'secret'
|
114
|
+
end
|
115
|
+
|
116
|
+
def tenant_id
|
117
|
+
'tenant'
|
118
|
+
end
|
119
|
+
|
120
|
+
def authorize_params
|
121
|
+
{ custom_option: 'value' }
|
122
|
+
end
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
126
|
+
subject do
|
127
|
+
OmniAuth::Strategies::AzureOauth2V2.new(app, provider_klass)
|
128
|
+
end
|
129
|
+
|
130
|
+
before do
|
131
|
+
allow(subject).to receive(:request) { request }
|
132
|
+
end
|
133
|
+
|
134
|
+
describe '#client' do
|
135
|
+
it 'has correct authorize url' do
|
136
|
+
expect(subject.client.options[:authorize_url]).to eql('https://login.microsoftonline.com/tenant/oauth2/v2.0/authorize')
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'has correct authorize params' do
|
140
|
+
subject.client
|
141
|
+
expect(subject.authorize_params[:domain_hint]).to be_nil
|
142
|
+
expect(subject.authorize_params[:custom_option]).to eql('value')
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
describe 'dynamic configuration - german' do
|
149
|
+
let(:provider_klass) {
|
150
|
+
Class.new {
|
151
|
+
def initialize(strategy)
|
152
|
+
end
|
153
|
+
|
154
|
+
def client_id
|
155
|
+
'id'
|
156
|
+
end
|
157
|
+
|
158
|
+
def client_secret
|
159
|
+
'secret'
|
160
|
+
end
|
161
|
+
|
162
|
+
def tenant_id
|
163
|
+
'tenant'
|
164
|
+
end
|
165
|
+
|
166
|
+
def base_azure_url
|
167
|
+
'https://login.microsoftonline.de'
|
168
|
+
end
|
169
|
+
}
|
170
|
+
}
|
171
|
+
|
172
|
+
subject do
|
173
|
+
OmniAuth::Strategies::AzureOauth2V2.new(app, provider_klass)
|
174
|
+
end
|
175
|
+
|
176
|
+
before do
|
177
|
+
allow(subject).to receive(:request) { request }
|
178
|
+
end
|
179
|
+
|
180
|
+
describe '#client' do
|
181
|
+
it 'has correct authorize url' do
|
182
|
+
expect(subject.client.options[:authorize_url]).to eql('https://login.microsoftonline.de/tenant/oauth2/v2.0/authorize')
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'has correct authorize params' do
|
186
|
+
subject.client
|
187
|
+
expect(subject.authorize_params[:domain_hint]).to be_nil
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
describe 'dynamic common configuration' do
|
193
|
+
let(:provider_klass) {
|
194
|
+
Class.new {
|
195
|
+
def initialize(strategy)
|
196
|
+
end
|
197
|
+
|
198
|
+
def client_id
|
199
|
+
'id'
|
200
|
+
end
|
201
|
+
|
202
|
+
def client_secret
|
203
|
+
'secret'
|
204
|
+
end
|
205
|
+
}
|
206
|
+
}
|
207
|
+
|
208
|
+
subject do
|
209
|
+
OmniAuth::Strategies::AzureOauth2V2.new(app, provider_klass)
|
210
|
+
end
|
211
|
+
|
212
|
+
before do
|
213
|
+
allow(subject).to receive(:request) { request }
|
214
|
+
end
|
215
|
+
|
216
|
+
describe '#client' do
|
217
|
+
it 'has correct authorize url' do
|
218
|
+
expect(subject.client.options[:authorize_url]).to eql('https://login.microsoftonline.com/common/oauth2/v2.0/authorize')
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
describe "raw_info" do
|
224
|
+
subject do
|
225
|
+
OmniAuth::Strategies::AzureOauth2V2.new(app, {client_id: 'id', client_secret: 'secret'})
|
226
|
+
end
|
227
|
+
|
228
|
+
let(:token) do
|
229
|
+
JWT.encode({"some" => "payload"}, "secret")
|
230
|
+
end
|
231
|
+
|
232
|
+
let(:access_token) do
|
233
|
+
double(:token => token)
|
234
|
+
end
|
235
|
+
|
236
|
+
before do
|
237
|
+
allow(subject).to receive(:access_token) { access_token }
|
238
|
+
allow(subject).to receive(:request) { request }
|
239
|
+
end
|
240
|
+
|
241
|
+
it "does not clash if JWT strategy is used" do
|
242
|
+
expect do
|
243
|
+
subject.info
|
244
|
+
end.to_not raise_error
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
describe 'token_params' do
|
249
|
+
let(:strategy) { OmniAuth::Strategies::AzureOauth2V2.new(app, client_id: 'id', client_secret: 'secret') }
|
250
|
+
let(:request) { double('Request', env: env) }
|
251
|
+
let(:env) { {} }
|
252
|
+
|
253
|
+
subject { strategy.token_params }
|
254
|
+
|
255
|
+
before { allow(strategy).to receive(:request).and_return request }
|
256
|
+
|
257
|
+
it { is_expected.to be_a OmniAuth::Strategy::Options }
|
258
|
+
end
|
259
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-azure-oauth2-v2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marcelo Guimarães
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-09-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: omniauth
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: jwt
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '3.0'
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '1.0'
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '3.0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: omniauth-oauth2
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.4'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '1.4'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rspec
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 2.14.0
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 2.14.0
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rake
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
description: An Windows Azure Active Directory OAuth2 2.0v strategy for OmniAuth
|
90
|
+
email:
|
91
|
+
- marceloguimaraesti@gmail.com
|
92
|
+
executables: []
|
93
|
+
extensions: []
|
94
|
+
extra_rdoc_files: []
|
95
|
+
files:
|
96
|
+
- ".gitignore"
|
97
|
+
- ".travis.yml"
|
98
|
+
- CHANGELOG.md
|
99
|
+
- Gemfile
|
100
|
+
- README.md
|
101
|
+
- Rakefile
|
102
|
+
- examples/sinatra.rb
|
103
|
+
- lib/omniauth-azure-oauth2-v2.rb
|
104
|
+
- lib/omniauth/azure_auth_request_helper.rb
|
105
|
+
- lib/omniauth/azure_oauth2_v2.rb
|
106
|
+
- lib/omniauth/azure_oauth2_v2/version.rb
|
107
|
+
- lib/omniauth/strategies/azure_oauth2_v2.rb
|
108
|
+
- omniauth-azure-oauth2-v2.gemspec
|
109
|
+
- spec/omniauth/strategies/azure_oauth2_v2_spec.rb
|
110
|
+
- spec/spec_helper.rb
|
111
|
+
homepage: https://github.com/MarceloAGuimaraes/omniauth-azure-oauth2-v2
|
112
|
+
licenses:
|
113
|
+
- MIT
|
114
|
+
metadata: {}
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
requirements: []
|
130
|
+
rubygems_version: 3.0.6
|
131
|
+
signing_key:
|
132
|
+
specification_version: 4
|
133
|
+
summary: An Windows Azure Active Directory OAuth2 2.0v strategy for OmniAuth
|
134
|
+
test_files: []
|