omniauth-azure-oauth2 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 277d288ce60567e9f3dd948e30a53ff4241b2238
4
+ data.tar.gz: 5b3a6edccbf4217230e55965cf7bce245a2faa62
5
+ SHA512:
6
+ metadata.gz: 0285ebc4357800e6c8fb9a075a8f9f767dbe372329912832f75035a24a4ab6b1ba17f6e0995b5576d431721f289ab326c97fa41115338b3ded5b2d5ef9e082bf
7
+ data.tar.gz: 32b6b1e9d5a822b823d2b024fec4f28e946a214f1276b1fa25820e282a42cc49f32f56ab456f97e60cfea4f9fc8ae3aa626081f344da33b5d9767aff913f3dc8
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .ruby-gemset
7
+ .ruby-version
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # VERSION 0.0.1
2
+
3
+ * Initial build
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-azure-oauth2.gemspec
4
+ gemspec
5
+
6
+ group :example do
7
+ gem 'sinatra'
8
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Deltek
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,121 @@
1
+ # OmniAuth 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.
4
+
5
+ One of the unique challenges of WAAD OAuth is that WAAD is multi tenant. Any given tenant can have multiple active
6
+ directories. The CLIENT-ID, REPLY-URL and keys will be unique to the tenant/AD/application combination. This gem simply
7
+ provides hooks for determining those unique values for each call.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'omniauth-azure-oauth2'
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ First, you will need to add your site as an application in WAAD.:
20
+ [Adding, Updating, and Removing an Application](http://msdn.microsoft.com/en-us/library/azure/dn132599.aspx)
21
+
22
+ Summary:
23
+ Select your Active Directory in https://manage.windowsazure.com/<tenantid> of type 'Web Application'. Name, sign-on url,
24
+ logo are not important. You will need the CLIENT-ID from the application configuration and you will need to generate
25
+ an expiring key (aka 'client secret'). REPLY URL is the oauth redirect uri which will be the omniauth callback path
26
+ https://example.com/users/auth/azure_oauth2/callback. The APP ID UI just needs to be unique to that tenant and identify
27
+ your site and isn't needed to configure the gem.
28
+ Permissions need Delegated Permissions to at least have "Enable sign-on and read user's profiles".
29
+
30
+ Note: Seems like the terminology is still fluid, so follow the MS guidance (buwahaha) to set this up.
31
+
32
+ The TenantInfo information can be a hash or class. It must provide client_id, client_secret and tenant_id.
33
+ Optionally a domain_hint. For a simple single-tenant app, this could be:
34
+
35
+ ```ruby
36
+ use OmniAuth::Builder do
37
+ provider :azure_oauth2,
38
+ {
39
+ client_id: ENV['AZURE_CLIENT_ID'],
40
+ client_secret: ENV['AZURE_CLIENT_ID'],
41
+ tenant_id: ENV['AZURE_TENANT_ID']
42
+ }
43
+ end
44
+ ```
45
+
46
+ For dynamic tenant assignment, pass a class that supports those same attributes and accepts the strategy as a parameter
47
+
48
+ ```ruby
49
+ class YouTenantProvider
50
+ def initialize(strategy)
51
+ @strategy = strategy
52
+ end
53
+
54
+ def client_id
55
+ tenant.azure_client_id
56
+ end
57
+
58
+ def client_secret
59
+ tenant.azure_client_secret
60
+ end
61
+
62
+ def tenant_id
63
+ tenant.azure_tanant_id
64
+ end
65
+
66
+ def domain_hint
67
+ tenant.azure_domain_hint
68
+ end
69
+
70
+ private
71
+
72
+ def tenant
73
+ # whatever strategy you want to figure out the right tenant from params/session
74
+ @tenant ||= Customer.find(@strategy.session[:customer_id])
75
+ end
76
+ end
77
+
78
+ use OmniAuth::Builder do
79
+ provider :azure_oauth2, YourTenantProvider
80
+ end
81
+ ```
82
+
83
+ ## Auth Hash Schema
84
+
85
+ The following information is provided back to you for this provider:
86
+
87
+ ```ruby
88
+ {
89
+ uid: '12345',
90
+ info: {
91
+ name: 'some one',
92
+ first_name: 'some',
93
+ last_name: 'one',
94
+ email: 'someone@example.com'
95
+ },
96
+ credentials: {
97
+ token: 'thetoken',
98
+ refresh_token: 'refresh'
99
+ },
100
+ extra: { raw_info: raw_api_response }
101
+ }
102
+ ```
103
+ ## notes
104
+
105
+ 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'.
106
+ This can be passed in as part of the config. It currently isn't designed to be dynamic.
107
+
108
+ ```ruby
109
+ use OmniAuth::Builder do
110
+ provider :azure_oauth2, TenantInfo, resource: 'myresource'
111
+ end
112
+ ```
113
+
114
+ ## Contributing
115
+
116
+ 1. Fork it
117
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
118
+ 3. Make your changes, add tests, run tests (`rake`)
119
+ 4. Commit your changes and tests (`git commit -am 'Added some feature'`)
120
+ 5. Push to the branch (`git push origin my-new-feature`)
121
+ 6. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require File.join('bundler', 'gem_tasks')
2
+ require File.join('rspec', 'core', 'rake_task')
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,31 @@
1
+ $:.push File.dirname(__FILE__) + '/../lib'
2
+
3
+ require 'omniauth-azure-oauth2'
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 @@
1
+ require File.join('omniauth', 'azure_oauth2')
@@ -0,0 +1 @@
1
+ require File.join('omniauth', 'strategies', 'azure_oauth2')
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module AzureOauth2
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
@@ -0,0 +1,59 @@
1
+ require 'omniauth/strategies/oauth2'
2
+ require 'jwt'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class AzureOauth2 < OmniAuth::Strategies::OAuth2
7
+ BASE_AZURE_URL = 'https://login.windows.net'
8
+
9
+ option :name, 'azure_oauth2'
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, tenant_id
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 ptions
24
+ end
25
+
26
+ options.client_id = provider.client_id
27
+ options.client_secret = provider.client_secret
28
+ options.tenant_id = provider.tenant_id
29
+
30
+ options.authorize_params.domain_hint = provider.domain_hint if provider.respond_to?(:domain_hint) && provider.domain_hint
31
+ options.client_options.authorize_url = "#{BASE_AZURE_URL}/#{options.tenant_id}/oauth2/authorize"
32
+ options.client_options.token_url = "#{BASE_AZURE_URL}/#{options.tenant_id}/oauth2/token"
33
+
34
+ options.token_params.resource = options.resource
35
+ super
36
+ end
37
+
38
+ uid {
39
+ raw_info['sub']
40
+ }
41
+
42
+ info do
43
+ {
44
+ name: raw_info['unique_name'],
45
+ first_name: raw_info['given_name'],
46
+ last_name: raw_info['family_name'],
47
+ email: raw_info['email'] || raw_info['upn']
48
+ }
49
+ end
50
+
51
+
52
+ def raw_info
53
+ # it's all here in JWT http://msdn.microsoft.com/en-us/library/azure/dn195587.aspx
54
+ @raw_info ||= JWT.decode(access_token.token, nil, false)
55
+ end
56
+
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path(File.join('..', 'lib', 'omniauth', 'azure_oauth2', 'version'), __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Mark Nadig"]
6
+ gem.email = ["mark@nadigs.net"]
7
+ gem.description = %q{An Windows Azure Active Directory OAuth2 strategy for OmniAuth}
8
+ gem.summary = %q{An Windows Azure Active Directory OAuth2 strategy for OmniAuth}
9
+ gem.homepage = "https://github.com/KonaTeam/omniauth-azure-oauth2"
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"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = OmniAuth::AzureOauth2::VERSION
17
+ gem.license = "MIT"
18
+
19
+ gem.add_dependency 'omniauth', '~> 1.0'
20
+ gem.add_dependency 'jwt', '~> 0.1'
21
+
22
+ gem.add_runtime_dependency 'omniauth-oauth2', '~> 1.1'
23
+
24
+ gem.add_development_dependency 'rspec', '>= 2.14.0'
25
+ gem.add_development_dependency 'rake'
26
+ end
@@ -0,0 +1,112 @@
1
+ require 'spec_helper'
2
+ require 'omniauth-azure-oauth2'
3
+
4
+ describe OmniAuth::Strategies::AzureOauth2 do
5
+ let(:request) { double('Request', :params => {}, :cookies => {}, :env => {}) }
6
+ let(:app) {
7
+ lambda do
8
+ [200, {}, ["Hello."]]
9
+ end
10
+ }
11
+
12
+ before do
13
+ OmniAuth.config.test_mode = true
14
+ end
15
+
16
+ after do
17
+ OmniAuth.config.test_mode = false
18
+ end
19
+
20
+ describe 'static configuration' do
21
+ let(:options) { @options || {} }
22
+ subject do
23
+ OmniAuth::Strategies::AzureOauth2.new(app, {client_id: 'id', client_secret: 'secret', tenant_id: 'tenant'}.merge(options))
24
+ end
25
+
26
+ describe '#client' do
27
+ it 'has correct authorize url' do
28
+ expect(subject.client.options[:authorize_url]).to eql('https://login.windows.net/tenant/oauth2/authorize')
29
+ end
30
+
31
+ it 'has correct authorize params' do
32
+ subject.client
33
+ expect(subject.authorize_params[:domain_hint]).to be_nil
34
+ end
35
+
36
+ it 'has correct token url' do
37
+ expect(subject.client.options[:token_url]).to eql('https://login.windows.net/tenant/oauth2/token')
38
+ end
39
+
40
+ it 'has correct token params' do
41
+ subject.client
42
+ expect(subject.token_params[:resource]).to eql('00000002-0000-0000-c000-000000000000')
43
+ end
44
+
45
+ describe "overrides" do
46
+ it 'should override domain_hint' do
47
+ @options = {domain_hint: 'hint'}
48
+ subject.client
49
+ expect(subject.authorize_params[:domain_hint]).to eql('hint')
50
+ end
51
+ end
52
+ end
53
+
54
+ end
55
+
56
+
57
+ describe 'dynamic configuration' do
58
+ let(:provider_klass) {
59
+ Class.new {
60
+ def initialize(strategy)
61
+ end
62
+
63
+ def client_id
64
+ 'id'
65
+ end
66
+
67
+ def client_secret
68
+ 'secret'
69
+ end
70
+
71
+ def tenant_id
72
+ 'tenant'
73
+ end
74
+
75
+ }
76
+ }
77
+
78
+ subject do
79
+ OmniAuth::Strategies::AzureOauth2.new(app, provider_klass)
80
+ end
81
+
82
+ describe '#client' do
83
+ it 'has correct authorize url' do
84
+ expect(subject.client.options[:authorize_url]).to eql('https://login.windows.net/tenant/oauth2/authorize')
85
+ end
86
+
87
+ it 'has correct authorize params' do
88
+ subject.client
89
+ expect(subject.authorize_params[:domain_hint]).to be_nil
90
+ end
91
+
92
+ it 'has correct token url' do
93
+ expect(subject.client.options[:token_url]).to eql('https://login.windows.net/tenant/oauth2/token')
94
+ end
95
+
96
+ it 'has correct token params' do
97
+ subject.client
98
+ expect(subject.token_params[:resource]).to eql('00000002-0000-0000-c000-000000000000')
99
+ end
100
+
101
+ # todo: how to get this working?
102
+ # describe "overrides" do
103
+ # it 'should override domain_hint' do
104
+ # provider_klass.domain_hint = 'hint'
105
+ # subject.client
106
+ # expect(subject.authorize_params[:domain_hint]).to eql('hint')
107
+ # end
108
+ # end
109
+ end
110
+
111
+ end
112
+ end
@@ -0,0 +1,2 @@
1
+ require File.join('bundler', 'setup')
2
+ require 'rspec'
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-azure-oauth2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Mark Nadig
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-31 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: '0.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '0.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: omniauth-oauth2
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 2.14.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: 2.14.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: An Windows Azure Active Directory OAuth2 strategy for OmniAuth
84
+ email:
85
+ - mark@nadigs.net
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - CHANGELOG.md
92
+ - Gemfile
93
+ - LICENSE
94
+ - README.md
95
+ - Rakefile
96
+ - examples/sinatra.rb
97
+ - lib/omniauth-azure-oauth2.rb
98
+ - lib/omniauth/azure_oauth2.rb
99
+ - lib/omniauth/azure_oauth2/version.rb
100
+ - lib/omniauth/strategies/azure_oauth2.rb
101
+ - omniauth-azure-oauth2.gemspec
102
+ - spec/omniauth/strategies/azure_oauth2_spec.rb
103
+ - spec/spec_helper.rb
104
+ homepage: https://github.com/KonaTeam/omniauth-azure-oauth2
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.2.2
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: An Windows Azure Active Directory OAuth2 strategy for OmniAuth
128
+ test_files: []