zaikio-jwt_auth 0.2.2 → 0.3.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: ec233ed24502a3c1787c5c8825ecbf4c889608522152192739ab5938a91e720a
4
- data.tar.gz: d15c29da5093ec019ff083874321d6fe709946eee57e464bb4b80ea8c89a7277
3
+ metadata.gz: cf4b231af0a8a9fb3d9c48d577c85d12ef02b2605418b22abf21512f1d714433
4
+ data.tar.gz: 2d106d3d2821edc1d24d96d5e69cda3e3b4e4d04b0f062c26a1d90fd2b223f3f
5
5
  SHA512:
6
- metadata.gz: 96a305a591381bbd7c768f27faaaf859dd2f01cca1032bb9f7b38b8e8a7b240c16da12e438cd6a325abe43ddf3f6d75602cfd068a9746348d52e89bb9274ce2d
7
- data.tar.gz: a46b2f66a46b9a906b3ee2bcc0f98ee8ac88412d3bbaac81e0bebdaad2d831749d26a935f7d86c694fedc21ad890a277590fe582843629c8b98b96caf5b474d6
6
+ metadata.gz: 325c2144f07a582d0bc3e4f3eeadfd68a1940e5230cefaa3a1b7bd9231b7bb74c86ccc1922f457945e78b05a8286f68b7551851705592e0c3838ebfa06f654a1
7
+ data.tar.gz: 6fc738d1533e5e06a15ebe476acd0a20b166bd08d5065462fdfe012363ae598d258e324806e0e35651f129b0d5dd5d8974ec92bb49b06e644c9bd2fb5f7a1236
@@ -2,8 +2,8 @@ module Zaikio
2
2
  module JWTAuth
3
3
  class RevokeAccessTokenJob < ApplicationJob
4
4
  def perform(event)
5
- DirectoryCache.update("api/v1/blacklisted_access_tokens.json", expires_after: 60.minutes) do |data|
6
- data["blacklisted_token_ids"] << event.payload["access_token_id"]
5
+ DirectoryCache.update("api/v1/revoked_access_tokens.json", expires_after: 60.minutes) do |data|
6
+ data["revoked_token_ids"] << event.payload["access_token_id"]
7
7
  data
8
8
  end
9
9
  end
@@ -26,15 +26,16 @@ module Zaikio
26
26
  end
27
27
 
28
28
  def self.revoked_jwt?(jti)
29
- blacklisted_token_ids.include?(jti)
29
+ revoked_token_ids.include?(jti)
30
30
  end
31
31
 
32
- def self.blacklisted_token_ids
32
+ def self.revoked_token_ids
33
33
  return [] if mocked_jwt_payload
34
34
 
35
- return configuration.blacklisted_token_ids if configuration.blacklisted_token_ids
36
-
37
- DirectoryCache.fetch("api/v1/blacklisted_access_tokens.json", expires_after: 60.minutes)["blacklisted_token_ids"]
35
+ configuration.revoked_token_ids || DirectoryCache.fetch(
36
+ "api/v1/revoked_access_tokens.json",
37
+ expires_after: 60.minutes
38
+ )["revoked_token_ids"]
38
39
  end
39
40
 
40
41
  def self.included(base)
@@ -70,24 +71,24 @@ module Zaikio
70
71
 
71
72
  token_data = TokenData.new(jwt_payload)
72
73
 
73
- return if show_error_if_token_is_blacklisted(token_data)
74
+ return if show_error_if_token_is_revoked(token_data)
74
75
 
75
76
  return if show_error_if_authorize_by_jwt_subject_type_fails(token_data)
76
77
 
77
78
  return if show_error_if_authorize_by_jwt_scopes_fails(token_data)
78
79
 
79
- send(:after_jwt_auth, token_data) if respond_to?(:after_jwt_auth)
80
+ send(:after_jwt_auth, token_data) if respond_to?(:after_jwt_auth, true)
80
81
  rescue JWT::ExpiredSignature
81
82
  render_error("jwt_expired") && (return)
82
83
  rescue JWT::DecodeError
83
84
  render_error("invalid_jwt") && (return)
84
85
  end
85
86
 
86
- def update_blacklisted_access_tokens_by_webhook
87
+ def update_revoked_access_tokens_by_webhook
87
88
  return unless params[:name] == "directory.revoked_access_token"
88
89
 
89
- DirectoryCache.update("api/v1/blacklisted_access_tokens.json", expires_after: 60.minutes) do |data|
90
- data["blacklisted_token_ids"] << params[:payload][:access_token_id]
90
+ DirectoryCache.update("api/v1/revoked_access_tokens.json", expires_after: 60.minutes) do |data|
91
+ data["revoked_token_ids"] << params[:payload][:access_token_id]
91
92
  data
92
93
  end
93
94
 
@@ -130,7 +131,7 @@ module Zaikio
130
131
  render_error("unpermitted_subject")
131
132
  end
132
133
 
133
- def show_error_if_token_is_blacklisted(token_data)
134
+ def show_error_if_token_is_revoked(token_data)
134
135
  return unless Zaikio::JWTAuth.revoked_jwt?(token_data.jti)
135
136
 
136
137
  render_error("invalid_jwt")
@@ -4,21 +4,21 @@ module Zaikio
4
4
  module JWTAuth
5
5
  class Configuration
6
6
  HOSTS = {
7
- development: "http://directory.zaikio.test",
8
- test: "http://directory.zaikio.test",
9
- staging: "https://directory.staging.zaikio.com",
10
- sandbox: "https://directory.sandbox.zaikio.com",
11
- production: "https://directory.zaikio.com"
7
+ development: "http://hub.zaikio.test",
8
+ test: "http://hub.zaikio.test",
9
+ staging: "https://hub.staging.zaikio.com",
10
+ sandbox: "https://hub.sandbox.zaikio.com",
11
+ production: "https://hub.zaikio.com"
12
12
  }.freeze
13
13
 
14
14
  attr_accessor :app_name
15
15
  attr_accessor :redis, :host
16
16
  attr_reader :environment
17
- attr_writer :logger, :blacklisted_token_ids, :keys
17
+ attr_writer :logger, :revoked_token_ids, :keys
18
18
 
19
19
  def initialize
20
20
  @environment = :sandbox
21
- @blacklisted_token_ids = nil
21
+ @revoked_token_ids = nil
22
22
  end
23
23
 
24
24
  def logger
@@ -31,11 +31,11 @@ module Zaikio
31
31
  end
32
32
 
33
33
  def keys
34
- @keys.is_a?(Proc) ? @keys.call : @keys
34
+ defined?(@keys) && @keys.is_a?(Proc) ? @keys.call : @keys
35
35
  end
36
36
 
37
- def blacklisted_token_ids
38
- @blacklisted_token_ids.is_a?(Proc) ? @blacklisted_token_ids.call : @blacklisted_token_ids
37
+ def revoked_token_ids
38
+ @revoked_token_ids.is_a?(Proc) ? @revoked_token_ids.call : @revoked_token_ids
39
39
  end
40
40
 
41
41
  private
@@ -14,7 +14,7 @@ module Zaikio
14
14
  jti: "unique-access-token-id",
15
15
  nbf: Time.now.to_i,
16
16
  exp: 1.hour.from_now.to_i,
17
- jku: "http://directory.zaikio.test/api/v1/jwt_public_keys.json",
17
+ jku: "http://hub.zaikio.test/api/v1/jwt_public_keys.json",
18
18
  scope: []
19
19
  }.merge(extra_payload).stringify_keys
20
20
  end
@@ -33,6 +33,10 @@ module Zaikio
33
33
  @payload["jti"]
34
34
  end
35
35
 
36
+ def expires_at
37
+ Time.at(@payload["exp"]).to_datetime
38
+ end
39
+
36
40
  # scope_options is an array of objects with:
37
41
  # scope, app_name (optional), except/only (array, optional)
38
42
  def scope_by_configurations?(scope_configurations, action_name, context)
@@ -1,5 +1,5 @@
1
1
  module Zaikio
2
2
  module JWTAuth
3
- VERSION = "0.2.2".freeze
3
+ VERSION = "0.3.1".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zaikio-jwt_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
- - Crispy Mountain GmbH
7
+ - crispymtn
8
+ - Jalyna Schröder
9
+ - Martin Spickermann
8
10
  autorequire:
9
11
  bindir: bin
10
12
  cert_chain: []
11
- date: 2020-04-28 00:00:00.000000000 Z
13
+ date: 2020-10-15 00:00:00.000000000 Z
12
14
  dependencies:
13
15
  - !ruby/object:Gem::Dependency
14
16
  name: oj
@@ -30,14 +32,14 @@ dependencies:
30
32
  requirements:
31
33
  - - ">="
32
34
  - !ruby/object:Gem::Version
33
- version: 6.0.2.2
35
+ version: 5.0.0
34
36
  type: :runtime
35
37
  prerelease: false
36
38
  version_requirements: !ruby/object:Gem::Requirement
37
39
  requirements:
38
40
  - - ">="
39
41
  - !ruby/object:Gem::Version
40
- version: 6.0.2.2
42
+ version: 5.0.0
41
43
  - !ruby/object:Gem::Dependency
42
44
  name: jwt
43
45
  requirement: !ruby/object:Gem::Requirement
@@ -54,7 +56,9 @@ dependencies:
54
56
  version: 2.2.1
55
57
  description: JWT-Based authentication and authorization with zaikio.
56
58
  email:
59
+ - op@crispymtn.com
57
60
  - js@crispymtn.com
61
+ - spickermann@gmail.com
58
62
  executables: []
59
63
  extensions: []
60
64
  extra_rdoc_files: []
@@ -93,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
97
  - !ruby/object:Gem::Version
94
98
  version: '0'
95
99
  requirements: []
96
- rubygems_version: 3.1.2
100
+ rubygems_version: 3.0.3
97
101
  signing_key:
98
102
  specification_version: 4
99
103
  summary: JWT-Based authentication and authorization with zaikio