authkeeper 0.1.11 → 0.1.12
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 35fee3ca91b02463c3ae188eaac29ec61a1648037e9d9fe4afc22c7111cd14f9
|
|
4
|
+
data.tar.gz: a5dfcc76f5178fcd781dc11953caf07c0b2642ce67df97cd9ab2321bd84bda33
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 87bbb1e064c3895257a4e52f7562fd01c4bea1fec9bc42a9d09672990af592105a598b26e89a9edfba421704f06443e33f3a653f61690b419744198cd780c8b1
|
|
7
|
+
data.tar.gz: 5e4390d669b30a5bab62ead49016f407b201b7c2c5c97240ddfe6b2c266ee110bbd203e93d903dc53904616ce973ae6f4b40768e7a53bd16084a2a882622042b
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Authkeeper
|
|
4
|
+
class FetchUuidService
|
|
5
|
+
include AuthkeeperDeps[jwt_encoder: 'jwt_encoder']
|
|
6
|
+
|
|
7
|
+
def call(token:)
|
|
8
|
+
payload = extract_uuid(token)
|
|
9
|
+
return { errors: ['Forbidden'] } if payload.blank?
|
|
10
|
+
return { errors: ['Forbidden'] } if payload['uuid'].blank?
|
|
11
|
+
|
|
12
|
+
{ result: payload['uuid'] }
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
def extract_uuid(token)
|
|
18
|
+
jwt_encoder.decode(token: token)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -5,7 +5,7 @@ module Authkeeper
|
|
|
5
5
|
InitializeError = Class.new(StandardError)
|
|
6
6
|
|
|
7
7
|
attr_accessor :user_model, :user_session_model, :access_token_name, :domain, :fallback_url_session_name, :omniauth_providers,
|
|
8
|
-
:token_expiration_seconds
|
|
8
|
+
:token_expiration_seconds, :current_user_cache_minutes
|
|
9
9
|
attr_reader :omniauth_configs
|
|
10
10
|
|
|
11
11
|
def initialize
|
|
@@ -20,6 +20,8 @@ module Authkeeper
|
|
|
20
20
|
@omniauth_configs = {}
|
|
21
21
|
|
|
22
22
|
@token_expiration_seconds = 18_144_000 # 30.days
|
|
23
|
+
|
|
24
|
+
@current_user_cache_minutes = nil
|
|
23
25
|
end
|
|
24
26
|
|
|
25
27
|
def validate
|
data/lib/authkeeper/container.rb
CHANGED
|
@@ -37,6 +37,7 @@ module Authkeeper
|
|
|
37
37
|
register('services.providers.vk') { Authkeeper::Providers::Vk.new }
|
|
38
38
|
register('services.providers.discord') { Authkeeper::Providers::Discord.new }
|
|
39
39
|
|
|
40
|
+
register('services.fetch_uuid') { Authkeeper::FetchUuidService.new }
|
|
40
41
|
register('services.fetch_session') { Authkeeper::FetchSessionService.new }
|
|
41
42
|
register('services.generate_token') { Authkeeper::GenerateTokenService.new }
|
|
42
43
|
end
|
|
@@ -14,6 +14,27 @@ module Authkeeper
|
|
|
14
14
|
private
|
|
15
15
|
|
|
16
16
|
def set_current_user
|
|
17
|
+
return find_user if Authkeeper.configuration.current_user_cache_minutes.nil?
|
|
18
|
+
|
|
19
|
+
access_token = cookies_token.presence || bearer_token.presence || params_token
|
|
20
|
+
return unless access_token
|
|
21
|
+
|
|
22
|
+
auth_uuid = Authkeeper::Container['services.fetch_uuid'].call(token: access_token)
|
|
23
|
+
return if auth_uuid[:errors].present?
|
|
24
|
+
|
|
25
|
+
user_id =
|
|
26
|
+
Rails.cache.fetch(
|
|
27
|
+
"authkeeper_cached_user_v2/#{auth_uuid[:result]}",
|
|
28
|
+
expires_in: Authkeeper.configuration.current_user_cache_minutes.minutes,
|
|
29
|
+
race_condition_ttl: 10.seconds
|
|
30
|
+
) do
|
|
31
|
+
find_user
|
|
32
|
+
current_user&.id
|
|
33
|
+
end
|
|
34
|
+
@current_user ||= User.find_by(id: user_id)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def find_user
|
|
17
38
|
access_token = cookies_token.presence || bearer_token.presence || params_token
|
|
18
39
|
return unless access_token
|
|
19
40
|
|
|
@@ -65,6 +86,9 @@ module Authkeeper
|
|
|
65
86
|
if access_token
|
|
66
87
|
auth_call = Authkeeper::Container['services.fetch_session'].call(token: access_token)
|
|
67
88
|
auth_call[:result].destroy if auth_call[:result]
|
|
89
|
+
|
|
90
|
+
auth_uuid = Authkeeper::Container['services.fetch_uuid'].call(token: access_token)
|
|
91
|
+
Rails.cache.delete("authkeeper_cached_user_v2/#{auth_uuid[:result]}") if auth_uuid[:result]
|
|
68
92
|
end
|
|
69
93
|
|
|
70
94
|
cookies.delete(access_token_name)
|
data/lib/authkeeper/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: authkeeper
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.12
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bogdanov Anton
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-
|
|
11
|
+
date: 2025-12-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|
|
@@ -67,6 +67,7 @@ files:
|
|
|
67
67
|
- app/mailers/authkeeper/application_mailer.rb
|
|
68
68
|
- app/models/authkeeper/application_record.rb
|
|
69
69
|
- app/services/authkeeper/fetch_session_service.rb
|
|
70
|
+
- app/services/authkeeper/fetch_uuid_service.rb
|
|
70
71
|
- app/services/authkeeper/generate_token_service.rb
|
|
71
72
|
- app/services/authkeeper/providers/discord.rb
|
|
72
73
|
- app/services/authkeeper/providers/github.rb
|