zaikio-jwt_auth 0.2.3 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13ffa04390d58b8362bdcdbec9faf414744c750832bec2059269053456fc92c1
4
- data.tar.gz: fa892487c030ac6f8215273b24f40975a6029888f737c8bebc1055170b062ea9
3
+ metadata.gz: 0ed1625f0c3baa4a4ffaa294a558f4da335e647708aabe66e8a51924bbbd02d5
4
+ data.tar.gz: 4f5495c0aa6bda2d70cdbf560c3db957ffe65d8017d49d97dcc9c8139b6a69d0
5
5
  SHA512:
6
- metadata.gz: c0a29c61eea44dec079b7a10039cc67f6ca3f16bd89be7e52698afec6d8e5760d2afb229d76dc2e2ade8e103df219e40017d65a91cdd8c80a47e460a8288b699
7
- data.tar.gz: 8ff49fc384edc4684b5cf1b54e86650cd03cd4770fbebf6a2f21207dd0e5bfbb178dcdd4dc76473917246a29980f936b61266310b2b3c68548476225db873862
6
+ metadata.gz: 77d5cfcc03cd050812d8b01b0e6d8d0954198bb6a002f86c46fb304c515bb54f9661535d0d7d6ed5b67ebcc552cb4d1a61affb40959e57c576f5b602cb74c980
7
+ data.tar.gz: 30d094c7015d1c73f059282277ba528994db14f4b67525f05265240cd9bc7986a958b13e9cb34765b3e1e36b4c96d7f60dc349b04580bbf7ef56ebd7db48a2ee
@@ -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
@@ -1,5 +1,6 @@
1
1
  require "jwt"
2
2
  require "oj"
3
+ require "active_support/core_ext/integer/time"
3
4
  require "zaikio/jwt_auth/railtie"
4
5
  require "zaikio/jwt_auth/configuration"
5
6
  require "zaikio/jwt_auth/directory_cache"
@@ -26,15 +27,16 @@ module Zaikio
26
27
  end
27
28
 
28
29
  def self.revoked_jwt?(jti)
29
- blacklisted_token_ids.include?(jti)
30
+ revoked_token_ids.include?(jti)
30
31
  end
31
32
 
32
- def self.blacklisted_token_ids
33
+ def self.revoked_token_ids
33
34
  return [] if mocked_jwt_payload
34
35
 
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"]
36
+ configuration.revoked_token_ids || DirectoryCache.fetch(
37
+ "api/v1/revoked_access_tokens.json",
38
+ expires_after: 60.minutes
39
+ )["revoked_token_ids"]
38
40
  end
39
41
 
40
42
  def self.included(base)
@@ -70,24 +72,24 @@ module Zaikio
70
72
 
71
73
  token_data = TokenData.new(jwt_payload)
72
74
 
73
- return if show_error_if_token_is_blacklisted(token_data)
75
+ return if show_error_if_token_is_revoked(token_data)
74
76
 
75
77
  return if show_error_if_authorize_by_jwt_subject_type_fails(token_data)
76
78
 
77
79
  return if show_error_if_authorize_by_jwt_scopes_fails(token_data)
78
80
 
79
- send(:after_jwt_auth, token_data) if respond_to?(:after_jwt_auth)
81
+ send(:after_jwt_auth, token_data) if respond_to?(:after_jwt_auth, true)
80
82
  rescue JWT::ExpiredSignature
81
83
  render_error("jwt_expired") && (return)
82
84
  rescue JWT::DecodeError
83
85
  render_error("invalid_jwt") && (return)
84
86
  end
85
87
 
86
- def update_blacklisted_access_tokens_by_webhook
88
+ def update_revoked_access_tokens_by_webhook
87
89
  return unless params[:name] == "directory.revoked_access_token"
88
90
 
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]
91
+ DirectoryCache.update("api/v1/revoked_access_tokens.json", expires_after: 60.minutes) do |data|
92
+ data["revoked_token_ids"] << params[:payload][:access_token_id]
91
93
  data
92
94
  end
93
95
 
@@ -130,7 +132,7 @@ module Zaikio
130
132
  render_error("unpermitted_subject")
131
133
  end
132
134
 
133
- def show_error_if_token_is_blacklisted(token_data)
135
+ def show_error_if_token_is_revoked(token_data)
134
136
  return unless Zaikio::JWTAuth.revoked_jwt?(token_data.jti)
135
137
 
136
138
  render_error("invalid_jwt")
@@ -4,25 +4,24 @@ 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
- attr_accessor :app_name
15
- attr_accessor :redis, :host
14
+ attr_accessor :app_name, :redis, :host
16
15
  attr_reader :environment
17
- attr_writer :logger, :blacklisted_token_ids, :keys
16
+ attr_writer :logger, :revoked_token_ids, :keys
18
17
 
19
18
  def initialize
20
19
  @environment = :sandbox
21
- @blacklisted_token_ids = nil
20
+ @revoked_token_ids = nil
22
21
  end
23
22
 
24
23
  def logger
25
- @logger ||= Logger.new(STDOUT)
24
+ @logger ||= Logger.new($stdout)
26
25
  end
27
26
 
28
27
  def environment=(env)
@@ -31,11 +30,11 @@ module Zaikio
31
30
  end
32
31
 
33
32
  def keys
34
- @keys.is_a?(Proc) ? @keys.call : @keys
33
+ defined?(@keys) && @keys.is_a?(Proc) ? @keys.call : @keys
35
34
  end
36
35
 
37
- def blacklisted_token_ids
38
- @blacklisted_token_ids.is_a?(Proc) ? @blacklisted_token_ids.call : @blacklisted_token_ids
36
+ def revoked_token_ids
37
+ @revoked_token_ids.is_a?(Proc) ? @revoked_token_ids.call : @revoked_token_ids
39
38
  end
40
39
 
41
40
  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
@@ -2,7 +2,7 @@ module Zaikio
2
2
  module JWTAuth
3
3
  class TokenData
4
4
  def self.subject_format
5
- %r{^((\w+)/((\w|-)+)\>)?(\w+)/((\w|-)+)$}
5
+ %r{^((\w+)/((\w|-)+)>)?(\w+)/((\w|-)+)$}
6
6
  end
7
7
 
8
8
  def self.actions_by_permission
@@ -33,6 +33,10 @@ module Zaikio
33
33
  @payload["jti"]
34
34
  end
35
35
 
36
+ def expires_at
37
+ Time.zone.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.3".freeze
3
+ VERSION = "0.4.0".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.3
4
+ version: 0.4.0
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: 2021-01-06 00:00:00.000000000 Z
12
14
  dependencies:
13
15
  - !ruby/object:Gem::Dependency
14
16
  name: oj
@@ -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: []
@@ -86,14 +90,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
86
90
  requirements:
87
91
  - - ">="
88
92
  - !ruby/object:Gem::Version
89
- version: '0'
93
+ version: 2.6.5
90
94
  required_rubygems_version: !ruby/object:Gem::Requirement
91
95
  requirements:
92
96
  - - ">="
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