oa-cadun 3.1.0 → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -1
- data/README.md +28 -13
- data/lib/oa-cadun/version.rb +1 -1
- data/lib/omni_auth/strategies/cadun.rb +2 -2
- data/oa-cadun.gemspec +10 -12
- data/spec/omni_auth/strategies/cadun_spec.rb +31 -22
- metadata +8 -10
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -9,10 +9,22 @@ The goal of this gem is to create a bridge between Cadun and your app through Om
|
|
9
9
|
Add into your Gemfile
|
10
10
|
|
11
11
|
gem "oa-cadun"
|
12
|
+
|
13
|
+
## Configuration
|
12
14
|
|
13
|
-
|
15
|
+
The middleware has 2 important options: `:service_id` and `:config_file`.
|
16
|
+
:service_id is the number of your service on CadUn.
|
17
|
+
:config_file is the YAML formatted file with the urls you want to use:
|
18
|
+
|
19
|
+
cadun:
|
20
|
+
logout_url: https://login.dev.globoi.com/Servlet/do/logout
|
21
|
+
login_url: https://login.dev.globoi.com/login
|
22
|
+
auth_url: isp-authenticator.dev.globoi.com
|
23
|
+
auth_port: 8280
|
24
|
+
|
25
|
+
The `config_file` must be in that format, otherwise it won't work. The final result will look like this:
|
14
26
|
|
15
|
-
config.middleware.use OmniAuth::Strategies::Cadun, :service_id => 1234
|
27
|
+
config.middleware.use OmniAuth::Strategies::Cadun, :service_id => 1234, :config_file => "#{File.dirname(__FILE__)}/cadun.yml"
|
16
28
|
|
17
29
|
After that, you just need to follow the OmniAuth standard configuration creating a callback controller to handle the CadUn's redirect. Something like this:
|
18
30
|
|
@@ -22,11 +34,12 @@ After that, you just need to follow the OmniAuth standard configuration creating
|
|
22
34
|
end
|
23
35
|
|
24
36
|
def create
|
25
|
-
auth = request.env['omniauth.auth']
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
37
|
+
if auth = request.env['omniauth.auth']
|
38
|
+
user = begin
|
39
|
+
User.find(auth['uid'])
|
40
|
+
rescue ActiveRecord::RecordNotFound
|
41
|
+
User.create_from_omniauth(auth)
|
42
|
+
end
|
30
43
|
|
31
44
|
session[:user_id] = user.id
|
32
45
|
redirect_to root_url
|
@@ -51,21 +64,23 @@ And set your routes:
|
|
51
64
|
match "/auth/cadun/logout" => "sessions#destroy"
|
52
65
|
|
53
66
|
|
54
|
-
## Dynamic Service Ids
|
67
|
+
## Tips: Dynamic Service Ids
|
55
68
|
|
56
69
|
Let's say your application works with many service ids. You can work with a "SETUP" step.
|
57
70
|
|
58
71
|
Add to the configuration:
|
59
72
|
|
60
|
-
config.middleware.use OmniAuth::Strategies::Cadun, :service_id => 1234, :setup => true
|
73
|
+
config.middleware.use OmniAuth::Strategies::Cadun, :service_id => 1234, :setup => true, :config => "cadun.yml"
|
61
74
|
|
62
75
|
Then add to your callback controller:
|
63
76
|
|
64
|
-
|
65
|
-
|
66
|
-
|
77
|
+
class SessionsController < ActionController::Base
|
78
|
+
def setup
|
79
|
+
request.env['omniauth.strategy'].options[:service_id] = object.service_id
|
80
|
+
render :nothing => true, :status => 404
|
81
|
+
end
|
67
82
|
end
|
68
83
|
|
69
84
|
It's really important to finish the action with a 404 status. It says to OmniAuth that it can go ahead and complete the flow.
|
70
85
|
|
71
|
-
The setup step can change the options of the Strategy, so you can change the service id and the redirect will go to any service you set.
|
86
|
+
The setup step can change the options of the Strategy, so you can change the service id and the redirect will go to any service you set up.
|
data/lib/oa-cadun/version.rb
CHANGED
@@ -25,13 +25,13 @@ module OmniAuth
|
|
25
25
|
:user_info => {
|
26
26
|
:id => user.id,
|
27
27
|
:GLBID => request.params['GLBID'],
|
28
|
-
:url => request.params['url'],
|
28
|
+
:url => request.params['url'],
|
29
29
|
:email => user.email,
|
30
30
|
:status => user.status,
|
31
31
|
:nickname => user.login,
|
32
32
|
:name => user.name,
|
33
33
|
:address => user.address,
|
34
|
-
:
|
34
|
+
:neighborhood => user.neighborhood,
|
35
35
|
:city => user.city,
|
36
36
|
:state => user.state,
|
37
37
|
:country => user.country,
|
data/oa-cadun.gemspec
CHANGED
@@ -1,24 +1,22 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
require "oa-cadun/version"
|
2
|
+
require "#{File.dirname(__FILE__)}/lib/oa-cadun/version"
|
4
3
|
|
5
4
|
Gem::Specification.new do |s|
|
6
|
-
s.name =
|
5
|
+
s.name = 'oa-cadun'
|
7
6
|
s.version = OACadun::VERSION::STRING
|
8
7
|
s.platform = Gem::Platform::RUBY
|
9
|
-
s.authors =
|
10
|
-
s.email =
|
11
|
-
s.homepage =
|
12
|
-
s.summary =
|
13
|
-
s.description =
|
8
|
+
s.authors = %w(Bruno Azisaka Maciel)
|
9
|
+
s.email = %w(bruno@azisaka.com.br)
|
10
|
+
s.homepage = 'https://github.com/azisaka/oa-cadun'
|
11
|
+
s.summary = 'OmniAuth strategy for CadUn'
|
12
|
+
s.description = 'The goal of this gem is to allow the developer to use CadUn (a login webservice made by Globo.com) in any web app using OmniAuth'
|
14
13
|
|
15
14
|
s.files = `git ls-files`.split("\n")
|
16
|
-
s.test_files = `git ls-files -- {
|
17
|
-
s.
|
18
|
-
s.require_paths = ["lib"]
|
15
|
+
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
16
|
+
s.require_paths = %w(lib)
|
19
17
|
|
20
18
|
s.add_dependency 'oa-core'
|
21
|
-
s.add_dependency 'cadun', '0.2.
|
19
|
+
s.add_dependency 'cadun', '0.2.1'
|
22
20
|
s.add_development_dependency 'rack'
|
23
21
|
s.add_development_dependency 'rspec'
|
24
22
|
s.add_development_dependency 'rr'
|
@@ -4,12 +4,12 @@ require 'spec_helper'
|
|
4
4
|
describe OmniAuth::Strategies::Cadun do
|
5
5
|
|
6
6
|
let(:app) { lambda { |env| [200, {}, ['Hello']] } }
|
7
|
-
let(:strategy) { OmniAuth::Strategies::Cadun.new
|
7
|
+
let(:strategy) { OmniAuth::Strategies::Cadun.new app, :service_id => 1, :config => "#{File.dirname(__FILE__)}/../../support/fixtures/config.yml" }
|
8
8
|
|
9
9
|
describe "#request_phase" do
|
10
10
|
context "when it has a referer" do
|
11
11
|
before do
|
12
|
-
strategy.call!
|
12
|
+
strategy.call! Rack::MockRequest.env_for("http://test.localhost/auth/cadun", "rack.session" => {}, "HTTP_HOST" => "test.localhost")
|
13
13
|
|
14
14
|
@status, @headers, @body = strategy.request_phase
|
15
15
|
end
|
@@ -47,29 +47,38 @@ describe OmniAuth::Strategies::Cadun do
|
|
47
47
|
describe "#auth_hash" do
|
48
48
|
before do
|
49
49
|
stub_requests
|
50
|
-
strategy.call!
|
50
|
+
strategy.call! Rack::MockRequest.env_for("http://localhost?GLBID=GLBID&url=/go_back", "rack.session" => {})
|
51
51
|
end
|
52
52
|
|
53
|
-
subject { strategy.auth_hash
|
53
|
+
subject { strategy.auth_hash }
|
54
54
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
55
|
+
describe ":uid" do
|
56
|
+
specify { subject[:uid].should == "21737810" }
|
57
|
+
end
|
58
|
+
|
59
|
+
describe ":provider" do
|
60
|
+
specify { subject[:provider].should == "cadun" }
|
61
|
+
end
|
62
|
+
|
63
|
+
describe ":user_info" do
|
64
|
+
specify { subject[:user_info].should include(:GLBID => "GLBID") }
|
65
|
+
specify { subject[:user_info].should include(:id => "21737810") }
|
66
|
+
specify { subject[:user_info].should include(:email => "fab1@spam.la") }
|
67
|
+
specify { subject[:user_info].should include(:status => "ATIVO") }
|
68
|
+
specify { subject[:user_info].should include(:nickname => "fabricio_fab1") }
|
69
|
+
specify { subject[:user_info].should include(:name => "Fabricio Rodrigo Lopes") }
|
70
|
+
specify { subject[:user_info].should include(:address => "Rua Uruguai, 59") }
|
71
|
+
specify { subject[:user_info].should include(:neighborhood => "Andaraí") }
|
72
|
+
specify { subject[:user_info].should include(:city => "Rio de Janeiro") }
|
73
|
+
specify { subject[:user_info].should include(:state => "RJ") }
|
74
|
+
specify { subject[:user_info].should include(:country => "Brasil") }
|
75
|
+
specify { subject[:user_info].should include(:gender => "MASCULINO") }
|
76
|
+
specify { subject[:user_info].should include(:birthday => "22/02/1983") }
|
77
|
+
specify { subject[:user_info].should include(:mobile => "21 99999999") }
|
78
|
+
specify { subject[:user_info].should include(:phone => "21 22881060") }
|
79
|
+
specify { subject[:user_info].should include(:cpf => "09532034765") }
|
80
|
+
specify { subject[:user_info].should include(:url => "/go_back") }
|
81
|
+
end
|
73
82
|
end
|
74
83
|
|
75
84
|
end
|
metadata
CHANGED
@@ -2,10 +2,12 @@
|
|
2
2
|
name: oa-cadun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 3.1.
|
5
|
+
version: 3.1.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
|
-
- Bruno
|
8
|
+
- Bruno
|
9
|
+
- Azisaka
|
10
|
+
- Maciel
|
9
11
|
autorequire:
|
10
12
|
bindir: bin
|
11
13
|
cert_chain: []
|
@@ -32,7 +34,7 @@ dependencies:
|
|
32
34
|
requirements:
|
33
35
|
- - "="
|
34
36
|
- !ruby/object:Gem::Version
|
35
|
-
version: 0.2.
|
37
|
+
version: 0.2.1
|
36
38
|
type: :runtime
|
37
39
|
version_requirements: *id002
|
38
40
|
- !ruby/object:Gem::Dependency
|
@@ -106,7 +108,7 @@ files:
|
|
106
108
|
- spec/support/fixtures/config.yml
|
107
109
|
- spec/support/fixtures/pessoa.xml
|
108
110
|
has_rdoc: true
|
109
|
-
homepage:
|
111
|
+
homepage: https://github.com/azisaka/oa-cadun
|
110
112
|
licenses: []
|
111
113
|
|
112
114
|
post_install_message:
|
@@ -133,9 +135,5 @@ rubygems_version: 1.6.2
|
|
133
135
|
signing_key:
|
134
136
|
specification_version: 3
|
135
137
|
summary: OmniAuth strategy for CadUn
|
136
|
-
test_files:
|
137
|
-
|
138
|
-
- spec/spec_helper.rb
|
139
|
-
- spec/support/fixtures/autorizacao.xml
|
140
|
-
- spec/support/fixtures/config.yml
|
141
|
-
- spec/support/fixtures/pessoa.xml
|
138
|
+
test_files: []
|
139
|
+
|