omniauth-elitmus 0.0.3
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 +15 -0
- data/.travis.yml +7 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +22 -0
- data/README.md +126 -0
- data/Rakefile +2 -0
- data/lib/omniauth-elitmus.rb +1 -0
- data/lib/omniauth/elitmus.rb +2 -0
- data/lib/omniauth/elitmus/version.rb +5 -0
- data/lib/omniauth/strategies/elitmus.rb +61 -0
- data/omniauth-elitmus.gemspec +25 -0
- data/test/helper.rb +62 -0
- data/test/support/shared_example.rb +85 -0
- data/test/test.rb +255 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5a61135ea30aa7e31fee8b6148f523528ce3b1f2
|
4
|
+
data.tar.gz: d67c251b4c8919dac678f917bf7b3d5549999169
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 36a77f728fffc6a111902dff01b54c7158626e4516c74d400fa9df58266d0a6fd799f4185f5369471624060c0487327e4b803f593d068a4012f73e362f353046
|
7
|
+
data.tar.gz: f9d7de27c351439796d13a6327e0df586873158e857cbeded5d2a07334ace85fb8c05d4919b8773c171d3cabe2d5e14fcf77f9ae6a26fcb64e3ad153b2f1e468
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Shrey Patel
|
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,126 @@
|
|
1
|
+
# Omniauth Elitmus
|
2
|
+
|
3
|
+
[](https://travis-ci.org/elitmus/omniauth-elitmus)
|
4
|
+
|
5
|
+
[](https://codeclimate.com/github/elitmus/omniauth-elitmus)
|
6
|
+
|
7
|
+
[](https://codeclimate.com/github/elitmus/omniauth-elitmus)
|
8
|
+
|
9
|
+
[](http://badge.fury.io/rb/omniauth-elitmus)
|
10
|
+
|
11
|
+
## eLitmus OAuth2 Strategy for OmniAuth
|
12
|
+
|
13
|
+
This is official OmniAuth strategy for authenticating to eLitmus.com. To use it, you'll need to register your consumer application on elitmus.com to get pair of OAuth2 Application ID and Secret. It supports the OAuth 2.0 server-side and client-side flows for 3rd party OAuth consumer applications
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'omniauth-elitmus'
|
21
|
+
```
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
$ bundle
|
26
|
+
|
27
|
+
Or install it yourself as:
|
28
|
+
|
29
|
+
$ gem install omniauth-elitmus
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
OmniAuth::Strategies::Elitmus is simply a Rack middleware.
|
34
|
+
|
35
|
+
First, register your application at 'www.elitmus.com/oauth/applications' with valid callback url to get app_id and secret (elitmus.com uses callback url to redirect to your app). Create environement variables 'ELITMUS_KEY', 'ELITMUS_SECRET' to store your app_id, secret respectively. Here's a quick example, adding the middleware to a Rails app in config/initializers/omniauth.rb.
|
36
|
+
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
40
|
+
provider :elitmus, ENV['ELITMUS_KEY'], ENV['ELITMUS_SECRET']
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
## Configuration
|
45
|
+
|
46
|
+
You can configure several options, which you can pass in to the `provider` method via a `Hash`. also refer 'Examples' section accordingly.
|
47
|
+
|
48
|
+
Option name | Default | Explanation
|
49
|
+
--- | --- | ---
|
50
|
+
`scope` | `public` | lets you set scope to provide granular access to different types of data. If not provided, scope defaults to 'public' for users. you can use any one of "write", "public" and "admin" values for scope.
|
51
|
+
`auth_type` | nil | Optionally specifies the requested authentication feature. Valid value is 'reauthenticate' (asks the user to re-authenticate unconditionally). If not specified, default value is nil. (reuses the existing session of last authenticated user if any).
|
52
|
+
`callback_path` | '/auth/:provider/callback' | Specify a custom callback URL used during the server-side flow. Note this must be same as specified at the time of your applicaiton registration at www.elitmus.com/oauth/applications. Execution flow returns back to this point at consumer application after authencitcation flow finishes at server-side. If not specified, default is '/auth/:provider/callback'. Make an entry for this end point in config/routes.rb of your consumer application. Strategy automatically replaces ':provider' by provider name as specified in config/initializers/omniauth.rb.
|
53
|
+
|
54
|
+
### Examples
|
55
|
+
|
56
|
+
#### scope
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
60
|
+
provider :elitmus, ENV['ELITMUS_KEY'], ENV['ELITMUS_SECRET'], { :scope => "admin" }
|
61
|
+
end
|
62
|
+
```
|
63
|
+
If not specified, default scope is 'public'
|
64
|
+
|
65
|
+
#### auth_type
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
69
|
+
provider :elitmus, ENV['ELITMUS_KEY'], ENV['ELITMUS_SECRET'],
|
70
|
+
{ :scope => "admin", :authorize_params => { :auth_type => "reauthenticate" }}
|
71
|
+
end
|
72
|
+
```
|
73
|
+
If not specified, default is nil.
|
74
|
+
|
75
|
+
#### callback_path
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
79
|
+
provider :elitmus, ENV['ELITMUS_KEY'], ENV['ELITMUS_SECRET'],
|
80
|
+
{ :scope => "admin", :authorize_params => { :auth_type => "reauthenticate" },
|
81
|
+
:callback_path => '/your/custom/callback/path'}
|
82
|
+
end
|
83
|
+
```
|
84
|
+
If not specified, default callback_path is '/auth/:provider/callback'.Here, finally it would be '/auth/elitmus/callback' as per explained in configuration table.
|
85
|
+
|
86
|
+
## Auth Hash
|
87
|
+
|
88
|
+
Here's an example *Auth Hash* available in `request.env['omniauth.auth']`:
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
{
|
92
|
+
:provider => 'elitmus',
|
93
|
+
:uid => '98979695',
|
94
|
+
:info => {
|
95
|
+
:email => 'kishoredaa@evergreen.com',
|
96
|
+
:name => 'Kishore Kumar'
|
97
|
+
},
|
98
|
+
:credentials => {
|
99
|
+
:token => 'ABCDEF...', # OAuth 2.0 access_token, which you may wish to store
|
100
|
+
:expires_at => 1321747205, # when the access token expires (it always will)
|
101
|
+
:expires => true # this will always be true
|
102
|
+
},
|
103
|
+
:extra => {
|
104
|
+
:raw_info => {
|
105
|
+
:id => '98979695',
|
106
|
+
:channel => 'Through a friend',
|
107
|
+
:email => 'kishoredaa@evergreen.com',
|
108
|
+
:name => 'Kishore Kumar'
|
109
|
+
:email_lower => 'kishoredaa@evergreen.com',
|
110
|
+
:first_login => 'Y',
|
111
|
+
:registered_on => '2012-01-17T00:37:29+05:30',
|
112
|
+
:source_campus => '0',
|
113
|
+
:status => 'active'
|
114
|
+
}
|
115
|
+
}
|
116
|
+
}
|
117
|
+
```
|
118
|
+
|
119
|
+
|
120
|
+
## Contributing
|
121
|
+
|
122
|
+
1. Fork it ( https://github.com/[my-github-username]/omniauth-elitmus/fork )
|
123
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
124
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
125
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
126
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'omniauth/elitmus'
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'omniauth/strategies/oauth2'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
class Elitmus < OmniAuth::Strategies::OAuth2
|
7
|
+
# class NoAuthorizationCodeError < StandardError; en
|
8
|
+
DEFAULT_SCOPE = 'public'
|
9
|
+
|
10
|
+
#OATUH2_PROVIDER_URL = "https://www.elitmus.com"
|
11
|
+
option :name, :elitmus
|
12
|
+
|
13
|
+
option :client_options, {
|
14
|
+
:site => "https://www.elitmus.com"
|
15
|
+
}
|
16
|
+
|
17
|
+
option :authorize_options, [:scope, :auth_type]
|
18
|
+
|
19
|
+
uid { raw_info['id'] }
|
20
|
+
|
21
|
+
info do
|
22
|
+
prune!({
|
23
|
+
'email' => raw_info['email'],
|
24
|
+
'name' => raw_info['name']
|
25
|
+
})
|
26
|
+
end
|
27
|
+
|
28
|
+
extra do
|
29
|
+
hash = {}
|
30
|
+
hash['raw_info'] = raw_info unless skip_info?
|
31
|
+
prune! hash
|
32
|
+
end
|
33
|
+
|
34
|
+
def raw_info
|
35
|
+
@raw_info ||= access_token.get('/api/v1/me').parsed
|
36
|
+
end
|
37
|
+
|
38
|
+
def authorize_params
|
39
|
+
super.tap do |params|
|
40
|
+
%w[scope auth_type].each do |v|
|
41
|
+
if request.params[v]
|
42
|
+
params[v.to_sym] = request.params[v]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
params[:scope] ||= DEFAULT_SCOPE
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def callback_url
|
50
|
+
options[:callback_url] || super
|
51
|
+
end
|
52
|
+
|
53
|
+
def prune!(hash)
|
54
|
+
hash.delete_if do |_, value|
|
55
|
+
prune!(value) if value.is_a?(Hash)
|
56
|
+
value.nil? || (value.respond_to?(:empty?) && value.empty?)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'omniauth/elitmus/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "omniauth-elitmus"
|
7
|
+
spec.version = Omniauth::Elitmus::VERSION
|
8
|
+
spec.authors = ["Shrey Patel","Shireesh Jayashetty"]
|
9
|
+
spec.email = ["aws@elitmus.com"]
|
10
|
+
spec.summary = 'eLitmus OAuth2 Strategy for OmniAuth'
|
11
|
+
spec.homepage = "https://github.com/elitmus/omniauth-elitmus"
|
12
|
+
spec.license = "MIT"
|
13
|
+
|
14
|
+
spec.files = `git ls-files`.split("\n")
|
15
|
+
spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
spec.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_runtime_dependency 'omniauth-oauth2', '~> 1.2'
|
20
|
+
|
21
|
+
spec.add_development_dependency 'minitest', '~> 5.5.1'
|
22
|
+
spec.add_development_dependency 'mocha', '~>1.1.0'
|
23
|
+
spec.add_development_dependency 'rake'
|
24
|
+
spec.add_development_dependency 'simplecov'
|
25
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'mocha/setup'
|
4
|
+
require "codeclimate-test-reporter"
|
5
|
+
CodeClimate::TestReporter.start
|
6
|
+
|
7
|
+
require 'simplecov'
|
8
|
+
SimpleCov.start
|
9
|
+
|
10
|
+
require 'omniauth/strategies/elitmus'
|
11
|
+
|
12
|
+
OmniAuth.config.test_mode = true
|
13
|
+
|
14
|
+
module BlockTestHelper
|
15
|
+
def test(name, &blk)
|
16
|
+
method_name = "test_#{name.gsub(/\s+/, '_')}"
|
17
|
+
raise "Method already defined: #{method_name}" if instance_methods.include?(method_name.to_sym)
|
18
|
+
define_method method_name, &blk
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
module CustomAssertions
|
23
|
+
def assert_has_key(key, hash, msg = nil)
|
24
|
+
msg = message(msg) { "Expected #{hash.inspect} to have key #{key.inspect}" }
|
25
|
+
assert hash.has_key?(key), msg
|
26
|
+
end
|
27
|
+
|
28
|
+
def refute_has_key(key, hash, msg = nil)
|
29
|
+
msg = message(msg) { "Expected #{hash.inspect} not to have key #{key.inspect}" }
|
30
|
+
refute hash.has_key?(key), msg
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class TestCase < Minitest::Test
|
35
|
+
extend BlockTestHelper
|
36
|
+
include CustomAssertions
|
37
|
+
end
|
38
|
+
|
39
|
+
class StrategyTestCase < TestCase
|
40
|
+
def setup
|
41
|
+
@request = stub('Request')
|
42
|
+
@request.stubs(:params).returns({})
|
43
|
+
@request.stubs(:cookies).returns({})
|
44
|
+
@request.stubs(:env).returns({})
|
45
|
+
@request.stubs(:scheme).returns('http')
|
46
|
+
@request.stubs(:ssl?).returns(false)
|
47
|
+
|
48
|
+
@client_id = '123'
|
49
|
+
@client_secret = '53cr3tz'
|
50
|
+
end
|
51
|
+
|
52
|
+
def strategy
|
53
|
+
@strategy ||= begin
|
54
|
+
args = [@client_id, @client_secret, @options].compact
|
55
|
+
OmniAuth::Strategies::Elitmus.new(nil, *args).tap do |strategy|
|
56
|
+
strategy.stubs(:request).returns(@request)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
Dir[File.expand_path('../support/**/*', __FILE__)].each &method(:require)
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# NOTE it would be useful if this lived in omniauth-oauth2 eventually
|
2
|
+
module OAuth2StrategyTests
|
3
|
+
def self.included(base)
|
4
|
+
base.class_eval do
|
5
|
+
include ClientTests
|
6
|
+
include AuthorizeParamsTests
|
7
|
+
include CSRFAuthorizeParamsTests
|
8
|
+
include TokenParamsTests
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module ClientTests
|
13
|
+
extend BlockTestHelper
|
14
|
+
|
15
|
+
test 'should be initialized with symbolized client_options' do
|
16
|
+
@options = { :client_options => { 'authorize_url' => 'https://example.com' } }
|
17
|
+
assert_equal 'https://example.com', strategy.client.options[:authorize_url]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module AuthorizeParamsTests
|
22
|
+
extend BlockTestHelper
|
23
|
+
|
24
|
+
test 'should include any authorize params passed in the :authorize_params option' do
|
25
|
+
@options = { :authorize_params => { :foo => 'bar', :baz => 'zip' } }
|
26
|
+
assert_equal 'bar', strategy.authorize_params['foo']
|
27
|
+
assert_equal 'zip', strategy.authorize_params['baz']
|
28
|
+
end
|
29
|
+
|
30
|
+
test 'should include top-level options that are marked as :authorize_options' do
|
31
|
+
@options = { :authorize_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
|
32
|
+
assert_equal 'bar', strategy.authorize_params['scope']
|
33
|
+
assert_equal 'baz', strategy.authorize_params['foo']
|
34
|
+
end
|
35
|
+
|
36
|
+
test 'should exclude top-level options that are not passed' do
|
37
|
+
@options = { :authorize_options => [:bar] }
|
38
|
+
refute_has_key :bar, strategy.authorize_params
|
39
|
+
refute_has_key 'bar', strategy.authorize_params
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
module CSRFAuthorizeParamsTests
|
44
|
+
extend BlockTestHelper
|
45
|
+
|
46
|
+
test 'should store random state in the session when none is present in authorize or request params' do
|
47
|
+
assert_includes strategy.authorize_params.keys, 'state'
|
48
|
+
refute_empty strategy.authorize_params['state']
|
49
|
+
refute_empty strategy.session['omniauth.state']
|
50
|
+
assert_equal strategy.authorize_params['state'], strategy.session['omniauth.state']
|
51
|
+
end
|
52
|
+
|
53
|
+
test 'should not store state in the session when present in authorize params vs. a random one' do
|
54
|
+
@options = { :authorize_params => { :state => 'bar' } }
|
55
|
+
refute_empty strategy.authorize_params['state']
|
56
|
+
refute_equal 'bar', strategy.authorize_params[:state]
|
57
|
+
refute_empty strategy.session['omniauth.state']
|
58
|
+
refute_equal 'bar', strategy.session['omniauth.state']
|
59
|
+
end
|
60
|
+
|
61
|
+
test 'should not store state in the session when present in request params vs. a random one' do
|
62
|
+
@request.stubs(:params).returns({ 'state' => 'foo' })
|
63
|
+
refute_empty strategy.authorize_params['state']
|
64
|
+
refute_equal 'foo', strategy.authorize_params[:state]
|
65
|
+
refute_empty strategy.session['omniauth.state']
|
66
|
+
refute_equal 'foo', strategy.session['omniauth.state']
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
module TokenParamsTests
|
71
|
+
extend BlockTestHelper
|
72
|
+
|
73
|
+
test 'should include any authorize params passed in the :token_params option' do
|
74
|
+
@options = { :token_params => { :foo => 'bar', :baz => 'zip' } }
|
75
|
+
assert_equal 'bar', strategy.token_params['foo']
|
76
|
+
assert_equal 'zip', strategy.token_params['baz']
|
77
|
+
end
|
78
|
+
|
79
|
+
test 'should include top-level options that are marked as :token_options' do
|
80
|
+
@options = { :token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
|
81
|
+
assert_equal 'bar', strategy.token_params['scope']
|
82
|
+
assert_equal 'baz', strategy.token_params['foo']
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
data/test/test.rb
ADDED
@@ -0,0 +1,255 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'omniauth-elitmus'
|
3
|
+
|
4
|
+
class StrategyTest < StrategyTestCase
|
5
|
+
include OAuth2StrategyTests
|
6
|
+
end
|
7
|
+
|
8
|
+
class ClientTest < StrategyTestCase
|
9
|
+
test 'has correct default Elitmus site' do
|
10
|
+
assert_equal 'https://www.elitmus.com', strategy.client.site
|
11
|
+
end
|
12
|
+
|
13
|
+
test 'has correct default authorize url' do
|
14
|
+
assert_equal '/oauth/authorize', strategy.client.options[:authorize_url]
|
15
|
+
end
|
16
|
+
|
17
|
+
test 'has correct default token url' do
|
18
|
+
assert_equal '/oauth/token', strategy.client.options[:token_url]
|
19
|
+
end
|
20
|
+
|
21
|
+
test 'should be initialized with only site option in symbolized client_options' do
|
22
|
+
@options = { :client_options => { 'site' => 'https://codephode.com' } }
|
23
|
+
assert_equal 'https://codephode.com', strategy.client.site
|
24
|
+
assert_equal '/oauth/authorize', strategy.client.options[:authorize_url]
|
25
|
+
assert_equal '/oauth/token', strategy.client.options[:token_url]
|
26
|
+
end
|
27
|
+
|
28
|
+
test 'should be initialized with site and authorize_url in symbolized client_options' do
|
29
|
+
@options = { :client_options => { 'site' => 'https://codephode.com', 'authorize_url' => '/custom/auth' } }
|
30
|
+
assert_equal 'https://codephode.com', strategy.client.site
|
31
|
+
assert_equal '/custom/auth', strategy.client.options[:authorize_url]
|
32
|
+
assert_equal '/oauth/token', strategy.client.options[:token_url]
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
test 'should be initialized with site and token_url in symbolized client_options' do
|
37
|
+
@options = { :client_options => { 'site' => 'https://codephode.com', 'token_url' => '/custom/token' } }
|
38
|
+
assert_equal 'https://codephode.com', strategy.client.site
|
39
|
+
assert_equal '/oauth/authorize', strategy.client.options[:authorize_url]
|
40
|
+
assert_equal '/custom/token', strategy.client.options[:token_url]
|
41
|
+
end
|
42
|
+
|
43
|
+
test 'should be initialized with symbolized client_options' do
|
44
|
+
@options = { :client_options => { 'site' => 'https://staging.shrey.com', 'authorize_url' => '/custom/auth', 'token_url' => '/custom/token' } }
|
45
|
+
assert_equal 'https://staging.shrey.com', strategy.client.site
|
46
|
+
assert_equal '/custom/auth', strategy.client.options[:authorize_url]
|
47
|
+
assert_equal '/custom/token', strategy.client.options[:token_url]
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
class CallbackUrlTest < StrategyTestCase
|
53
|
+
test "returns the default callback url" do
|
54
|
+
url_base = 'http://myconsumerapp.authrequest.com'
|
55
|
+
@request.stubs(:url).returns("#{url_base}/some/page")
|
56
|
+
strategy.stubs(:script_name).returns('') # as not to depend on Rack env
|
57
|
+
assert_equal "#{url_base}/auth/elitmus/callback", strategy.callback_url
|
58
|
+
end
|
59
|
+
|
60
|
+
test "returns path from callback_path option" do
|
61
|
+
@options = { :callback_path => "/auth/some/custom/path/callback"}
|
62
|
+
url_base = 'http://myconsumerapp.authrequest.com'
|
63
|
+
@request.stubs(:url).returns("#{url_base}/page/path")
|
64
|
+
strategy.stubs(:script_name).returns('') # as not to depend on Rack env
|
65
|
+
assert_equal "#{url_base}/auth/some/custom/path/callback", strategy.callback_url
|
66
|
+
end
|
67
|
+
|
68
|
+
test "returns url from callback_url option" do
|
69
|
+
url = 'http://myconsumerapp.authrequest.com/auth/elitmus/callback'
|
70
|
+
@options = { :callback_url => url }
|
71
|
+
assert_equal url, strategy.callback_url
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
class AuthorizeParamsTest < StrategyTestCase
|
76
|
+
|
77
|
+
|
78
|
+
test 'should include top-level options with their default values if marked as :authorize_options' do
|
79
|
+
@options = { :authorize_options => [:scope, :foo], :foo => 'baz' }
|
80
|
+
assert_equal 'public', strategy.authorize_params['scope']
|
81
|
+
assert_equal 'baz', strategy.authorize_params['foo']
|
82
|
+
end
|
83
|
+
|
84
|
+
test 'includes default scope for public' do
|
85
|
+
assert strategy.authorize_params.is_a?(Hash)
|
86
|
+
assert_equal 'public', strategy.authorize_params[:scope]
|
87
|
+
end
|
88
|
+
|
89
|
+
test 'includes auth_type parameter from request when present' do
|
90
|
+
@request.stubs(:params).returns({ 'auth_type' => 'reauthenticate' })
|
91
|
+
assert strategy.authorize_params.is_a?(Hash)
|
92
|
+
assert_equal 'reauthenticate', strategy.authorize_params[:auth_type]
|
93
|
+
end
|
94
|
+
|
95
|
+
test 'overrides default scope with parameter passed from request' do
|
96
|
+
@request.stubs(:params).returns({ 'scope' => 'admin' })
|
97
|
+
assert strategy.authorize_params.is_a?(Hash)
|
98
|
+
assert_equal 'admin', strategy.authorize_params[:scope]
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
class UidTest < StrategyTestCase
|
103
|
+
def setup
|
104
|
+
super
|
105
|
+
strategy.stubs(:raw_info).returns({ 'id' => '123' })
|
106
|
+
end
|
107
|
+
|
108
|
+
test 'returns the id from raw_info' do
|
109
|
+
assert_equal '123', strategy.uid
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
class InfoTestOptionalDataPresent < StrategyTestCase
|
114
|
+
def setup
|
115
|
+
super
|
116
|
+
@raw_info ||= { 'name' => 'Fred Smith' }
|
117
|
+
strategy.stubs(:raw_info).returns(@raw_info)
|
118
|
+
end
|
119
|
+
|
120
|
+
test 'returns the name' do
|
121
|
+
assert_equal 'Fred Smith', strategy.info['name']
|
122
|
+
end
|
123
|
+
|
124
|
+
test 'returns the email' do
|
125
|
+
@raw_info['email'] = 'fred@smith.com'
|
126
|
+
assert_equal 'fred@smith.com', strategy.info['email']
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
class InfoTestOptionalDataNotPresent < StrategyTestCase
|
132
|
+
def setup
|
133
|
+
super
|
134
|
+
@raw_info = { 'name' => 'Fred Smith' }
|
135
|
+
strategy.stubs(:raw_info).returns(@raw_info)
|
136
|
+
end
|
137
|
+
|
138
|
+
test 'has no email key' do
|
139
|
+
refute_has_key 'email', strategy.info
|
140
|
+
end
|
141
|
+
|
142
|
+
test 'has no nickname key' do
|
143
|
+
refute_has_key 'nickname', strategy.info
|
144
|
+
end
|
145
|
+
|
146
|
+
test 'has no first name key' do
|
147
|
+
refute_has_key 'first_name', strategy.info
|
148
|
+
end
|
149
|
+
|
150
|
+
test 'has no last name key' do
|
151
|
+
refute_has_key 'last_name', strategy.info
|
152
|
+
end
|
153
|
+
|
154
|
+
test 'has no location key' do
|
155
|
+
refute_has_key 'location', strategy.info
|
156
|
+
end
|
157
|
+
|
158
|
+
test 'has no description key' do
|
159
|
+
refute_has_key 'description', strategy.info
|
160
|
+
end
|
161
|
+
|
162
|
+
test 'has no urls' do
|
163
|
+
refute_has_key 'urls', strategy.info
|
164
|
+
end
|
165
|
+
|
166
|
+
test 'has no verified key' do
|
167
|
+
refute_has_key 'verified', strategy.info
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
class RawInfoTest < StrategyTestCase
|
172
|
+
def setup
|
173
|
+
super
|
174
|
+
@access_token = stub('OAuth2::AccessToken')
|
175
|
+
@appsecret_proof = 'appsecret_proof'
|
176
|
+
@options = {:appsecret_proof => @appsecret_proof}
|
177
|
+
end
|
178
|
+
|
179
|
+
test 'should not include raw_info in extras hash when skip_info is specified' do
|
180
|
+
@options = { :skip_info => true }
|
181
|
+
strategy.stubs(:raw_info).returns({:foo => 'bar' })
|
182
|
+
refute_has_key 'raw_info', strategy.extra
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
class CredentialsTest < StrategyTestCase
|
189
|
+
def setup
|
190
|
+
super
|
191
|
+
@access_token = stub('OAuth2::AccessToken')
|
192
|
+
@access_token.stubs(:token)
|
193
|
+
@access_token.stubs(:expires?)
|
194
|
+
@access_token.stubs(:expires_at)
|
195
|
+
@access_token.stubs(:refresh_token)
|
196
|
+
strategy.stubs(:access_token).returns(@access_token)
|
197
|
+
end
|
198
|
+
|
199
|
+
test 'returns a Hash' do
|
200
|
+
assert_kind_of Hash, strategy.credentials
|
201
|
+
end
|
202
|
+
|
203
|
+
test 'returns the token' do
|
204
|
+
@access_token.stubs(:token).returns('123')
|
205
|
+
assert_equal '123', strategy.credentials['token']
|
206
|
+
end
|
207
|
+
|
208
|
+
test 'returns the expiry status' do
|
209
|
+
@access_token.stubs(:expires?).returns(true)
|
210
|
+
assert strategy.credentials['expires']
|
211
|
+
|
212
|
+
@access_token.stubs(:expires?).returns(false)
|
213
|
+
refute strategy.credentials['expires']
|
214
|
+
end
|
215
|
+
|
216
|
+
test 'returns the refresh token and expiry time when expiring' do
|
217
|
+
ten_mins_from_now = (Time.now + 600).to_i
|
218
|
+
@access_token.stubs(:expires?).returns(true)
|
219
|
+
@access_token.stubs(:refresh_token).returns('321')
|
220
|
+
@access_token.stubs(:expires_at).returns(ten_mins_from_now)
|
221
|
+
assert_equal '321', strategy.credentials['refresh_token']
|
222
|
+
assert_equal ten_mins_from_now, strategy.credentials['expires_at']
|
223
|
+
end
|
224
|
+
|
225
|
+
test 'does not return the refresh token when test is nil and expiring' do
|
226
|
+
@access_token.stubs(:expires?).returns(true)
|
227
|
+
@access_token.stubs(:refresh_token).returns(nil)
|
228
|
+
assert_nil strategy.credentials['refresh_token']
|
229
|
+
refute_has_key 'refresh_token', strategy.credentials
|
230
|
+
end
|
231
|
+
|
232
|
+
test 'does not return the refresh token when not expiring' do
|
233
|
+
@access_token.stubs(:expires?).returns(false)
|
234
|
+
@access_token.stubs(:refresh_token).returns('XXX')
|
235
|
+
assert_nil strategy.credentials['refresh_token']
|
236
|
+
refute_has_key 'refresh_token', strategy.credentials
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
class ExtraTest < StrategyTestCase
|
241
|
+
def setup
|
242
|
+
super
|
243
|
+
@raw_info = { 'name' => 'Fred Smith', 'email' => 'fred@smith.com', 'city' => 'bangalore' }
|
244
|
+
strategy.stubs(:raw_info).returns(@raw_info)
|
245
|
+
end
|
246
|
+
|
247
|
+
test 'returns a Hash' do
|
248
|
+
assert_kind_of Hash, strategy.extra
|
249
|
+
end
|
250
|
+
|
251
|
+
test 'contains raw info' do
|
252
|
+
assert_equal({ 'raw_info' => @raw_info }, strategy.extra)
|
253
|
+
end
|
254
|
+
|
255
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-elitmus
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shrey Patel
|
8
|
+
- Shireesh Jayashetty
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-06-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: omniauth-oauth2
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.2'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.2'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: minitest
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 5.5.1
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 5.5.1
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: mocha
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 1.1.0
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 1.1.0
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rake
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: simplecov
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
description:
|
85
|
+
email:
|
86
|
+
- aws@elitmus.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- lib/omniauth-elitmus.rb
|
98
|
+
- lib/omniauth/elitmus.rb
|
99
|
+
- lib/omniauth/elitmus/version.rb
|
100
|
+
- lib/omniauth/strategies/elitmus.rb
|
101
|
+
- omniauth-elitmus.gemspec
|
102
|
+
- test/helper.rb
|
103
|
+
- test/support/shared_example.rb
|
104
|
+
- test/test.rb
|
105
|
+
homepage: https://github.com/elitmus/omniauth-elitmus
|
106
|
+
licenses:
|
107
|
+
- MIT
|
108
|
+
metadata: {}
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.4.6
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: eLitmus OAuth2 Strategy for OmniAuth
|
129
|
+
test_files:
|
130
|
+
- test/helper.rb
|
131
|
+
- test/support/shared_example.rb
|
132
|
+
- test/test.rb
|