zaikio-oauth_client 0.19.0 → 0.19.3

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: 58d2e1d10678b7eddb4afc7931c94e04299b63027c3b02c5773e03bf74b29b7d
4
+ data.tar.gz: 44459fbc11ec98ccdd1f88819416f50b704a1d9f1a32a7a24d17a92b863563e9
5
5
  SHA512:
6
- metadata.gz: 46884a09302f56b53e64e8ee2cd1172c5792a1ecf82ff6e0a8b054d979f86f3b63449a4bd79633c3f95f076e11e0f3bc5669b26d8988643232c784c92f447d5b
7
- data.tar.gz: f1e5992edef1cda3bd6b68f2089c07201264d2b1e64a4713ae0d6ec84af5e708172b9b53ceb76d38245645ec41ebf79f4da7d63a40e17a6441e4d7171f9e47e8
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
@@ -1,5 +1,5 @@
1
1
  module Zaikio
2
2
  module OAuthClient
3
- VERSION = "0.19.0".freeze
3
+ VERSION = "0.19.3".freeze
4
4
  end
5
5
  end
@@ -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
- access_token = Zaikio::AccessToken.find_by(id: id)
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
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.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zaikio GmbH