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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d82ba1e01192f3e9fac8f47bc5ded67fb2b869f724fcdcd26ec42718c4ca53f5
4
- data.tar.gz: 48a24101ed54396c68d96077c0eaf7dc16fbd317ecbae092773ae9f29a31b9bd
3
+ metadata.gz: fd5390d254c886ad8c082def82463c6653bdb91b4f08433bf138b872e9fb54ff
4
+ data.tar.gz: b9bca34becf29861bd4e5f57d88492a9dfb7aecb8ad6ed2306c2007ee75740e5
5
5
  SHA512:
6
- metadata.gz: 46884a09302f56b53e64e8ee2cd1172c5792a1ecf82ff6e0a8b054d979f86f3b63449a4bd79633c3f95f076e11e0f3bc5669b26d8988643232c784c92f447d5b
7
- data.tar.gz: f1e5992edef1cda3bd6b68f2089c07201264d2b1e64a4713ae0d6ec84af5e708172b9b53ceb76d38245645ec41ebf79f4da7d63a40e17a6441e4d7171f9e47e8
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
@@ -1,5 +1,5 @@
1
1
  module Zaikio
2
2
  module OAuthClient
3
- VERSION = "0.19.0".freeze
3
+ VERSION = "0.19.1".freeze
4
4
  end
5
5
  end
@@ -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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zaikio-oauth_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.0
4
+ version: 0.19.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zaikio GmbH