doorkeeper_hub 0.1.4 → 0.1.5

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
  SHA256:
3
- metadata.gz: 57317b863c1df69f8ef98933a88adeefe67d16a9045b34a651f50040e7d0660a
4
- data.tar.gz: 608d6f40b3f891882847825f615a537a32218be747eb4e754809b6d860349518
3
+ metadata.gz: 50b7e28e158b353429f556bb4f171ce8d385ff44cd20105c1450d2a2f82dc6ae
4
+ data.tar.gz: 892dd0510930e88cb8d113ca099db81b3c5ec026818d4abbd3dbdf5da7679ef4
5
5
  SHA512:
6
- metadata.gz: 9610fe1a924385f480ffde41a24ad5428b32ad838b9666398d11bc3073d06518d689a8e3f7b6e246b1330c68f475560d4ce3d97aeb13d601d1606ef7237173fc
7
- data.tar.gz: dd9825328ded32b28d500813a530f6845f9a45710bb71dd955996f91c3aed67b05e3bb043a8650a009c8352a49ef4db0439db9ae1bda8c093d67bb0cc96021d1
6
+ metadata.gz: ae0b8aa90bc7886c2ac279d7b2a674129b320fa9f7a2084c07708b2ee3214dfe11174ded731f6f4f414a1656033b7d4b65c4345def6b3bd3fa0f38ed9bca33da
7
+ data.tar.gz: 168d6a716b87ed915dcd2755e08db3f70ab2ba42e8ff6eaeb0ee05986052288c3bb56d5f4fc9a2b1bbf2e45e883d0597633a42e3225e83557f26ba320113a4fd
@@ -1,8 +1,7 @@
1
1
  module DoorkeeperHub
2
2
  class OmniauthCallbacksController < Devise::OmniauthCallbacksController
3
3
  skip_before_action :verify_authenticity_token,
4
- :check_login!,
5
- :check_d_token, only: :saml
4
+ :authenticate_doorkeeper!, only: :saml
6
5
 
7
6
  def saml
8
7
  @user = DoorkeeperHub
data/config/routes.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  Rails.application.routes.draw do
2
- devise_for DoorkeeperHub.devise_scope,
2
+ devise_for DoorkeeperHub.devise_routes_scope,
3
3
  controllers: {
4
4
  omniauth_callbacks: 'doorkeeper_hub/omniauth_callbacks'
5
5
  }
@@ -3,25 +3,17 @@ module DoorkeeperHub
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
- before_action :check_login!, :check_d_token
6
+ before_action :authenticate_doorkeeper!
7
7
  end
8
8
 
9
- def check_login!
10
- redirect_to user_saml_omniauth_authorize_path unless user_signed_in?
11
- end
12
-
13
- def company
14
- @company ||=
15
- current_user.companies.active.find_by(doorkeeper_token: params[:d_token]) ||
16
- raise(ActionController::RoutingError.new('Not Found'))
17
- end
18
-
19
- def check_login!
20
- redirect_to user_saml_omniauth_authorize_path unless user_signed_in?
21
- end
22
-
23
- def after_sign_in_path_for(current_user)
24
- root_path(d_token: params_or_default_d_token)
9
+ def authenticate_doorkeeper!
10
+ if signed_in?(DoorkeeperHub.devise_scope)
11
+ redirect_to root_path_with_token if params[:d_token].nil?
12
+ else
13
+ redirect_to omniauth_authorize_path(
14
+ DoorkeeperHub.devise_scope, :saml
15
+ )
16
+ end
25
17
  end
26
18
 
27
19
  def default_url_options(options = {})
@@ -29,14 +21,22 @@ module DoorkeeperHub
29
21
  options
30
22
  end
31
23
 
32
- def check_d_token
33
- if params[:d_token].nil? && current_user.present?
34
- redirect_to root_path d_token: params_or_default_d_token
35
- end
24
+ def after_sign_in_path_for(_)
25
+ root_path_with_token
26
+ end
27
+
28
+ def root_path_with_token
29
+ root_path d_token: params_or_default_d_token
36
30
  end
37
31
 
38
32
  def params_or_default_d_token
39
33
  params[:d_token] || current_user.companies.first.doorkeeper_token
40
34
  end
35
+
36
+ def company
37
+ @company ||=
38
+ current_user.companies.active.find_by(doorkeeper_token: params[:d_token]) ||
39
+ raise(ActionController::RoutingError.new('Not Found'))
40
+ end
41
41
  end
42
42
  end
@@ -1,3 +1,3 @@
1
1
  module DoorkeeperHub
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -13,8 +13,12 @@ module DoorkeeperHub
13
13
  yield config
14
14
  end
15
15
 
16
+ def self.devise_routes_scope
17
+ user_model.to_s.downcase.pluralize.to_sym
18
+ end
19
+
16
20
  def self.devise_scope
17
- config.user_model.to_s.downcase.pluralize.to_sym
21
+ user_model.to_s.downcase.to_sym
18
22
  end
19
23
 
20
24
  def self.user_model
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doorkeeper_hub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jimmy Fan