Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit 96e12f8

Browse files
authored
Merge pull request #821 from derrabauke/fix-oidc-auth-stuff
fix: delete unneeded oidc adapter overrides and simplify other auth procedures
2 parents f898e99 + 801e1ae commit 96e12f8

File tree

5 files changed

+24
-35
lines changed

5 files changed

+24
-35
lines changed

app/adapters/application.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* @submodule timed-adapters
44
* @public
55
*/
6-
import { inject as service } from "@ember/service";
76
import OIDCJSONAPIAdapter from "ember-simple-auth-oidc/adapters/oidc-json-api-adapter";
87

98
/**
@@ -15,24 +14,5 @@ import OIDCJSONAPIAdapter from "ember-simple-auth-oidc/adapters/oidc-json-api-ad
1514
* @public
1615
*/
1716
export default class ApplicationAdapter extends OIDCJSONAPIAdapter {
18-
@service session;
19-
@service router;
20-
2117
namespace = "api/v1";
22-
23-
get headers() {
24-
return { ...this.session.headers };
25-
}
26-
27-
handleResponse(status, ...args) {
28-
if (status === 401) {
29-
if (this.session.isAuthenticated) {
30-
this.session.invalidate();
31-
} else {
32-
this.router.transitionTo("login");
33-
}
34-
}
35-
36-
return super.handleResponse(status, ...args);
37-
}
3818
}

app/analysis/index/controller.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { cleanParams, toQueryString } from "timed/utils/url";
2020
import config from "../../config/environment";
2121

2222
const rAF = () => {
23+
/* istanbul ignore next */
2324
return new Promise((resolve) => {
2425
window.requestAnimationFrame(resolve);
2526
});

app/services/fetch.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,10 @@ export default class FetchService extends Service {
8989
}
9090

9191
get headers() {
92-
const headers = {
92+
return {
9393
accept: CONTENT_TYPE,
9494
"content-type": CONTENT_TYPE,
95+
...this.session.headers,
9596
};
96-
97-
if (this.token) {
98-
headers.authorization = `Bearer ${this.token}`;
99-
}
100-
101-
return headers;
102-
}
103-
104-
get token() {
105-
return this.session.data.authenticated?.access_token;
10697
}
10798
}

tests/helpers/session-mock.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import Service from "@ember/service";
2+
3+
class SessionMock extends Service {
4+
isAuthenticated = true;
5+
headers = {
6+
authorization: "Bearer TEST1234",
7+
};
8+
}
9+
10+
export default function setupSession(hooks) {
11+
hooks.beforeEach(async function () {
12+
this.owner.register("service:session", SessionMock);
13+
});
14+
}

tests/unit/services/fetch-test.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { setupTest } from "ember-qunit";
22
import { module, test } from "qunit";
3+
import setupSession from "timed/tests/helpers/session-mock";
34

45
module("Unit | Service | fetch", function (hooks) {
56
setupTest(hooks);
7+
setupSession(hooks);
68

79
test("exists", function (assert) {
810
const service = this.owner.lookup("service:fetch");
@@ -13,16 +15,17 @@ module("Unit | Service | fetch", function (hooks) {
1315
const service = this.owner.lookup("service:fetch");
1416
const session = this.owner.lookup("service:session");
1517

16-
session.data.authenticated = { access_token: "test" };
17-
18-
assert.equal(service.get("headers.authorization"), "Bearer test");
18+
assert.equal(
19+
service.get("headers.authorization"),
20+
session.headers.authorization
21+
);
1922
});
2023

2124
test("does not add the auth token to the headers if no token is given", function (assert) {
2225
const service = this.owner.lookup("service:fetch");
2326
const session = this.owner.lookup("service:session");
2427

25-
session.data.authenticated = { access_token: null };
28+
delete session.headers.authorization;
2629

2730
assert.notOk(service.get("headers.authorization"));
2831
});

0 commit comments

Comments
 (0)