prx_auth-rails 1.3.0 → 1.4.0
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: 16f02bc649e6a16709b4a504649a925d3ead05209f8b3bd5c5e4aa28416bc57e
|
4
|
+
data.tar.gz: fbc0d03cd674fa514541f23d9c6da6ac46db9031c110ddc3f604e66e073c9a8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d16efe0713bb453b5a4238f0ff6983898b5b5872d07396be5c66cf88ca7f4e2f23834a1abc8462c9a2cf0e8f40f1416d7e8cf82ec48611492deddcd52b8812c
|
7
|
+
data.tar.gz: d3eacf2afcc2b9af1a741988bdb8e70c7c664672c487c6515ca336e65ac5f3db42adf63fc05b6fe89b39ef2ff6c45ad1e8dccaa0e5204b3bfba50d2388e6a07f
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'open-uri'
|
2
|
-
|
3
1
|
module PrxAuth::Rails
|
4
2
|
class SessionsController < ApplicationController
|
5
3
|
include PrxAuth::Rails::Engine.routes.url_helpers
|
@@ -42,6 +40,7 @@ module PrxAuth::Rails
|
|
42
40
|
result_path = if valid_nonce?(jwt_id_claims['nonce']) &&
|
43
41
|
users_match?(jwt_id_claims, jwt_access_claims)
|
44
42
|
sign_in_user(jwt_access_claims)
|
43
|
+
lookup_and_register_accounts_names
|
45
44
|
after_sign_in_path_for(current_user)
|
46
45
|
else
|
47
46
|
auth_error_sessions_path(error: 'verification_failed')
|
@@ -1,8 +1,12 @@
|
|
1
1
|
require 'prx_auth/rails/token'
|
2
|
+
require 'open-uri'
|
2
3
|
|
3
4
|
module PrxAuth
|
4
5
|
module Rails
|
5
6
|
module Controller
|
7
|
+
|
8
|
+
PRX_ACCOUNT_NAME_MAPPING_KEY = 'prx.account.name.mapping'.freeze
|
9
|
+
|
6
10
|
def prx_auth_token
|
7
11
|
rack_auth_token = env_prx_auth_token
|
8
12
|
return rack_auth_token if rack_auth_token.present?
|
@@ -26,12 +30,53 @@ module PrxAuth
|
|
26
30
|
PrxAuth::Rails::Token.new(prx_auth_token)
|
27
31
|
end
|
28
32
|
|
33
|
+
def lookup_and_register_accounts_names
|
34
|
+
session[PRX_ACCOUNT_NAME_MAPPING_KEY] =
|
35
|
+
lookup_account_names_mapping
|
36
|
+
end
|
37
|
+
|
38
|
+
def account_name_for(id)
|
39
|
+
id = id.to_i
|
40
|
+
|
41
|
+
name =
|
42
|
+
if session[PRX_ACCOUNT_NAME_MAPPING_KEY].has_key?(id)
|
43
|
+
session[PRX_ACCOUNT_NAME_MAPPING_KEY][id]
|
44
|
+
else
|
45
|
+
session[PRX_ACCOUNT_NAME_MAPPING_KEY][id] = lookup_account_name_for(id)
|
46
|
+
end
|
47
|
+
|
48
|
+
name = "[#{id}] Unknown Account Name" unless name.present?
|
49
|
+
|
50
|
+
name
|
51
|
+
end
|
52
|
+
|
29
53
|
def sign_in_user(token)
|
30
54
|
session['prx.auth'] = token
|
31
55
|
end
|
32
56
|
|
33
57
|
private
|
34
58
|
|
59
|
+
def lookup_account_name_for(id)
|
60
|
+
id = id.to_i
|
61
|
+
|
62
|
+
res = lookup_account_names_mapping([id])
|
63
|
+
res[id]
|
64
|
+
end
|
65
|
+
|
66
|
+
def lookup_account_names_mapping(ids=current_user.resources)
|
67
|
+
id_host = PrxAuth::Rails.configuration.id_host
|
68
|
+
ids_param = ids.map(&:to_s).join(',')
|
69
|
+
|
70
|
+
options = {}
|
71
|
+
options[:ssl_verify_mode] = OpenSSL::SSL::VERIFY_NONE if ::Rails.env.development?
|
72
|
+
|
73
|
+
accounts = URI.open("https://#{id_host}/api/v1/accounts?account_ids=#{ids_param}", options).read
|
74
|
+
|
75
|
+
mapping = JSON.parse(accounts)['accounts'].map { |acct| [acct['id'], acct['display_name']] }.to_h
|
76
|
+
|
77
|
+
mapping
|
78
|
+
end
|
79
|
+
|
35
80
|
def env_prx_auth_token
|
36
81
|
if !defined? @_prx_auth_token
|
37
82
|
@_prx_auth_token = request.env['prx.auth'] && PrxAuth::Rails::Token.new(request.env['prx.auth'])
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prx_auth-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Rhoden
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|