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 +4 -4
- data/README.md +8 -2
- data/lib/auth0_current_user/version.rb +1 -1
- data/lib/auth0_current_user/web_secured.rb +10 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04b57d13c9018a8184b2474ecf1f3031a5d0b87a961f07ac6dcd4db03689f2ee
|
4
|
+
data.tar.gz: '0393295868660f4f19c785e2c9cf21343f12df603394b98919a2b9e1557c51eb'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
-
|
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
|
|
@@ -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 ||=
|
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
|
-
@
|
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
|
-
@
|
30
|
+
@_configuration ||= Configuration.new
|
31
31
|
end
|
32
32
|
|
33
33
|
def email
|
34
|
-
@_email ||=
|
34
|
+
@_email ||= userinfo['email'] || userinfo['name']
|
35
35
|
end
|
36
36
|
|
37
37
|
def logged_in_using_omniauth?
|
38
|
-
redirect_to '/' unless
|
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
|