zaikio-oauth_client 0.19.0 → 0.19.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zaikio/oauth_client/test_helper.rb +26 -1
- data/lib/zaikio/oauth_client/version.rb +1 -1
- data/lib/zaikio/oauth_client.rb +5 -0
- 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: fd5390d254c886ad8c082def82463c6653bdb91b4f08433bf138b872e9fb54ff
|
4
|
+
data.tar.gz: b9bca34becf29861bd4e5f57d88492a9dfb7aecb8ad6ed2306c2007ee75740e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61f6e1657014daa3b0cc5efb2e5a0ac97c0d81708d68ad7a98b030e24ce5fd2e3918c2613371dc7f9ed64f5546dad84e8f189e996fe1db113a5a295137cba74c
|
7
|
+
data.tar.gz: 38e9e845d6bae276a28ef32d6fab275ae0539598c1f7c85680ba87554e3ac0f5619261cb9346435b787c06526d0a87ca2ddfbb502a299027d1b81ea75bc424af
|
@@ -3,6 +3,23 @@ module Zaikio
|
|
3
3
|
module TestHelper
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
|
+
VirtualAccessToken = Struct.new(: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
|
+
bearer_id: person_id,
|
16
|
+
audience: audience,
|
17
|
+
bearer_type: "Person",
|
18
|
+
expired?: false
|
19
|
+
)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
6
23
|
class TestSessionController < ActionController::Base # rubocop:disable Rails/ApplicationController
|
7
24
|
def show
|
8
25
|
if session[params[:key]].nil?
|
@@ -43,7 +60,15 @@ module Zaikio
|
|
43
60
|
get "/zaikio/oauth_client/test_helper/session", params: { id: value, key: key }
|
44
61
|
end
|
45
62
|
|
46
|
-
def logged_in_as(person)
|
63
|
+
def logged_in_as(person, access_token: nil, client_name: nil)
|
64
|
+
client_name ||= Zaikio::OAuthClient.client_name ||
|
65
|
+
Zaikio::OAuthClient.configuration.all_client_names.first
|
66
|
+
set_session(
|
67
|
+
:zaikio_access_token_id,
|
68
|
+
access_token&.id || "AT:#{client_name}:#{person.id}"
|
69
|
+
)
|
70
|
+
|
71
|
+
# Deprecated please use zaikio_access_token_id
|
47
72
|
set_session(:zaikio_person_id, person.id)
|
48
73
|
end
|
49
74
|
end
|
data/lib/zaikio/oauth_client.rb
CHANGED
@@ -83,6 +83,11 @@ module Zaikio
|
|
83
83
|
def find_active_access_token(id)
|
84
84
|
return unless id
|
85
85
|
|
86
|
+
if Rails.env.test?
|
87
|
+
access_token = TestHelper.find_active_access_token(id)
|
88
|
+
return access_token if access_token
|
89
|
+
end
|
90
|
+
|
86
91
|
access_token = Zaikio::AccessToken.find_by(id: id)
|
87
92
|
access_token = access_token.refresh! if access_token&.expired?
|
88
93
|
|