doorkeeper_sso_client 0.3.0 → 0.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4ba633d01e5284693e1017241a56d0714eb900a7
4
- data.tar.gz: 7f3c8145ad1dd0718c5501becce65b970cad1d2c
3
+ metadata.gz: de2665ad3f5e0134f533f0f1f372e47283286e45
4
+ data.tar.gz: 04fe335ebe3c4bb15c5a0d24059926c47efaac58
5
5
  SHA512:
6
- metadata.gz: b801b58747c26ebfeeb4b23963bc8d22c51160a69ac9736bc2b9ddb93e7cc4de36c0874c35e7bebfa667e22837e10d48d2babfc55ffe48d46531cf53ae71bc4f
7
- data.tar.gz: 58da3a6a8822c79de13fa85bdad701b2c731fb2a793100ea4ca2482eabd3f677059cfeace9dd8e91e782b8469f2516fbeaba71137abb7ed763cdda49e6a209a2
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}.passport.try(:active?)
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]
@@ -1,3 +1,3 @@
1
1
  module DoorkeeperSsoClient
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -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
- self.passport = create_passport
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
- passport { Fabricate('DoorkeeperSsoClient::Passport') }
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
- # Will redirect to sso server to completely logout user
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
- has_one :passport, as: :identity, class_name: "DoorkeeperSsoClient::Passport"
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.3.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-09 00:00:00.000000000 Z
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
@@ -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