omniauth-cas-login 1.0.1
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 +15 -0
- data/.gitignore +7 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/README.md +25 -0
- data/Rakefile +8 -0
- data/lib/omniauth-cas-login.rb +2 -0
- data/lib/omniauth-cas-login/version.rb +5 -0
- data/lib/omniauth/strategies/cas_login.rb +131 -0
- data/omniauth-cas-login.gemspec +26 -0
- data/spec/omniauth/strategies/cas_login_spec.rb +70 -0
- data/spec/spec_helper.rb +20 -0
- metadata +127 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
---
|
|
2
|
+
!binary "U0hBMQ==":
|
|
3
|
+
metadata.gz: !binary |-
|
|
4
|
+
YWM1OGEwMDJlNjcwNjc5YTdhNzcwZGFlZDYyNmQxMWI0OGEzYWZhYQ==
|
|
5
|
+
data.tar.gz: !binary |-
|
|
6
|
+
N2QxZWNlYzFmYmM1N2VjNGNhNDZjNjMzYjMyYmQ3YjAxYjc5YmEyOA==
|
|
7
|
+
SHA512:
|
|
8
|
+
metadata.gz: !binary |-
|
|
9
|
+
ZmI5NzdlMmUxYzdhOTczODI3OWFmMzEwMmEwYTE5ZWM5ZjZjMDkxZTNjNDI5
|
|
10
|
+
Y2IwMzJiMzU5Njg3ZWM4NGI5NWM2OWMwODhiZWFkMjdmMjExNjFmMDVkMWZl
|
|
11
|
+
YmI5NzU2MzcxMzVhN2UzOTc1MGNkZmYwZTc1MTdmNjI5NDg4NDQ=
|
|
12
|
+
data.tar.gz: !binary |-
|
|
13
|
+
ZGQ0MzBjZjkxMzY1YjJmNGQ4YmUwMDJjNmZjMTU1MDk2YWZjYjg3ZjgzOTdl
|
|
14
|
+
YTc4MDFmMTUyYjNjMTMzMzJjZjE3YmUxZWM4NmZiNDQ2MGU2OTIzZDU2MDQ2
|
|
15
|
+
MDZkNjdlNjZiZmY5MjM2Mzk5NmY3M2U2NmY5MzExMmQ4ZDRjYzU=
|
data/.gitignore
ADDED
data/.rspec
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--colour
|
data/Gemfile
ADDED
data/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# OmniAuth CAS Login
|
|
2
|
+
|
|
3
|
+
This gem contains the CAS Login strategy for OmniAuth.
|
|
4
|
+
|
|
5
|
+
## Before You Begin
|
|
6
|
+
|
|
7
|
+
You should have already installed OmniAuth into your app; if not, read the [OmniAuth README](https://github.com/intridea/omniauth) to get started.
|
|
8
|
+
|
|
9
|
+
## Using This Strategy
|
|
10
|
+
|
|
11
|
+
First start by adding this gem to your Gemfile:
|
|
12
|
+
|
|
13
|
+
gem 'omniauth-cas-login'
|
|
14
|
+
|
|
15
|
+
If you need to use the gem locally from source, place the root folder in 'vendor/gems' and add the following line instead:
|
|
16
|
+
|
|
17
|
+
gem 'omniauth-cas-login', :path => 'vendor/gems/omniauth-cas-login'
|
|
18
|
+
|
|
19
|
+
Next, tell OmniAuth about this provider. For a Rails app, your `config/initializers/omniauth.rb` file should look like this:
|
|
20
|
+
|
|
21
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
|
22
|
+
provider :cas_login, "CLIENT_KEY", "CLIENT_SECRET"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
Replace CLIENT_KEY and CLIENT_SECRET with the appropriate values you obtained from the login provider.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
require 'omniauth'
|
|
2
|
+
require 'oauth2'
|
|
3
|
+
require 'securerandom'
|
|
4
|
+
|
|
5
|
+
module OmniAuth
|
|
6
|
+
module Strategies
|
|
7
|
+
class CasLogin
|
|
8
|
+
include OmniAuth::Strategy
|
|
9
|
+
|
|
10
|
+
option :name, 'cas_login'
|
|
11
|
+
|
|
12
|
+
args [:client_id, :client_secret]
|
|
13
|
+
|
|
14
|
+
option :client_id, nil
|
|
15
|
+
option :client_secret, nil
|
|
16
|
+
option :authorize_params, {}
|
|
17
|
+
option :authorize_options, [:scope]
|
|
18
|
+
option :provider_ignores_state, false
|
|
19
|
+
|
|
20
|
+
option :client_options, {
|
|
21
|
+
:site => nil,
|
|
22
|
+
:authorize_url => nil,
|
|
23
|
+
:token_url => nil,
|
|
24
|
+
:profile_url => nil
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
attr_accessor :access_token
|
|
28
|
+
|
|
29
|
+
uid{ raw_info['principal'] }
|
|
30
|
+
|
|
31
|
+
info do
|
|
32
|
+
{
|
|
33
|
+
:principal => raw_info['principal'],
|
|
34
|
+
:email => raw_info.has_key?('email') ? raw_info['email'] : '',
|
|
35
|
+
:name => raw_info['name'],
|
|
36
|
+
:thirdPartyIds => raw_info.has_key?('thirdPartyIds') ? raw_info['thirdPartyIds'] : {}
|
|
37
|
+
}
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
extra do
|
|
41
|
+
{ 'raw_info' => raw_info }
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
credentials do
|
|
45
|
+
{ 'token' => access_token.token }
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def client
|
|
49
|
+
::OAuth2::Client.new(options.client_id, options.client_secret, deep_symbolize(options.client_options))
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def callback_url
|
|
53
|
+
full_host + script_name + callback_path
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def request_phase
|
|
57
|
+
redirect client.auth_code.authorize_url({:redirect_uri => callback_url}.merge(authorize_params))
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def authorize_params
|
|
61
|
+
options.authorize_params[:state] = SecureRandom.hex(24)
|
|
62
|
+
params = options.authorize_params.merge(options.authorize_options.inject({}){|h,k| h[k.to_sym] = options[k] if options[k]; h})
|
|
63
|
+
if OmniAuth.config.test_mode
|
|
64
|
+
@env ||= {}
|
|
65
|
+
@env['rack.session'] ||= {}
|
|
66
|
+
end
|
|
67
|
+
session['omniauth.state'] = params[:state]
|
|
68
|
+
params
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def callback_phase
|
|
72
|
+
if request.params['error'] || request.params['error_reason']
|
|
73
|
+
raise CallbackError.new(request.params['error'], request.params['error_description'] || request.params['error_reason'], request.params['error_uri'])
|
|
74
|
+
end
|
|
75
|
+
if !options.provider_ignores_state && (request.params['state'].to_s.empty? || request.params['state'] != session.delete('omniauth.state'))
|
|
76
|
+
raise CallbackError.new(nil, :csrf_detected)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
self.access_token = build_access_token
|
|
80
|
+
self.access_token = access_token.refresh! if access_token.expired?
|
|
81
|
+
|
|
82
|
+
super
|
|
83
|
+
rescue ::OAuth2::Error, CallbackError => e
|
|
84
|
+
fail!(:invalid_credentials, e)
|
|
85
|
+
rescue ::Timeout::Error, ::Errno::ETIMEDOUT => e
|
|
86
|
+
fail!(:timeout, e)
|
|
87
|
+
rescue ::SocketError => e
|
|
88
|
+
fail!(:failed_to_connect, e)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def raw_info
|
|
92
|
+
@raw_info ||= access_token.get(options.client_options.profile_url).parsed
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
protected
|
|
96
|
+
|
|
97
|
+
def deep_symbolize(hash)
|
|
98
|
+
hash.inject({}) do |h, (k,v)|
|
|
99
|
+
h[k.to_sym] = v.is_a?(Hash) ? deep_symbolize(v) : v
|
|
100
|
+
h
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def build_access_token
|
|
105
|
+
access_token_url = client.token_url(:client_id => options.client_id, :client_secret => options.client_secret, :code => request.params['code'], :redirect_uri => callback_url)
|
|
106
|
+
|
|
107
|
+
response = client.request(:get, access_token_url)
|
|
108
|
+
access_token_str = response.parsed['access_token']
|
|
109
|
+
expires_str = response.parsed['expiration']
|
|
110
|
+
|
|
111
|
+
::OAuth2::AccessToken.from_hash(
|
|
112
|
+
client, {:access_token => access_token_str, :expires_in => expires_str, :mode => :query, :param_name => 'access_token'}
|
|
113
|
+
)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# An error that is indicated in the OAuth 2.0 callback.
|
|
117
|
+
# This could be a `redirect_uri_mismatch` or other
|
|
118
|
+
class CallbackError < StandardError
|
|
119
|
+
attr_accessor :error, :error_reason, :error_uri
|
|
120
|
+
|
|
121
|
+
def initialize(error, error_reason=nil, error_uri=nil)
|
|
122
|
+
self.error = error
|
|
123
|
+
self.error_reason = error_reason
|
|
124
|
+
self.error_uri = error_uri
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
OmniAuth.config.add_camelization 'cas_login', 'CasLogin'
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'omniauth-cas-login/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |gem|
|
|
7
|
+
gem.name = "omniauth-cas-login"
|
|
8
|
+
gem.version = OmniAuth::CasLogin::VERSION
|
|
9
|
+
gem.authors = ["Antonio Ruano Cuesta"]
|
|
10
|
+
gem.email = ["ruanest@gmail.com"]
|
|
11
|
+
gem.description = %q{OmniAuth strategy for CAS Login}
|
|
12
|
+
gem.summary = %q{OmniAuth strategy for CAS Login}
|
|
13
|
+
gem.homepage = ""
|
|
14
|
+
|
|
15
|
+
gem.files = `git ls-files`.split($/)
|
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
18
|
+
gem.require_paths = ["lib"]
|
|
19
|
+
|
|
20
|
+
gem.add_dependency 'omniauth', '~> 1.1.1'
|
|
21
|
+
gem.add_dependency 'oauth2', '~> 0.8.0'
|
|
22
|
+
gem.add_dependency 'json'
|
|
23
|
+
|
|
24
|
+
gem.add_development_dependency 'rspec', '~> 2.13.0'
|
|
25
|
+
gem.add_development_dependency 'simplecov'
|
|
26
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'omniauth-cas-login'
|
|
3
|
+
|
|
4
|
+
describe OmniAuth::Strategies::CasLogin do
|
|
5
|
+
subject { OmniAuth::Strategies::CasLogin.new(nil) }
|
|
6
|
+
|
|
7
|
+
it 'should add a camelization for itself' do
|
|
8
|
+
OmniAuth::Utils.camelize('cas_login').should == 'CasLogin'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
describe '#callback_path' do
|
|
12
|
+
it 'has the correct callback path' do
|
|
13
|
+
subject.callback_path.should eq('/auth/cas_login/callback')
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe '#uid' do
|
|
18
|
+
before :each do
|
|
19
|
+
subject.stub(:raw_info) { { 'principal' => 'uid' } }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'returns the id from raw_info' do
|
|
23
|
+
subject.uid.should eq('uid')
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
describe '#info' do
|
|
28
|
+
before :each do
|
|
29
|
+
subject.stub(:raw_info) { {} }
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
context 'and therefore has all the necessary fields' do
|
|
33
|
+
it { subject.info.should have_key :principal }
|
|
34
|
+
it { subject.info.should have_key :name }
|
|
35
|
+
it { subject.info.should have_key :email }
|
|
36
|
+
it { subject.info.should have_key :thirdPartyIds }
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe '#extra' do
|
|
41
|
+
before :each do
|
|
42
|
+
subject.stub(:raw_info) { { :foo => 'bar' } }
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it { subject.extra['raw_info'].should eq({ :foo => 'bar' }) }
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
describe '#raw_info' do
|
|
49
|
+
before :each do
|
|
50
|
+
response = double('response', :parsed => { :foo => 'bar' })
|
|
51
|
+
subject.stub(:access_token) { double('access token', :get => response) }
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it 'returns parsed response from access token' do
|
|
55
|
+
subject.raw_info.should eq({ :foo => 'bar' })
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
describe '#authorize_params' do
|
|
60
|
+
describe 'scope' do
|
|
61
|
+
before :each do
|
|
62
|
+
subject.stub(:session => {})
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it 'sets default scope' do
|
|
66
|
+
subject.authorize_params['scope'].should eq(nil)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require 'simplecov'
|
|
2
|
+
SimpleCov.start
|
|
3
|
+
|
|
4
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
|
5
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
|
6
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
|
7
|
+
# loaded once.
|
|
8
|
+
#
|
|
9
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
|
10
|
+
RSpec.configure do |config|
|
|
11
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
|
12
|
+
config.run_all_when_everything_filtered = true
|
|
13
|
+
config.filter_run :focus
|
|
14
|
+
|
|
15
|
+
# Run specs in random order to surface order dependencies. If you find an
|
|
16
|
+
# order dependency and want to debug it, you can fix the order by providing
|
|
17
|
+
# the seed, which is printed after each run.
|
|
18
|
+
# --seed 1234
|
|
19
|
+
config.order = 'random'
|
|
20
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: omniauth-cas-login
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Antonio Ruano Cuesta
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2013-10-22 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.1.1
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ~>
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 1.1.1
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: oauth2
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ~>
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 0.8.0
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ~>
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 0.8.0
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: json
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ! '>='
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ! '>='
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
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.13.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.13.0
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: simplecov
|
|
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: OmniAuth strategy for CAS Login
|
|
84
|
+
email:
|
|
85
|
+
- ruanest@gmail.com
|
|
86
|
+
executables: []
|
|
87
|
+
extensions: []
|
|
88
|
+
extra_rdoc_files: []
|
|
89
|
+
files:
|
|
90
|
+
- .gitignore
|
|
91
|
+
- .rspec
|
|
92
|
+
- Gemfile
|
|
93
|
+
- README.md
|
|
94
|
+
- Rakefile
|
|
95
|
+
- lib/omniauth-cas-login.rb
|
|
96
|
+
- lib/omniauth-cas-login/version.rb
|
|
97
|
+
- lib/omniauth/strategies/cas_login.rb
|
|
98
|
+
- omniauth-cas-login.gemspec
|
|
99
|
+
- spec/omniauth/strategies/cas_login_spec.rb
|
|
100
|
+
- spec/spec_helper.rb
|
|
101
|
+
homepage: ''
|
|
102
|
+
licenses: []
|
|
103
|
+
metadata: {}
|
|
104
|
+
post_install_message:
|
|
105
|
+
rdoc_options: []
|
|
106
|
+
require_paths:
|
|
107
|
+
- lib
|
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
109
|
+
requirements:
|
|
110
|
+
- - ! '>='
|
|
111
|
+
- !ruby/object:Gem::Version
|
|
112
|
+
version: '0'
|
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - ! '>='
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '0'
|
|
118
|
+
requirements: []
|
|
119
|
+
rubyforge_project:
|
|
120
|
+
rubygems_version: 2.1.9
|
|
121
|
+
signing_key:
|
|
122
|
+
specification_version: 4
|
|
123
|
+
summary: OmniAuth strategy for CAS Login
|
|
124
|
+
test_files:
|
|
125
|
+
- spec/omniauth/strategies/cas_login_spec.rb
|
|
126
|
+
- spec/spec_helper.rb
|
|
127
|
+
has_rdoc:
|