devise-jwt 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/README.md +23 -1
- data/lib/devise/jwt.rb +15 -0
- data/lib/devise/jwt/defaults_generator.rb +19 -12
- data/lib/devise/jwt/mapping_inspector.rb +8 -0
- data/lib/devise/jwt/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30e463b1ff2eee31807c9e08ad02d39e18291a34
|
4
|
+
data.tar.gz: 8d425949dcc6fa52e7f1db7e44eb0743dec4e6f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e3caeea62311d2731fcabe065cefc2d6e4435b146165dc796038e425832be22aa4f9d28b8f214363c7faa680771a5acdfebff44e391879172b20fa72ab9ae75
|
7
|
+
data.tar.gz: 0f15207820873a6644c2b491223b88f931cac592ae1ba6415350c0b0e048f93bdfbe8aabe1864f68503cee826668b6f93210d6d0f2c4209e3cee18853b8b09ac
|
data/CHANGELOG.md
CHANGED
@@ -4,7 +4,12 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
6
6
|
|
7
|
-
## [0.
|
7
|
+
## [0.3.0] - 2017-06-07
|
8
|
+
### Fixed
|
9
|
+
- Allow configuring request formats to take into account through
|
10
|
+
`request_formats` configuration option
|
11
|
+
|
12
|
+
## [0.2.1] - 2017-04-13
|
8
13
|
### Fixed
|
9
14
|
- Ignore expired token revocation
|
10
15
|
|
data/README.md
CHANGED
@@ -55,7 +55,7 @@ Currently, HS256 algorithm is the one in use.
|
|
55
55
|
|
56
56
|
You have to tell which user models you want to be able to authenticate with JWT tokens. For them, the authentication process will be like this:
|
57
57
|
|
58
|
-
- A user authenticates
|
58
|
+
- A user authenticates through devise create session request (for example, using the standard `:database_authenticatable` module).
|
59
59
|
- If the authentication succeeds, a JWT token is dispatched to the client in the `Authorization` response header, with format `Bearer #{token}` (tokens are also dispatched on a successful sign up).
|
60
60
|
- The client can use this token to authenticate following requests for the same user, providing it in the `Authorization` request header, also with format `Bearer #{token}`
|
61
61
|
- When the client visits devise destroy session request, the token is revoked.
|
@@ -253,6 +253,28 @@ jwt.revocation_requests = [
|
|
253
253
|
|
254
254
|
**Important**: You are encouraged to delimit your regular expression with `^` and `$` to avoid unintentional matches.
|
255
255
|
|
256
|
+
#### request_formats
|
257
|
+
|
258
|
+
Request formats that must be processed (in order to dispatch or revoke tokens).
|
259
|
+
|
260
|
+
It must be a hash of devise scopes as keys and an array of request formats as
|
261
|
+
values. When a scope is not present or if it has a nil item, requests without
|
262
|
+
format will be taken into account.
|
263
|
+
|
264
|
+
For example, with following configuration, `user` scope would dispatch and
|
265
|
+
revoke tokens in `json` requests (as in `/users/sign_in.json`), while
|
266
|
+
`admin_user` would do it in `xml` and with no format (as in
|
267
|
+
`/admin_user/sign_in.xml` and `/admin_user/sign_in`).
|
268
|
+
|
269
|
+
```ruby
|
270
|
+
jwt.request_formats = {
|
271
|
+
user: [:json],
|
272
|
+
admin_user: [nil, :xml]
|
273
|
+
}
|
274
|
+
```
|
275
|
+
|
276
|
+
By default, only requests without format are processed.
|
277
|
+
|
256
278
|
## Development
|
257
279
|
|
258
280
|
There are docker and docker-compose files configured to create a development environment for this gem. So, if you use Docker you only need to run:
|
data/lib/devise/jwt.rb
CHANGED
@@ -42,6 +42,21 @@ module Devise
|
|
42
42
|
forward_to_warden(:revocation_requests, value)
|
43
43
|
end
|
44
44
|
|
45
|
+
# A hash of warden scopes as keys and an array of request formats that will
|
46
|
+
# be processed as values. When a scope is not present or if it has a nil
|
47
|
+
# item, requests without format will be taken into account.
|
48
|
+
#
|
49
|
+
# For example, with following configuration, `user` scope would dispatch and
|
50
|
+
# revoke tokens in `json` requests, while `admin_user` would do it in `xml`
|
51
|
+
# and with no format.
|
52
|
+
#
|
53
|
+
# @example
|
54
|
+
# {
|
55
|
+
# user: [:json],
|
56
|
+
# admin_user: [nil, :xml]
|
57
|
+
# }
|
58
|
+
setting :request_formats, {}
|
59
|
+
|
45
60
|
def self.forward_to_warden(setting, value)
|
46
61
|
Warden::JWTAuth.config.send("#{setting}=", value)
|
47
62
|
end
|
@@ -62,36 +62,43 @@ module Devise
|
|
62
62
|
|
63
63
|
def add_sign_in_request(inspector)
|
64
64
|
return unless inspector.session?
|
65
|
-
defaults[:dispatch_requests]
|
65
|
+
defaults[:dispatch_requests].push(*sign_in_requests(inspector))
|
66
66
|
end
|
67
67
|
|
68
68
|
def add_registration_request(inspector)
|
69
69
|
return unless inspector.registration?
|
70
|
-
defaults[:dispatch_requests]
|
70
|
+
defaults[:dispatch_requests].push(*registration_requests(inspector))
|
71
71
|
end
|
72
72
|
|
73
73
|
def add_revocation_requests(inspector)
|
74
74
|
return unless inspector.session?
|
75
|
-
defaults[:revocation_requests]
|
75
|
+
defaults[:revocation_requests].push(*sign_out_requests(inspector))
|
76
76
|
end
|
77
77
|
|
78
|
-
def
|
79
|
-
|
78
|
+
def sign_in_requests(inspector)
|
79
|
+
requests(inspector, :sign_in)
|
80
80
|
end
|
81
81
|
|
82
|
-
def
|
83
|
-
|
82
|
+
def sign_out_requests(inspector)
|
83
|
+
requests(inspector, :sign_out)
|
84
84
|
end
|
85
85
|
|
86
|
-
def
|
87
|
-
|
86
|
+
def registration_requests(inspector)
|
87
|
+
requests(inspector, :registration)
|
88
88
|
end
|
89
89
|
|
90
|
-
# :reek:
|
91
|
-
def
|
90
|
+
# :reek:FeatureEnvy
|
91
|
+
def requests(inspector, name)
|
92
92
|
path = inspector.path(name)
|
93
93
|
method = inspector.method(name)
|
94
|
-
|
94
|
+
inspector.formats.map do |format|
|
95
|
+
request_for_format(path, method, format)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def request_for_format(path, method, format)
|
100
|
+
path_regexp = format ? /^#{path}.#{format}$/ : /^#{path}$/
|
101
|
+
[method, path_regexp]
|
95
102
|
end
|
96
103
|
end
|
97
104
|
end
|
@@ -44,6 +44,10 @@ module Devise
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
+
def formats
|
48
|
+
JWT.config.request_formats[scope] || default_formats
|
49
|
+
end
|
50
|
+
|
47
51
|
private
|
48
52
|
|
49
53
|
def path_parts(name)
|
@@ -64,6 +68,10 @@ module Devise
|
|
64
68
|
def sign_out_via
|
65
69
|
mapping.sign_out_via.to_s.upcase
|
66
70
|
end
|
71
|
+
|
72
|
+
def default_formats
|
73
|
+
[nil]
|
74
|
+
end
|
67
75
|
end
|
68
76
|
end
|
69
77
|
end
|
data/lib/devise/jwt/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise-jwt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marc Busqué
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: devise
|