devise-jwt 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +43 -1
- data/devise-jwt.gemspec +1 -1
- data/lib/devise/jwt/test_helpers.rb +31 -0
- data/lib/devise/jwt/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ae27be60b14e728a0f86baaef42c0dc4bf04813
|
4
|
+
data.tar.gz: b671e8223fcc31bfbae9e020ef3c363b600e63e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b78d89e4b8ef89e96a07b7ea49417b52aa04672ae585056c335d74a1fbb9c0f4e8ee7f7442df44753f20de04ebe7607af48250395451fd944595bfcf99229b23
|
7
|
+
data.tar.gz: 232d88e6253117a24b34909c253fb4cd9ae81f147a2bd4e85b79e48c9d18d04cacc42c6d4f881b5ff6be805bf0903262fcedb357a3228e9b1854fb44daae9666
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,10 @@ 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.5.2] - 2017-12-23
|
8
|
+
### Added
|
9
|
+
- Added a test helper to authenticate request headers
|
10
|
+
|
7
11
|
## [0.5.1] - 2017-12-11
|
8
12
|
### Added
|
9
13
|
- Update `warden-jwt_auth` dependency to ensure JWT scopes are not fetched from
|
data/README.md
CHANGED
@@ -26,7 +26,7 @@ You can read about which security concerns this library takes into account and a
|
|
26
26
|
Add this line to your application's Gemfile:
|
27
27
|
|
28
28
|
```ruby
|
29
|
-
gem 'devise-jwt', '~> 0.5.
|
29
|
+
gem 'devise-jwt', '~> 0.5.2'
|
30
30
|
```
|
31
31
|
|
32
32
|
And then execute:
|
@@ -309,6 +309,48 @@ class User < ApplicationRecord
|
|
309
309
|
end
|
310
310
|
```
|
311
311
|
|
312
|
+
### Testing
|
313
|
+
|
314
|
+
Models configured with `:jwt_authenticatable` can't be retrieved from the
|
315
|
+
session. For this reason, `sign_in` devise testing helper methods won't work as
|
316
|
+
expected.
|
317
|
+
|
318
|
+
What you need to do in order to authenticate test environment requests is the
|
319
|
+
same that you will do in production: to provide a valid token in the
|
320
|
+
`Authorization` header (in the form of `Bearer #{token}`) at every request.
|
321
|
+
|
322
|
+
There are two ways you can get a valid token:
|
323
|
+
|
324
|
+
- Inspecting the `Authorization` response header after a valid sign in request.
|
325
|
+
- Manually creating it.
|
326
|
+
|
327
|
+
The first option tests the real workflow of your application, but it can slow
|
328
|
+
things if you perform it at every test.
|
329
|
+
|
330
|
+
For the second option, a test helper is provided in order to add the
|
331
|
+
`Authorization` name/value pair to given request headers. You can use it as in
|
332
|
+
the following example:
|
333
|
+
|
334
|
+
```ruby
|
335
|
+
# First, require the helper module
|
336
|
+
require 'devise/jwt/test_helpers'
|
337
|
+
|
338
|
+
# ...
|
339
|
+
|
340
|
+
it 'tests something' do
|
341
|
+
user = fetch_my_user()
|
342
|
+
headers = { 'Accept' => 'application/json', 'Content-Type' => 'application/json' }
|
343
|
+
# This will add a valid token for `user` in the `Authorization` header
|
344
|
+
auth_headers = Devise::JWT::TestHelpers.auth_headers(headers, user)
|
345
|
+
|
346
|
+
get '/my/end_point', headers: auth_headers
|
347
|
+
|
348
|
+
expect_something()
|
349
|
+
end
|
350
|
+
```
|
351
|
+
|
352
|
+
Usually you will wrap this in your own test helper.
|
353
|
+
|
312
354
|
### Configuration reference
|
313
355
|
|
314
356
|
This library can be configured calling `jwt` on devise config object:
|
data/devise-jwt.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
24
|
spec.add_dependency 'devise', '~> 4.0'
|
25
|
-
spec.add_dependency 'warden-jwt_auth', '~> 0.3.
|
25
|
+
spec.add_dependency 'warden-jwt_auth', '~> 0.3.2'
|
26
26
|
|
27
27
|
spec.add_development_dependency "bundler", "~> 1.12"
|
28
28
|
spec.add_development_dependency "rake", "~> 10.0"
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Devise
|
4
|
+
module JWT
|
5
|
+
# Helpers to make testing authorization through JWT easier
|
6
|
+
module TestHelpers
|
7
|
+
# Returns headers with a valid token in the `Authorization` header
|
8
|
+
# added.
|
9
|
+
#
|
10
|
+
# Be aware that a fresh copy of `headers` is returned with the new
|
11
|
+
# key/value pair added, instead of modifying given argument.
|
12
|
+
#
|
13
|
+
# @param headers [Hash] Headers to which add the `Authorization` item.
|
14
|
+
# @param user [ActiveRecord::Base] The user to authenticate.
|
15
|
+
# @param scope [Symbol] The warden scope. If `nil` it will be
|
16
|
+
# autodetected.
|
17
|
+
# @param aud [String] The aud claim. If `nil` it will be autodetected from
|
18
|
+
# the header name configured in `Devise::JWT.config.aud_header`.
|
19
|
+
#
|
20
|
+
# :reek:LongParemeterList
|
21
|
+
def self.auth_headers(headers, user, scope: nil, aud: nil)
|
22
|
+
scope ||= Devise::Mapping.find_scope!(user)
|
23
|
+
aud ||= headers[Warden::JWTAuth.config.aud_header]
|
24
|
+
token, _payload = Warden::JWTAuth::UserEncoder.new.call(
|
25
|
+
user, scope, aud
|
26
|
+
)
|
27
|
+
Warden::JWTAuth::HeaderParser.to_headers(headers, token)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
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.5.
|
4
|
+
version: 0.5.2
|
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-12-
|
11
|
+
date: 2017-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: devise
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.3.
|
33
|
+
version: 0.3.2
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.3.
|
40
|
+
version: 0.3.2
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -201,6 +201,7 @@ files:
|
|
201
201
|
- lib/devise/jwt/revocation_strategies/jti_matcher.rb
|
202
202
|
- lib/devise/jwt/revocation_strategies/null.rb
|
203
203
|
- lib/devise/jwt/revocation_strategies/whitelist.rb
|
204
|
+
- lib/devise/jwt/test_helpers.rb
|
204
205
|
- lib/devise/jwt/version.rb
|
205
206
|
homepage: https://github.com/waiting-for-dev/devise-jwt
|
206
207
|
licenses:
|