Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace pass-auth authenticated service with user service #1260

Merged
merged 8 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .docker/ember-dev/Dockerfile

This file was deleted.

23 changes: 0 additions & 23 deletions .docker/nginx-template.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,8 @@ server {
#charset utf-8;
#access_log /var/log/nginx/host.access.log main;

# Add Content Security Policy
add_header Content-Security-Policy "$CSP_HEADERS";

location / {
root /usr/share/nginx/html;
index index.html index.htm;
add_header Content-Security-Policy "$CSP_HEADERS";
}

# This is important, any 404 will cause the ember
# app to re-load. This is because all ember URLs
# (e.g. https://pass/grants/foo), when issued as an HTTP
# request, have nothing that 'serves' them. Instead, the
# ember app, when loaded, inspects the URL and renders the
# correct page client-side. So we want the ember app to load
# and parse all these 404 URLs.
#
# Note, the equals sign means that a 200 is returned
# instead of a 404
error_page 404 = ${PASS_UI_ROOT_URL}/index.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
11 changes: 4 additions & 7 deletions app/authenticators/http-only.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ export default class HttpOnly extends Base {
*/
restore(data) {
return new RSVP.Promise((resolve, reject) => {
if (window.location.pathname === '/app/auth-callback') {
return reject('Could not restore session.');
}
if (!this._validateData(data)) {
return reject('Could not restore session.');
}
Expand All @@ -35,7 +32,7 @@ export default class HttpOnly extends Base {
* @public
*/
async authenticate() {
const url = `${window.location.origin}/authenticated`;
const url = `/user/whoami`;

let response = await fetch(url);

Expand All @@ -61,16 +58,16 @@ export default class HttpOnly extends Base {

async _validateData(data) {
// see https://tools.ietf.org/html/rfc6749#section-4.2.2
if (isEmpty(data) || isEmpty(data.user.id)) return false;
if (isEmpty(data) || isEmpty(data.id)) return false;

const url = `${window.location.origin}/authenticated`;
const url = `/user/whoami`;

let response = await fetch(url);

if (response.ok) {
const refreshedData = await response.json();

return data.user.id === refreshedData.user.id;
return data.id === refreshedData.id;
} else {
return false;
}
Expand Down
1 change: 1 addition & 0 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

{{content-for "head"}}

<link rel="icon" href="/app/favicon.png" />
<link integrity="" rel="stylesheet" href="{{rootURL}}assets/vendor.css" />
<link integrity="" rel="stylesheet" href="{{rootURL}}assets/pass-ui.css" />
<link rel="stylesheet" href="{{rootURL}}coreUI.css" />
Expand Down
2 changes: 0 additions & 2 deletions app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ Router.map(function () {
});
this.route('not-found-error', { path: '/*path' });
this.route('thanks');
this.route('auth-callback');
this.route('authenticated');
});

export default Router;
15 changes: 0 additions & 15 deletions app/routes/auth-callback.js

This file was deleted.

17 changes: 0 additions & 17 deletions app/services/app-static-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ export default class AppStaticConfigService extends Service {
const overrides = `${this._config.branding.overrides}`;
this.addCSS(overrides);
}
if (this._config.branding.favicon) {
const favicon = `${this._config.branding.favicon}`;
this.addFavicon(favicon);
}
}
}

Expand Down Expand Up @@ -85,17 +81,4 @@ export default class AppStaticConfigService extends Service {

window.document.head.appendChild(newLink);
}

addFavicon(uri) {
const fav = document.querySelector('head link[rel="icon"]');
if (fav || !uri) {
return;
}

const newFav = window.document.createElement('link');
newFav.setAttribute('rel', 'icon');
newFav.setAttribute('href', uri);

window.document.head.appendChild(newFav);
}
}
2 changes: 1 addition & 1 deletion app/services/current-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default class CurrentUserService extends Service {
*/
@task
load = function* () {
let userId = this.session.data.authenticated.user.id;
let userId = this.session.data.authenticated.id;

if (userId) {
let user = yield this.store.findRecord('user', userId);
Expand Down
11 changes: 0 additions & 11 deletions mirage/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,6 @@ export default function (config) {
};
});

/** Auth Service */
this.get('/authenticated', (schema, request) => {
const user = schema.find('user', 0);

return {
user: {
id: user.id,
},
};
});

/** User Service */
this.get('/pass-user-service/whoami', (schema, request) => {
const userId = request.queryParams.userToken;
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/app-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module('Acceptance | application', function (hooks) {
setupMirage(hooks);

hooks.beforeEach(async function () {
await authenticateSession({ user: { id: '0' } });
await authenticateSession({ id: '0' });
});

test('Make sure app loads outside of root', async function (assert) {
Expand Down
4 changes: 1 addition & 3 deletions tests/acceptance/nih-submission-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ module('Acceptance | submission', function (hooks) {
setupMirage(hooks);

hooks.beforeEach(async function () {
await authenticateSession({
user: { id: '0' },
});
await authenticateSession({ id: '0' });
});

test('can walk through an nih submission workflow and make a submission - base case', async function (assert) {
Expand Down
4 changes: 1 addition & 3 deletions tests/acceptance/proxy-submission-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ module('Acceptance | proxy submission', function (hooks) {

this.server.create('user', attrs);

await authenticateSession({
user: { id: '0' },
});
await authenticateSession({ id: '0' });
});

test('can walk through a proxy submission workflow and make a submission – with pass account', async function (assert) {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/services/current-user-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module('Unit | Service | current-user', (hooks) => {
'@id': user.get('id'),
};

service.set('session', { data: { authenticated: { user: { id: '000' } } } });
service.set('session', { data: { authenticated: { id: '000' } } });

service.set(
'store',
Expand Down
Loading