auth0_current_user 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b17d5fc0d9110bac480f41841b521209c9050301345637a5bd094be02be98515
4
- data.tar.gz: 585b48bd66b46d4e5fbd6a12cd8fd634800131acead3c235692dc081733a18f1
3
+ metadata.gz: 04b57d13c9018a8184b2474ecf1f3031a5d0b87a961f07ac6dcd4db03689f2ee
4
+ data.tar.gz: '0393295868660f4f19c785e2c9cf21343f12df603394b98919a2b9e1557c51eb'
5
5
  SHA512:
6
- metadata.gz: 8c68d89ce3c6866e8dc10ac6043d2ad34895ea551080700089012e7ec43bb084108efc8a945c7a279a8b89ab345384b2a362677e9d3e7e326b2be59bdb64d297
7
- data.tar.gz: 0cc0ddb2ef2b808b3eecc282577dfb81c26622e2b72928fa68947b02b29c42ba32e8a656e4596e21ff58602965989ed3acf92a68c207da7b1be8c3f47b9f5808
6
+ metadata.gz: e23a9950bc5514039fb35b0cc8671e192e22629864521449e235260c12cbc350cef1de9093d22cea16b6794c9f2d1431dbef66557f028fd2ff42d17190b8c43d
7
+ data.tar.gz: ff233b630c6ec27000d1f3a46f15047648158c73602e7e451687095527c4051e24d3f8c744d0b428b4ea0dc7d4cd917fb6893cbe55f646b1e86544429ae44311
data/README.md CHANGED
@@ -30,9 +30,15 @@ After including the gem in your Gemfile, run `rails g auth0_current_user:install
30
30
  * :user, 'user', :User, 'User'
31
31
  * :my_user, 'my_user', :MyUser, 'MyUser'
32
32
 
33
- To take advantage of the Auth0 authenticating add `include Auth0CurrentUser::Secured` to your base controller or and controller that you wish to be locked down for authentication.
33
+ To take advantage of the Auth0 authentication there are two flows you can use by simply including the relevant module in which ever controller you wish to lockdown.
34
+ 1. Web
34
35
 
35
- Once the `Secured` module is included in your controller, that will give you access to the `#current_user` method. It will find the `authenticated_klass` by it's email and using [Request Store](https://github.com/steveklabnik/request_store), store the user to be available either globally throught the store or in the controllers and views with the `#current_user` method.
36
+ a. `include Auth0CurrentUser::WebSecured`
37
+ 3. Api
38
+
39
+ a. `include Auth0CurrentUser::ApiSecured`
40
+
41
+ In either case, you will have access to the `current_user` method. The `WebSecured` will check for `current_user` or `session['userinfo']` and the `ApiSecured` will check against the JsonWebToken being passed in.
36
42
 
37
43
  ## Development
38
44
 
@@ -1,3 +1,3 @@
1
1
  module Auth0CurrentUser
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -3,12 +3,12 @@ module Auth0CurrentUser
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
- helper_method :current_user
7
6
  before_action :logged_in_using_omniauth?
7
+ helper_method :current_user
8
8
  end
9
9
 
10
10
  def current_user
11
- @_current_user ||= RequestStore.store[:current_user] ||= Kernel.const_get(authenticated_klass).find_by(email: email)
11
+ @_current_user ||= Kernel.const_get(authenticated_klass).find_by(email: email)
12
12
  end
13
13
 
14
14
  private
@@ -19,7 +19,7 @@ module Auth0CurrentUser
19
19
  return
20
20
  end
21
21
 
22
- @authenticated_klass ||= configuration.authenticated_klass.to_s.classify
22
+ @_authenticated_klass ||= configuration.authenticated_klass.to_s.classify
23
23
  rescue NameError => e
24
24
  Rails.logger.error("You must create a #{authenticated_klass} model/migration")
25
25
  rescue StandardError => e
@@ -27,15 +27,19 @@ module Auth0CurrentUser
27
27
  end
28
28
 
29
29
  def configuration
30
- @configuration ||= Configuration.new
30
+ @_configuration ||= Configuration.new
31
31
  end
32
32
 
33
33
  def email
34
- @_email ||= session.dig(:userinfo, :email)
34
+ @_email ||= userinfo['email'] || userinfo['name']
35
35
  end
36
36
 
37
37
  def logged_in_using_omniauth?
38
- redirect_to '/' unless current_user || session[:userinfo].present?
38
+ redirect_to '/' unless session[:userinfo].present? && Time.zone.now < Time.zone.at(userinfo['exp'])
39
+ end
40
+
41
+ def userinfo
42
+ session['userinfo'] || {}
39
43
  end
40
44
 
41
45
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auth0_current_user
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Heft