zaikio-oauth_client 0.19.0 → 0.19.3
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 +4 -4
- data/lib/zaikio/oauth_client/test_helper.rb +27 -1
- data/lib/zaikio/oauth_client/version.rb +1 -1
- data/lib/zaikio/oauth_client.rb +9 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58d2e1d10678b7eddb4afc7931c94e04299b63027c3b02c5773e03bf74b29b7d
|
4
|
+
data.tar.gz: 44459fbc11ec98ccdd1f88819416f50b704a1d9f1a32a7a24d17a92b863563e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4dd805f5c186d1d502afd9788b77ed7f9178672c841b03d7f9c5c97f81d5dc3243a255f1087f1e49bc312a024b4758df7599e871efcd650e34097527c927e51
|
7
|
+
data.tar.gz: 025cfe46f4cdc9cb9138b814d86a82f3b7590a6fba2e1261bbe420ba6d16a43392eb88306500a02a2fa5cc3047a7970a24e7c6e28fc6bf91dcc6833554d5165a
|
@@ -3,6 +3,24 @@ module Zaikio
|
|
3
3
|
module TestHelper
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
|
+
VirtualAccessToken = Struct.new(:id, :bearer_id, :bearer_type, :audience, :expired?, keyword_init: true)
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def find_active_access_token(id)
|
10
|
+
return unless id.to_s.starts_with?("AT:")
|
11
|
+
|
12
|
+
_, audience, person_id = id.split(":")
|
13
|
+
|
14
|
+
VirtualAccessToken.new(
|
15
|
+
id: id,
|
16
|
+
bearer_id: person_id,
|
17
|
+
audience: audience,
|
18
|
+
bearer_type: "Person",
|
19
|
+
expired?: false
|
20
|
+
)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
6
24
|
class TestSessionController < ActionController::Base # rubocop:disable Rails/ApplicationController
|
7
25
|
def show
|
8
26
|
if session[params[:key]].nil?
|
@@ -43,7 +61,15 @@ module Zaikio
|
|
43
61
|
get "/zaikio/oauth_client/test_helper/session", params: { id: value, key: key }
|
44
62
|
end
|
45
63
|
|
46
|
-
def logged_in_as(person)
|
64
|
+
def logged_in_as(person, access_token: nil, client_name: nil)
|
65
|
+
client_name ||= Zaikio::OAuthClient.client_name ||
|
66
|
+
Zaikio::OAuthClient.configuration.all_client_names.first
|
67
|
+
set_session(
|
68
|
+
:zaikio_access_token_id,
|
69
|
+
access_token&.id || "AT:#{client_name}:#{person.id}"
|
70
|
+
)
|
71
|
+
|
72
|
+
# Deprecated please use zaikio_access_token_id
|
47
73
|
set_session(:zaikio_person_id, person.id)
|
48
74
|
end
|
49
75
|
end
|
data/lib/zaikio/oauth_client.rb
CHANGED
@@ -80,10 +80,17 @@ module Zaikio
|
|
80
80
|
|
81
81
|
# This method can be used to find an active access token by id.
|
82
82
|
# It might refresh the access token to get an active one.
|
83
|
-
def find_active_access_token(id)
|
83
|
+
def find_active_access_token(id, valid_for: 30.seconds)
|
84
84
|
return unless id
|
85
85
|
|
86
|
-
|
86
|
+
if Rails.env.test?
|
87
|
+
access_token = TestHelper.find_active_access_token(id)
|
88
|
+
return access_token if access_token
|
89
|
+
end
|
90
|
+
|
91
|
+
access_token = Zaikio::AccessToken.valid(valid_for.from_now).or(
|
92
|
+
Zaikio::AccessToken.valid_refresh(valid_for.from_now)
|
93
|
+
).find_by(id: id)
|
87
94
|
access_token = access_token.refresh! if access_token&.expired?
|
88
95
|
|
89
96
|
access_token
|