prx_auth-rails 1.2.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/README.md +25 -6
- data/Rakefile +12 -4
- data/app/assets/config/prx_auth-rails_manifest.js +3 -0
- data/app/assets/images/prx_auth-rails/user.svg +5 -0
- data/app/assets/javascripts/prx_auth-rails/user_widget.js.erb +44 -0
- data/app/assets/stylesheets/prx_auth-rails/user_widget.css +69 -0
- data/app/controllers/prx_auth/rails/sessions_controller.rb +121 -0
- data/app/views/prx_auth/rails/sessions/auth_error.html.erb +15 -0
- data/app/views/prx_auth/rails/sessions/show.html.erb +38 -0
- data/config/initializers/assets.rb +1 -0
- data/config/routes.rb +7 -0
- data/lib/prx_auth/rails.rb +1 -0
- data/lib/prx_auth/rails/configuration.rb +15 -4
- data/lib/prx_auth/rails/engine.rb +9 -0
- data/lib/prx_auth/rails/ext/controller.rb +81 -4
- data/lib/prx_auth/rails/token.rb +5 -1
- data/lib/prx_auth/rails/version.rb +1 -1
- data/prx_auth-rails.gemspec +3 -1
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/config/manifest.js +2 -0
- data/test/dummy/app/assets/images/.keep +0 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/channels/application_cable/channel.rb +4 -0
- data/test/dummy/app/channels/application_cable/connection.rb +4 -0
- data/test/dummy/app/controllers/application_controller.rb +8 -0
- data/test/dummy/app/controllers/concerns/.keep +0 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/javascript/packs/application.js +15 -0
- data/test/dummy/app/jobs/application_job.rb +7 -0
- data/test/dummy/app/mailers/application_mailer.rb +4 -0
- data/test/dummy/app/models/application_record.rb +3 -0
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +15 -0
- data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/test/dummy/bin/rails +5 -0
- data/test/dummy/bin/rake +5 -0
- data/test/dummy/bin/setup +33 -0
- data/test/dummy/bin/spring +10 -0
- data/test/dummy/config.ru +6 -0
- data/test/dummy/config/application.rb +22 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/cable.yml +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +76 -0
- data/test/dummy/config/environments/production.rb +120 -0
- data/test/dummy/config/environments/test.rb +60 -0
- data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
- data/test/dummy/config/initializers/assets.rb +12 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +8 -0
- data/test/dummy/config/initializers/content_security_policy.rb +28 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +6 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/permissions_policy.rb +11 -0
- data/test/dummy/config/initializers/prx_auth.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +33 -0
- data/test/dummy/config/puma.rb +43 -0
- data/test/dummy/config/routes.rb +3 -0
- data/test/dummy/config/spring.rb +6 -0
- data/test/dummy/config/storage.yml +34 -0
- data/test/dummy/lib/assets/.keep +0 -0
- data/test/dummy/log/.keep +0 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/test/dummy/public/apple-touch-icon.png +0 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/storage/.keep +0 -0
- data/test/prx_auth/rails/configuration_test.rb +18 -12
- data/test/prx_auth/rails/sessions_controller_test.rb +104 -0
- data/test/prx_auth/rails/token_test.rb +1 -1
- data/test/test_helper.rb +20 -9
- metadata +158 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf8c434fb9b4854b2dd16dd7a49a9cfbf3adcc371269e93b8fe0b1c82f7d8e44
|
4
|
+
data.tar.gz: 2402bb437ecfb9873dee6fc5763a7fb63005549f78e8fa6d36315a08aacc50e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7aac974b86051fb56c34cfc95526cff184f8301c7f109e3f2965be8b0db6bdbae79c2099ef768317354381333bb88c60de1608c1feeab0d8d075f54937590684
|
7
|
+
data.tar.gz: f9042ad439ac44c6d7e3d9d3813cbf7940ad421a9ef536e2e80e9bed1f4bbaf8f28cc6371f14b237a2bd303c2d53dbdc745acaae21de7498cf4b9c209a8f9948
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# PrxAuth::Rails
|
2
2
|
|
3
|
-
Rails integration for next generation PRX Authorization system.
|
3
|
+
Rails integration for next generation PRX Authorization system. This
|
4
|
+
provides common OpenId authorization patterns used in PRX apps.
|
4
5
|
|
5
6
|
## Installation
|
6
7
|
|
@@ -14,17 +15,32 @@ And then execute:
|
|
14
15
|
|
15
16
|
## Usage
|
16
17
|
|
17
|
-
Installing the gem in a Rails project will automatically add the
|
18
|
+
Installing the gem in a Rails project will automatically add the
|
19
|
+
appropriate Rack middleware to your Rails application and add two
|
20
|
+
methods to your controllers. These methods are:
|
18
21
|
|
19
|
-
* `prx_auth_token`: returns a token (similar to PrxAuth::Token) which
|
22
|
+
* `prx_auth_token`: returns a token (similar to PrxAuth::Token) which
|
23
|
+
automatically namespaces queries. The main methods you will be
|
24
|
+
interested in are `authorized?`, `globally_authorized?` and `resources`.
|
25
|
+
More information can be found in PrxAuth.
|
20
26
|
|
21
|
-
* `prx_authenticated?`: returns whether or not this request includes a
|
27
|
+
* `prx_authenticated?`: returns whether or not this request includes a
|
28
|
+
valid PrxAuth token.
|
29
|
+
|
30
|
+
This will let set up the Rails app to be ready for HTTP requests
|
31
|
+
associated with an OpenId access token.
|
22
32
|
|
23
33
|
### Configuration
|
24
34
|
|
25
|
-
Generally, configuration is not required and the gem aims for great
|
35
|
+
Generally, configuration is not required and the gem aims for great
|
36
|
+
defaults, but you can override some settings if you need to change the
|
37
|
+
default behavior.
|
38
|
+
|
39
|
+
If you're using the Rails server-side session flow, you must supply the
|
40
|
+
client_id via configuration.
|
26
41
|
|
27
|
-
In your rails app, add a file to config/initializers called
|
42
|
+
In your rails app, add a file to config/initializers called
|
43
|
+
`prx_auth.rb`:
|
28
44
|
|
29
45
|
```ruby
|
30
46
|
PrxAuth::Rails.configure do |config|
|
@@ -36,6 +52,9 @@ PrxAuth::Rails.configure do |config|
|
|
36
52
|
# as .authorized?(:my_great_ns, :foo). Has no impact on unscoped queries.
|
37
53
|
config.namespace = :my_great_ns # default: derived from Rails::Application name.
|
38
54
|
# e.g. class Feeder < Rails::Application => :feeder
|
55
|
+
|
56
|
+
# Set up the PRX OpenID client_id if using the backend rails sessions flow.
|
57
|
+
config.client_id = '<some client id>'
|
39
58
|
end
|
40
59
|
```
|
41
60
|
|
data/Rakefile
CHANGED
@@ -1,10 +1,18 @@
|
|
1
|
-
require
|
1
|
+
require "bundler/setup"
|
2
|
+
|
3
|
+
APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
|
4
|
+
load "rails/tasks/engine.rake"
|
5
|
+
|
6
|
+
load "rails/tasks/statistics.rake"
|
7
|
+
|
8
|
+
require "bundler/gem_tasks"
|
2
9
|
require 'rake'
|
3
|
-
require
|
10
|
+
require "rake/testtask"
|
4
11
|
|
5
|
-
Rake::TestTask.new do |t|
|
12
|
+
Rake::TestTask.new(:test) do |t|
|
6
13
|
t.libs << 'test'
|
7
|
-
t.pattern = 'test/**/*
|
14
|
+
t.pattern = 'test/**/*_test.rb'
|
15
|
+
t.verbose = false
|
8
16
|
end
|
9
17
|
|
10
18
|
task default: :test
|
@@ -0,0 +1,5 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
2
|
+
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
3
|
+
<svg width="100%" height="100%" viewBox="0 0 51 51" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:1.41421;">
|
4
|
+
<path d="M51,25.5C51,11.44 39.56,0 25.5,0C11.44,0 0,11.44 0,25.5C0,32.927 3.194,39.621 8.277,44.285L8.253,44.306L9.08,45.003C9.134,45.049 9.192,45.086 9.246,45.13C9.685,45.495 10.141,45.841 10.604,46.175C10.755,46.284 10.905,46.392 11.058,46.498C11.553,46.839 12.061,47.163 12.58,47.47C12.693,47.537 12.807,47.602 12.922,47.666C13.49,47.99 14.07,48.295 14.665,48.575C14.708,48.596 14.753,48.614 14.796,48.635C16.734,49.535 18.801,50.196 20.964,50.586C21.02,50.597 21.077,50.607 21.134,50.617C21.806,50.733 22.485,50.826 23.172,50.888C23.255,50.895 23.339,50.9 23.423,50.907C24.107,50.964 24.799,51 25.5,51C26.195,51 26.88,50.964 27.56,50.909C27.647,50.902 27.733,50.897 27.819,50.89C28.501,50.828 29.174,50.738 29.839,50.624C29.896,50.613 29.955,50.603 30.012,50.592C32.142,50.21 34.18,49.564 36.092,48.686C36.163,48.654 36.234,48.623 36.305,48.59C36.877,48.321 37.436,48.031 37.984,47.722C38.12,47.645 38.256,47.567 38.391,47.487C38.89,47.194 39.38,46.887 39.857,46.56C40.029,46.443 40.196,46.32 40.366,46.198C40.773,45.905 41.173,45.602 41.561,45.286C41.648,45.217 41.74,45.156 41.825,45.085L42.673,44.376L42.648,44.355C47.776,39.689 51,32.965 51,25.5ZM1.855,25.5C1.855,12.462 12.462,1.855 25.5,1.855C38.538,1.855 49.145,12.462 49.145,25.5C49.145,32.526 46.062,38.843 41.181,43.177C40.908,42.988 40.634,42.82 40.353,42.679L32.502,38.754C31.797,38.401 31.359,37.693 31.359,36.905L31.359,34.164C31.541,33.939 31.733,33.685 31.932,33.406C32.948,31.971 33.763,30.374 34.357,28.656C35.532,28.097 36.291,26.927 36.291,25.606L36.291,22.319C36.291,21.515 35.996,20.735 35.468,20.122L35.468,15.794C35.516,15.312 35.687,12.597 33.722,10.357C32.013,8.406 29.247,7.418 25.5,7.418C21.753,7.418 18.987,8.406 17.278,10.356C15.313,12.596 15.484,15.313 15.532,15.793L15.532,20.121C15.005,20.734 14.709,21.514 14.709,22.318L14.709,25.605C14.709,26.626 15.167,27.578 15.952,28.221C16.703,31.163 18.249,33.39 18.82,34.145L18.82,36.828C18.82,37.585 18.407,38.281 17.742,38.644L10.41,42.643C10.177,42.77 9.945,42.919 9.713,43.085C4.892,38.753 1.855,32.475 1.855,25.5Z" style="fill:white;fill-rule:nonzero;"/>
|
5
|
+
</svg>
|
@@ -0,0 +1,44 @@
|
|
1
|
+
// https://stackoverflow.com/questions/8578617/inject-a-script-tag-with-remote-src-and-wait-for-it-to-execute
|
2
|
+
function prxInjectScript(src, callback) {
|
3
|
+
const script = document.createElement('script');
|
4
|
+
|
5
|
+
script.type = 'text/javascript';
|
6
|
+
script.async = false;
|
7
|
+
script.src = src;
|
8
|
+
|
9
|
+
script.onload = function () { script.onload = null; callback(); }
|
10
|
+
|
11
|
+
document.getElementsByTagName('head')[0].appendChild(script);
|
12
|
+
}
|
13
|
+
|
14
|
+
document.addEventListener('DOMContentLoaded', function () {
|
15
|
+
const idHost = 'https://<%= PrxAuth::Rails.configuration.id_host %>';
|
16
|
+
const scriptUrl = idHost + '/widget.js';
|
17
|
+
|
18
|
+
prxInjectScript(scriptUrl, function () {
|
19
|
+
const signIn = new PRXSignIn(idHost);
|
20
|
+
|
21
|
+
signIn.signedIn(function (prx) {
|
22
|
+
const widget = document.getElementById('prx-user-widget');
|
23
|
+
const account = document.getElementById('prx-user-widget-menu-account');
|
24
|
+
|
25
|
+
if (!prx.userinfo) {
|
26
|
+
// Not logged in
|
27
|
+
widget.classList.add('no-user-info');
|
28
|
+
|
29
|
+
const url = idHost + '/session?return_to=' + encodeURIComponent(window.location);
|
30
|
+
|
31
|
+
account.innerHTML = '<a class=sign-in href="' + url + '">Sign in</a>';
|
32
|
+
} else {
|
33
|
+
// Logged in
|
34
|
+
widget.classList.add('user-info');
|
35
|
+
|
36
|
+
const account = document.getElementById('prx-user-widget-menu-account');
|
37
|
+
account.innerText = prx.userinfo.email;
|
38
|
+
|
39
|
+
signIn.listApps('prx-user-widget-menu-apps');
|
40
|
+
}
|
41
|
+
});
|
42
|
+
});
|
43
|
+
});
|
44
|
+
|
@@ -0,0 +1,69 @@
|
|
1
|
+
#prx-user-widget {
|
2
|
+
display: flex;
|
3
|
+
flex-direction: column;
|
4
|
+
height: 100%;
|
5
|
+
justify-content: center;
|
6
|
+
padding: 0 20px;
|
7
|
+
position: absolute;
|
8
|
+
right: 0;
|
9
|
+
transition-property: opacity;
|
10
|
+
transition-duration: 0.2s;
|
11
|
+
}
|
12
|
+
@media (max-width: ) {
|
13
|
+
#prx-user-widget {
|
14
|
+
height: auto;
|
15
|
+
top: 0;
|
16
|
+
}
|
17
|
+
}
|
18
|
+
#prx-user-widget:hover {
|
19
|
+
}
|
20
|
+
#prx-user-widget:hover .user-icon {
|
21
|
+
opacity: 1;
|
22
|
+
}
|
23
|
+
#prx-user-widget:hover #prx-user-widget-menu {
|
24
|
+
display: block;
|
25
|
+
}
|
26
|
+
#prx-user-widget .user-icon {
|
27
|
+
cursor: pointer;
|
28
|
+
height: 2em;
|
29
|
+
opacity: 0.7;
|
30
|
+
width: 2em;
|
31
|
+
}
|
32
|
+
#prx-user-widget #prx-user-widget-menu {
|
33
|
+
background-color: #1a1a1a;
|
34
|
+
display: none;
|
35
|
+
right: 0;
|
36
|
+
padding: 10px 20px;
|
37
|
+
position: absolute;
|
38
|
+
top: 100%;
|
39
|
+
z-index: 999;
|
40
|
+
display: none;
|
41
|
+
}
|
42
|
+
|
43
|
+
#prx-user-widget #prx-user-widget-menu h1 {
|
44
|
+
color: white;
|
45
|
+
font-size: .9em;
|
46
|
+
font-weight: 700;
|
47
|
+
}
|
48
|
+
|
49
|
+
#prx-user-widget #prx-user-widget-menu-apps {
|
50
|
+
padding: 0;
|
51
|
+
}
|
52
|
+
#prx-user-widget #prx-user-widget-menu-apps ul {
|
53
|
+
border-top: 1px solid #ddd;
|
54
|
+
padding: 15px 0 0;
|
55
|
+
}
|
56
|
+
|
57
|
+
#prx-user-widget #prx-user-widget-menu-apps ul li a {
|
58
|
+
display: block;
|
59
|
+
font-weight: normal;
|
60
|
+
opacity: 0.7;
|
61
|
+
padding: 5px 0;
|
62
|
+
text-transform: none;
|
63
|
+
}
|
64
|
+
#prx-user-widget #prx-user-widget-menu-apps ul li a:hover {
|
65
|
+
opacity: 1;
|
66
|
+
}
|
67
|
+
.prx-home #prx-user-widget.loaded:hover {
|
68
|
+
background: transparent;
|
69
|
+
}
|
@@ -0,0 +1,121 @@
|
|
1
|
+
module PrxAuth::Rails
|
2
|
+
class SessionsController < ApplicationController
|
3
|
+
include PrxAuth::Rails::Engine.routes.url_helpers
|
4
|
+
|
5
|
+
skip_before_action :authenticate!
|
6
|
+
|
7
|
+
before_action :set_nonce!, only: :show
|
8
|
+
|
9
|
+
ID_NONCE_SESSION_KEY = 'id_prx_openid_nonce'.freeze
|
10
|
+
|
11
|
+
def new
|
12
|
+
set_nonce! unless fetch_nonce.present?
|
13
|
+
|
14
|
+
config = PrxAuth::Rails.configuration
|
15
|
+
|
16
|
+
id_auth_params = {
|
17
|
+
client_id: config.prx_client_id,
|
18
|
+
nonce: fetch_nonce,
|
19
|
+
response_type: 'id_token token',
|
20
|
+
scope: 'openid apps',
|
21
|
+
prompt: 'necessary'
|
22
|
+
}
|
23
|
+
|
24
|
+
redirect_to '//' + config.id_host + '/authorize?' + id_auth_params.to_query
|
25
|
+
end
|
26
|
+
|
27
|
+
def show
|
28
|
+
end
|
29
|
+
|
30
|
+
def destroy
|
31
|
+
sign_out_user
|
32
|
+
redirect_to after_sign_out_path
|
33
|
+
end
|
34
|
+
|
35
|
+
def auth_error
|
36
|
+
@auth_error_message = params.require(:error)
|
37
|
+
end
|
38
|
+
|
39
|
+
def create
|
40
|
+
jwt_id_claims = id_claims
|
41
|
+
jwt_access_claims = access_claims
|
42
|
+
|
43
|
+
jwt_access_claims['id_token'] = jwt_id_claims.as_json
|
44
|
+
|
45
|
+
result_path = if valid_nonce?(jwt_id_claims['nonce']) &&
|
46
|
+
users_match?(jwt_id_claims, jwt_access_claims)
|
47
|
+
sign_in_user(jwt_access_claims)
|
48
|
+
lookup_and_register_accounts_names
|
49
|
+
after_sign_in_path_for(current_user)
|
50
|
+
else
|
51
|
+
auth_error_sessions_path(error: 'verification_failed')
|
52
|
+
end
|
53
|
+
reset_nonce!
|
54
|
+
|
55
|
+
redirect_to result_path
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def after_sign_in_path_for(_)
|
61
|
+
return super if defined?(super)
|
62
|
+
|
63
|
+
"/"
|
64
|
+
end
|
65
|
+
|
66
|
+
def after_sign_out_path
|
67
|
+
return super if defined?(super)
|
68
|
+
|
69
|
+
"https://#{id_host}/session/sign_out"
|
70
|
+
end
|
71
|
+
|
72
|
+
def id_claims
|
73
|
+
id_token = params.require('id_token')
|
74
|
+
validate_token(id_token)
|
75
|
+
end
|
76
|
+
|
77
|
+
def access_claims
|
78
|
+
access_token = params.require('access_token')
|
79
|
+
validate_token(access_token)
|
80
|
+
end
|
81
|
+
|
82
|
+
def reset_nonce!
|
83
|
+
session[ID_NONCE_SESSION_KEY] = nil
|
84
|
+
end
|
85
|
+
|
86
|
+
def set_nonce!
|
87
|
+
n = session[ID_NONCE_SESSION_KEY]
|
88
|
+
return n if n.present?
|
89
|
+
|
90
|
+
session[ID_NONCE_SESSION_KEY] = SecureRandom.hex
|
91
|
+
end
|
92
|
+
|
93
|
+
def fetch_nonce
|
94
|
+
session[ID_NONCE_SESSION_KEY]
|
95
|
+
end
|
96
|
+
|
97
|
+
def valid_nonce?(nonce)
|
98
|
+
return false if fetch_nonce.nil?
|
99
|
+
|
100
|
+
fetch_nonce == nonce
|
101
|
+
end
|
102
|
+
|
103
|
+
def users_match?(claims1, claims2)
|
104
|
+
return false if claims1['sub'].nil? || claims2['sub'].nil?
|
105
|
+
|
106
|
+
claims1['sub'] == claims2['sub']
|
107
|
+
end
|
108
|
+
|
109
|
+
def validate_token(token)
|
110
|
+
prx_auth_cert = Rack::PrxAuth::Certificate.new("https://#{id_host}/api/v1/certs")
|
111
|
+
auth_validator = Rack::PrxAuth::AuthValidator.new(token, prx_auth_cert, id_host)
|
112
|
+
auth_validator.
|
113
|
+
claims.
|
114
|
+
with_indifferent_access
|
115
|
+
end
|
116
|
+
|
117
|
+
def id_host
|
118
|
+
PrxAuth::Rails.configuration.id_host
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<div class='main'>
|
2
|
+
<section>
|
3
|
+
<h3>Not authorized for this application.</h3>
|
4
|
+
|
5
|
+
<p>Message was: <pre><%= @auth_error_message %></pre>
|
6
|
+
<% if @auth_error_message == 'invalid_scope' %>
|
7
|
+
Did you add a row in the account_applications table on id.prx?
|
8
|
+
<% end %>
|
9
|
+
</p>
|
10
|
+
|
11
|
+
<p>
|
12
|
+
<a href="<%= new_sessions_path %>">Try logging in again</a>
|
13
|
+
</p>
|
14
|
+
</section>
|
15
|
+
</div>
|
@@ -0,0 +1,38 @@
|
|
1
|
+
<div style="display:none;">
|
2
|
+
<%= form_for(:sessions, :url => PrxAuth::Rails::Engine.routes.url_helpers.sessions_path) do |f| %>
|
3
|
+
<%= hidden_field_tag :access_token, '', id: 'access-token-field' %>
|
4
|
+
<%= hidden_field_tag :id_token, '', id: 'id-token-field' %>
|
5
|
+
<%= f.submit id: 'sessions-form-submit' %>
|
6
|
+
<% end %>
|
7
|
+
</div>
|
8
|
+
|
9
|
+
<script type='application/javascript'>
|
10
|
+
|
11
|
+
function parseURLFragment() {
|
12
|
+
let hashParams = {};
|
13
|
+
let e,
|
14
|
+
a = /\+/g, // Regex for replacing addition symbol with a space
|
15
|
+
r = /([^&;=]+)=?([^&;]*)/g,
|
16
|
+
d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
|
17
|
+
q = window.location.hash.substring(1);
|
18
|
+
|
19
|
+
while (e = r.exec(q))
|
20
|
+
hashParams[d(e[1])] = d(e[2]);
|
21
|
+
|
22
|
+
return hashParams;
|
23
|
+
}
|
24
|
+
|
25
|
+
window.addEventListener("load", () => {
|
26
|
+
var idToken = document.querySelector("#id-token-field");
|
27
|
+
var accessToken = document.querySelector("#access-token-field");
|
28
|
+
var submit = document.querySelector("input#sessions-form-submit[type=submit]");
|
29
|
+
|
30
|
+
var hashParams = parseURLFragment();
|
31
|
+
|
32
|
+
accessToken.value = hashParams['access_token'];
|
33
|
+
idToken.value = hashParams['id_token'];
|
34
|
+
|
35
|
+
submit.click();
|
36
|
+
});
|
37
|
+
|
38
|
+
</script>
|
@@ -0,0 +1 @@
|
|
1
|
+
Rails.application.config.assets.precompile << %w(prx_auth-rails_manifest.js)
|
data/config/routes.rb
ADDED
data/lib/prx_auth/rails.rb
CHANGED
@@ -1,17 +1,28 @@
|
|
1
1
|
class PrxAuth::Rails::Configuration
|
2
|
-
attr_accessor :install_middleware,
|
2
|
+
attr_accessor :install_middleware,
|
3
|
+
:namespace,
|
4
|
+
:prx_client_id,
|
5
|
+
:id_host
|
6
|
+
|
3
7
|
|
4
8
|
def initialize
|
5
9
|
@install_middleware = true
|
6
10
|
if defined?(::Rails)
|
7
11
|
klass = ::Rails.application.class
|
8
|
-
|
9
|
-
|
12
|
+
parent_name = if ::Rails::VERSION::MAJOR >= 6
|
13
|
+
klass.module_parent_name
|
14
|
+
else
|
15
|
+
klass.parent_name
|
16
|
+
end
|
17
|
+
klass_name = if parent_name.present?
|
18
|
+
parent_name
|
10
19
|
else
|
11
20
|
klass.name
|
12
21
|
end
|
13
22
|
|
14
23
|
@namespace = klass_name.underscore.intern
|
24
|
+
@prx_client_id = nil
|
25
|
+
@id_host = nil
|
15
26
|
end
|
16
27
|
end
|
17
|
-
end
|
28
|
+
end
|