jwt-auth 1.2.0 → 2.0.0

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
  SHA1:
3
- metadata.gz: b8bbf5c4951540d2735fdd31dd738b79bf60a70d
4
- data.tar.gz: 5a2efb6655951066e3cc6dcad47cf266a7b2fcbd
3
+ metadata.gz: 071e994384ea5a8b92ebcf11e387e0b3620c032d
4
+ data.tar.gz: ff916fe29fb2df997ba8f526ef7dc2992d76f310
5
5
  SHA512:
6
- metadata.gz: 99d861c597546f3474672dd98a29a2bc4d95598cf4a50a881d6a8866f1d746e721a29bc9b03ed0bc4cbdab60e3d7b5fa9d2881983ff8384339339438fe99bdde
7
- data.tar.gz: 982e74b49487c254d8b57eb6ac4b197be42d55d8f6bed42f075bd79efb4332aacf44e1f62bfedd20a29f90b0b55925bbabcb6bb5ade055b46ae4b91c18be0631
6
+ metadata.gz: 96bfb99af4c98261d9d8069d6522d729a823100515deac9d2f3d0a37b3062cf9c185e95b0e307362344a319dc0159acf6b5958012378cd0e27fc46c7bac6757d
7
+ data.tar.gz: 536591c41ada1b6d7f793d3dc3a070567e418ce6b9d0b1f8d5a48a32d2209b9833c431342db08d7766dad944b280f88e6da17b8a4c93e03b343747dfc7a2306b
data/README.md CHANGED
@@ -53,11 +53,19 @@ end
53
53
 
54
54
  ```
55
55
 
56
- Include controller methods in your `ApplicationController`:
56
+ Include controller methods in your `ApplicationController` and handle unauthorized errors:
57
57
 
58
58
  ```ruby
59
59
  class ApplicationController < ActionController::API
60
60
  include JWT::Auth::Authentication
61
+
62
+ rescue_from JWT::Auth::UnauthorizedError, :with => :handle_unauthorized
63
+
64
+ protected
65
+
66
+ def handle_unauthorized
67
+ head :unauthorized
68
+ end
61
69
  end
62
70
  ```
63
71
 
@@ -3,6 +3,7 @@
3
3
  require 'jwt'
4
4
 
5
5
  require 'jwt/auth/version'
6
+ require 'jwt/auth/errors'
6
7
  require 'jwt/auth/configuration'
7
8
  require 'jwt/auth/authenticatable'
8
9
  require 'jwt/auth/authentication'
@@ -19,7 +19,7 @@ module JWT
19
19
  # Authenticate a request
20
20
  #
21
21
  def authenticate_user
22
- return head :unauthorized unless token&.valid?
22
+ raise JWT::Auth::UnauthorizedError unless token&.valid?
23
23
 
24
24
  # Regenerate token (renews expiration date)
25
25
  add_token_to_response
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JWT
4
+ module Auth
5
+ class Error < StandardError; end
6
+
7
+ class UnauthorizedError < Error; end
8
+ end
9
+ end
@@ -13,7 +13,7 @@ module JWT
13
13
  attr_accessor :expiration, :subject
14
14
 
15
15
  def valid?
16
- subject && Time.at(expiration).future?
16
+ subject && expiration && Time.at(expiration).future?
17
17
  end
18
18
 
19
19
  def renew!
@@ -2,6 +2,6 @@
2
2
 
3
3
  module JWT
4
4
  module Auth
5
- VERSION = '1.2.0'
5
+ VERSION = '2.0.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jwt-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Dejonckheere
@@ -114,6 +114,7 @@ files:
114
114
  - lib/jwt/auth/authenticatable.rb
115
115
  - lib/jwt/auth/authentication.rb
116
116
  - lib/jwt/auth/configuration.rb
117
+ - lib/jwt/auth/errors.rb
117
118
  - lib/jwt/auth/token.rb
118
119
  - lib/jwt/auth/version.rb
119
120
  - spec/configuration_spec.rb