doorkeeper_sso_client 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/doorkeeper_sso_client/mixins/devise/controller_helpers.rb +10 -1
- data/lib/doorkeeper_sso_client/version.rb +1 -1
- data/lib/omniauth/strategies/doorkeeper_sso.rb +2 -3
- data/spec/fabricators/user_fabricator.rb +1 -1
- data/spec/lib/doorkeeper_sso_client/mixins/devise/controller_helper_spec.rb +21 -2
- data/spec/test_app/app/models/user.rb +1 -1
- metadata +2 -5
- data/lib/doorkeeper_sso_client/mixins/controller_helpers.rb +0 -39
- data/spec/models/config_spec.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de2665ad3f5e0134f533f0f1f372e47283286e45
|
4
|
+
data.tar.gz: 04fe335ebe3c4bb15c5a0d24059926c47efaac58
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81c42da53e7dd63163dbc736f8cf1e6be92a020accc7307630081a74b62adf2ed598e2da8c60113d1d9423f6017a606f6c79ef4a64ad063e094d22c71c48629a
|
7
|
+
data.tar.gz: e7e99d711c781c6c6e2f5011dc73bfffe7a758f5b6bf3c8cb990307083b4680017485e99492e91a20daf3bbff22b16871587f0a2571f6fe4500ff16d4c05607d
|
@@ -9,7 +9,7 @@ module DoorkeeperSsoClient
|
|
9
9
|
class_eval <<-METHODS, __FILE__, __LINE__ + 1
|
10
10
|
def validate_passport!
|
11
11
|
if #{scope}_signed_in?
|
12
|
-
sign_out(current_#{scope}) unless current_#{scope}.
|
12
|
+
sign_out(current_#{scope}) unless current_#{scope}.passports.find_by_uid(session['passport_id']).try(:active?)
|
13
13
|
end
|
14
14
|
return true
|
15
15
|
end
|
@@ -21,6 +21,15 @@ module DoorkeeperSsoClient
|
|
21
21
|
end
|
22
22
|
super
|
23
23
|
end
|
24
|
+
|
25
|
+
def after_sign_in_path_for(resource_or_scope)
|
26
|
+
scope = ::Devise::Mapping.find_scope!(resource_or_scope)
|
27
|
+
if scope == :#{scope}
|
28
|
+
request.env['omniauth.origin'] || super
|
29
|
+
else
|
30
|
+
super
|
31
|
+
end
|
32
|
+
end
|
24
33
|
METHODS
|
25
34
|
|
26
35
|
unless options[:skip_devise_hook]
|
@@ -14,8 +14,6 @@ module OmniAuth
|
|
14
14
|
option :fields, [:email, :name, :first_name, :last_name]
|
15
15
|
option :uid_field, :id
|
16
16
|
|
17
|
-
attr_accessor :passport
|
18
|
-
|
19
17
|
uid do
|
20
18
|
user_info[options.uid_field.to_s]
|
21
19
|
end
|
@@ -48,7 +46,8 @@ module OmniAuth
|
|
48
46
|
end
|
49
47
|
|
50
48
|
def call_app!
|
51
|
-
|
49
|
+
create_passport
|
50
|
+
session[:passport_id] = passport_info["id"]
|
52
51
|
super
|
53
52
|
end
|
54
53
|
|
@@ -4,5 +4,5 @@ Fabricator(:user) do
|
|
4
4
|
password { 'password' }
|
5
5
|
name { |attrs| [attrs[:first_name], attrs[:last_name]].join(" ") }
|
6
6
|
email { FFaker::Internet.email }
|
7
|
-
|
7
|
+
passports { [ Fabricate('DoorkeeperSsoClient::Passport') ] }
|
8
8
|
end
|
@@ -20,7 +20,7 @@ RSpec.describe "DoorkeeperSsoClient::Mixins::Devise::ControllerHelpers DeviseHoo
|
|
20
20
|
before(:each) do
|
21
21
|
@request.env["devise.mapping"] = Devise.mappings[:user]
|
22
22
|
sign_in user
|
23
|
-
get :index
|
23
|
+
get :index, nil, {'passport_id' => passport.uid}
|
24
24
|
end
|
25
25
|
|
26
26
|
describe "::activate_sso" do
|
@@ -47,10 +47,29 @@ RSpec.describe "DoorkeeperSsoClient::Mixins::Devise::ControllerHelpers DeviseHoo
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
|
50
|
+
|
51
51
|
describe "#after_sign_out_path_for" do
|
52
|
+
# Will redirect to sso server to completely logout user
|
52
53
|
it { expect(controller.after_sign_out_path_for(:user)).to eq "http://sso_server.com/logout?app_id=123" }
|
53
54
|
end
|
55
|
+
|
56
|
+
|
57
|
+
describe "#after_sign_in_path_for" do
|
58
|
+
# Will redirect to request.env['omniauth.origin']
|
59
|
+
context "has omniauth.origin" do
|
60
|
+
before(:each) do
|
61
|
+
mock_env = @request.env.merge 'omniauth.origin' => "http://localhost/profile"
|
62
|
+
allow(@request).to receive(:env).and_return(mock_env)
|
63
|
+
end
|
64
|
+
|
65
|
+
it { expect(controller.after_sign_in_path_for(:user)).to eq "http://localhost/profile" }
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "omniauth.origin env missing" do
|
69
|
+
it { expect(controller.after_sign_in_path_for(:user)).to eq "/anonymous" }
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
54
73
|
end
|
55
74
|
|
56
75
|
|
@@ -3,7 +3,7 @@ class User < ActiveRecord::Base
|
|
3
3
|
devise :database_authenticatable, :registerable,
|
4
4
|
:recoverable, :rememberable, :trackable, :validatable, password_length: 6..128
|
5
5
|
|
6
|
-
|
6
|
+
has_many :passports, as: :identity, class_name: "DoorkeeperSsoClient::Passport"
|
7
7
|
|
8
8
|
validates :email, :first_name, presence: true
|
9
9
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: doorkeeper_sso_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Wong
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: omniauth
|
@@ -316,7 +316,6 @@ files:
|
|
316
316
|
- lib/doorkeeper_sso_client/engine.rb
|
317
317
|
- lib/doorkeeper_sso_client/logging.rb
|
318
318
|
- lib/doorkeeper_sso_client/mixins.rb
|
319
|
-
- lib/doorkeeper_sso_client/mixins/controller_helpers.rb
|
320
319
|
- lib/doorkeeper_sso_client/mixins/devise/controller_helpers.rb
|
321
320
|
- lib/doorkeeper_sso_client/passport_verifier.rb
|
322
321
|
- lib/doorkeeper_sso_client/version.rb
|
@@ -328,7 +327,6 @@ files:
|
|
328
327
|
- spec/fabricators/user_fabricator.rb
|
329
328
|
- spec/lib/doorkeeper_sso_client/config_spec.rb
|
330
329
|
- spec/lib/doorkeeper_sso_client/mixins/devise/controller_helper_spec.rb
|
331
|
-
- spec/models/config_spec.rb
|
332
330
|
- spec/models/passport_spec.rb
|
333
331
|
- spec/rails_helper.rb
|
334
332
|
- spec/spec_helper.rb
|
@@ -375,7 +373,6 @@ test_files:
|
|
375
373
|
- spec/fabricators/user_fabricator.rb
|
376
374
|
- spec/lib/doorkeeper_sso_client/config_spec.rb
|
377
375
|
- spec/lib/doorkeeper_sso_client/mixins/devise/controller_helper_spec.rb
|
378
|
-
- spec/models/config_spec.rb
|
379
376
|
- spec/models/passport_spec.rb
|
380
377
|
- spec/rails_helper.rb
|
381
378
|
- spec/spec_helper.rb
|
@@ -1,39 +0,0 @@
|
|
1
|
-
module DoorkeeperSsoClient
|
2
|
-
module Mixins
|
3
|
-
module ControllerHelpers
|
4
|
-
extend ActiveSupport::Concern
|
5
|
-
|
6
|
-
module ClassMethods
|
7
|
-
def activate_sso(scope, options = {})
|
8
|
-
|
9
|
-
class_eval <<-METHODS, __FILE__, __LINE__ + 1
|
10
|
-
def validate_passport!
|
11
|
-
if #{scope}_signed_in?
|
12
|
-
sign_out(current_#{scope}) unless current_#{scope}.passport.try(:active?)
|
13
|
-
end
|
14
|
-
return true
|
15
|
-
end
|
16
|
-
|
17
|
-
def after_sign_out_path_for(resource_or_scope)
|
18
|
-
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
19
|
-
if scope == :#{scope}
|
20
|
-
return File.join( DoorkeeperSsoClient::Config.base_uri, "logout?app_id=" + DoorkeeperSsoClient::Config.oauth_client_id.to_s )
|
21
|
-
end
|
22
|
-
super
|
23
|
-
end
|
24
|
-
METHODS
|
25
|
-
|
26
|
-
unless options[:skip_devise_hook]
|
27
|
-
class_eval <<-METHODS, __FILE__, __LINE__ + 1
|
28
|
-
def authenticate_#{scope}!
|
29
|
-
store_location_for(:#{scope}, request.original_url)
|
30
|
-
validate_passport!
|
31
|
-
redirect_to DoorkeeperSsoClient::Config.oauth_login_path unless #{scope}_signed_in?
|
32
|
-
end
|
33
|
-
METHODS
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
data/spec/models/config_spec.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
RSpec.describe DoorkeeperSsoClient::Config, :type => :model do
|
4
|
-
before(:each) do
|
5
|
-
DoorkeeperSsoClient::Config.oauth_client_id = 123
|
6
|
-
DoorkeeperSsoClient::Config.oauth_client_secret = 'abc'
|
7
|
-
DoorkeeperSsoClient::Config.base_uri = 'http://localhost'
|
8
|
-
end
|
9
|
-
|
10
|
-
describe "stores config" do
|
11
|
-
it { expect(DoorkeeperSsoClient::Config.oauth_client_id).to eq 123 }
|
12
|
-
it { expect(DoorkeeperSsoClient::Config.oauth_client_secret).to eq 'abc' }
|
13
|
-
it { expect(DoorkeeperSsoClient::Config.base_uri).to eq 'http://localhost' }
|
14
|
-
end
|
15
|
-
|
16
|
-
describe "have default values" do
|
17
|
-
it { expect(DoorkeeperSsoClient::Config.sessions_path).to eq '/sso/sessions' }
|
18
|
-
it { expect(DoorkeeperSsoClient::Config.passport_verification_timeout_ms).to eq 200 }
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|