Skip to content

Commit

Permalink
chore(lint): fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
anehx authored and derrabauke committed Oct 25, 2023
1 parent 3ae5676 commit 973ceb5
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 86 deletions.
22 changes: 12 additions & 10 deletions addon/authenticators/oidc.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ export default class OidcAuthenticator extends BaseAuthenticator {
async authenticate({ code, redirectUri, codeVerifier, isRefresh }) {
if (!this.config.tokenEndpoint || !this.config.userinfoEndpoint) {
throw new Error(
"Please define all OIDC endpoints (auth, token, userinfo)"
"Please define all OIDC endpoints (auth, token, userinfo)",
);
}

if (isRefresh) {
return await this._refresh(
this.session.data.authenticated.refresh_token,
redirectUri
redirectUri,
);
}

Expand Down Expand Up @@ -66,7 +66,7 @@ export default class OidcAuthenticator extends BaseAuthenticator {
"Content-Type": "application/x-www-form-urlencoded",
},
body,
}
},
);

const isServerError = isServerErrorResponse(response);
Expand Down Expand Up @@ -110,7 +110,9 @@ export default class OidcAuthenticator extends BaseAuthenticator {

if (this.config.afterLogoutUri) {
params.push(
`post_logout_redirect_uri=${getAbsoluteUrl(this.config.afterLogoutUri)}`
`post_logout_redirect_uri=${getAbsoluteUrl(
this.config.afterLogoutUri,
)}`,
);
}

Expand All @@ -121,8 +123,8 @@ export default class OidcAuthenticator extends BaseAuthenticator {
this._redirectToUrl(
`${getAbsoluteUrl(
this.config.endSessionEndpoint,
this.config.host
)}?${params.join("&")}`
this.config.host,
)}?${params.join("&")}`,
);
}

Expand Down Expand Up @@ -183,7 +185,7 @@ export default class OidcAuthenticator extends BaseAuthenticator {
"Content-Type": "application/x-www-form-urlencoded",
},
body,
}
},
);
isServerError = isServerErrorResponse(response);
if (isServerError) throw new Error(response.message);
Expand All @@ -208,9 +210,9 @@ export default class OidcAuthenticator extends BaseAuthenticator {
this,
() =>
resolve(
this._refresh(refresh_token, redirectUri, retryCount + 1)
this._refresh(refresh_token, redirectUri, retryCount + 1),
),
this.config.retryTimeout
this.config.retryTimeout,
);
});
}
Expand All @@ -232,7 +234,7 @@ export default class OidcAuthenticator extends BaseAuthenticator {
Authorization: `${this.config.authPrefix} ${accessToken}`,
Accept: "application/json",
},
}
},
);

const userinfo = await response.json();
Expand Down
10 changes: 6 additions & 4 deletions addon/routes/oidc-authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default class OIDCAuthenticationRoute extends Route {
async afterModel(_, transition) {
if (!this.config.authEndpoint) {
throw new Error(
"Please define all OIDC endpoints (auth, token, logout, userinfo)"
"Please define all OIDC endpoints (auth, token, logout, userinfo)",
);
}

Expand All @@ -80,7 +80,7 @@ export default class OIDCAuthenticationRoute extends Route {
return await this._handleCallbackRequest(
queryParams.code,
queryParams.state,
transition
transition,
);
}

Expand Down Expand Up @@ -159,7 +159,7 @@ export default class OIDCAuthenticationRoute extends Route {

if (this.config.enablePkce) {
const pkceChallenge = generatePkceChallenge(
this.session.data.pkceCodeVerifier
this.session.data.pkceCodeVerifier,
);
search.push(`code_challenge=${pkceChallenge}`);
search.push("code_challenge_method=S256");
Expand All @@ -168,7 +168,9 @@ export default class OIDCAuthenticationRoute extends Route {
search = search.filter(Boolean).join("&");

this._redirectToUrl(
`${getAbsoluteUrl(this.config.host)}${this.config.authEndpoint}?${search}`
`${getAbsoluteUrl(this.config.host)}${
this.config.authEndpoint
}?${search}`,
);
}
}
4 changes: 2 additions & 2 deletions addon/unauthorized.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import getAbsoluteUrl from "ember-simple-auth-oidc/utils/absolute-url";

const replaceUri = (session) => {
location.replace(
getAbsoluteUrl(getConfig(getOwner(session)).afterLogoutUri || "")
getAbsoluteUrl(getConfig(getOwner(session)).afterLogoutUri || ""),
);
};

Expand All @@ -28,7 +28,7 @@ export default function handleUnauthorized(session) {
this,
replaceUri,
session,
getConfig(getOwner(session)).unauthorizedRequestRedirectTimeout
getConfig(getOwner(session)).unauthorizedRequestRedirectTimeout,
);
}
}
2 changes: 1 addition & 1 deletion addon/utils/pkce.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function generateCodeVerifier(len = 43) {
const chars = new Array(len);
for (let i = 0; i < len; i++) {
chars[i] = RANDOM_DATA_ALPHABET.charCodeAt(
randomData[i] % RANDOM_DATA_ALPHABET.length
randomData[i] % RANDOM_DATA_ALPHABET.length,
);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/dummy/mirage/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default function makeServer(config) {
{},
{
data: { items: [{ id: 1, name: "Test" }] },
}
},
);
});
},
Expand Down
8 changes: 1 addition & 7 deletions tests/unit/adapters/oidc-json-api-adapter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ module("Unit | Adapter | oidc json api adapter", function (hooks) {
setupMirage(hooks);

test("it sets the correct headers", async function (assert) {
assert.expect(1);

const adapter = this.owner.lookup("adapter:oidc-json-api-adapter");
const session = this.owner.lookup("service:session");
set(session, "session.isAuthenticated", true);
Expand All @@ -19,8 +17,6 @@ module("Unit | Adapter | oidc json api adapter", function (hooks) {
});

test("it refreshes the access token before ember-data requests", async function (assert) {
assert.expect(21);

const adapter = this.owner.lookup("adapter:oidc-json-api-adapter");

adapter.session.refreshAuthentication.perform = () => {
Expand All @@ -46,8 +42,6 @@ module("Unit | Adapter | oidc json api adapter", function (hooks) {
});

test("it invalidates the session correctly on a 401 response", function (assert) {
assert.expect(3);

const adapter = this.owner.lookup("adapter:oidc-json-api-adapter");
const session = adapter.session;
session.session.content = {};
Expand All @@ -60,7 +54,7 @@ module("Unit | Adapter | oidc json api adapter", function (hooks) {

assert.strictEqual(
adapter.session.data.nextURL,
location.href.replace(location.origin, "")
location.href.replace(location.origin, ""),
);

assert.verifySteps(["invalidate"]);
Expand Down
8 changes: 1 addition & 7 deletions tests/unit/adapters/oidc-rest-adapter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ module("Unit | Adapter | oidc rest adapter", function (hooks) {
setupMirage(hooks);

test("it sets the correct headers", async function (assert) {
assert.expect(1);

const adapter = this.owner.lookup("adapter:oidc-rest-adapter");
const session = this.owner.lookup("service:session");
set(session, "session.isAuthenticated", true);
Expand All @@ -19,8 +17,6 @@ module("Unit | Adapter | oidc rest adapter", function (hooks) {
});

test("it refreshes the access token before ember-data requests", async function (assert) {
assert.expect(21);

const adapter = this.owner.lookup("adapter:oidc-rest-adapter");

adapter.session.refreshAuthentication.perform = () => {
Expand All @@ -46,8 +42,6 @@ module("Unit | Adapter | oidc rest adapter", function (hooks) {
});

test("it invalidates the session correctly on a 401 response", function (assert) {
assert.expect(3);

const adapter = this.owner.lookup("adapter:oidc-rest-adapter");
const session = adapter.session;
session.session.content = {};
Expand All @@ -60,7 +54,7 @@ module("Unit | Adapter | oidc rest adapter", function (hooks) {

assert.strictEqual(
adapter.session.data.nextURL,
location.href.replace(location.origin, "")
location.href.replace(location.origin, ""),
);

assert.verifySteps(["invalidate"]);
Expand Down
14 changes: 2 additions & 12 deletions tests/unit/authenticators/oidc-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const getTokenBody = (expired) => {
return btoa(
JSON.stringify({
exp: Date.now() + time,
})
}),
);
};

Expand All @@ -19,8 +19,6 @@ module("Unit | Authenticator | OIDC", function (hooks) {
setupMirage(hooks);

test("it can authenticate", async function (assert) {
assert.expect(4);

const subject = this.owner.lookup("authenticator:oidc");

set(subject, "redirectUri", "test");
Expand All @@ -34,8 +32,6 @@ module("Unit | Authenticator | OIDC", function (hooks) {
});

test("it can restore a session", async function (assert) {
assert.expect(4);

const subject = this.owner.lookup("authenticator:oidc");

const data = await subject.restore({
Expand All @@ -51,16 +47,12 @@ module("Unit | Authenticator | OIDC", function (hooks) {
});

test("it can invalidate a session", async function (assert) {
assert.expect(1);

const subject = this.owner.lookup("authenticator:oidc");

assert.ok(await subject.invalidate());
});

test("it can refresh a session", async function (assert) {
assert.expect(4);

const subject = this.owner.lookup("authenticator:oidc");

const data = await subject._refresh("x.y.z");
Expand All @@ -72,15 +64,13 @@ module("Unit | Authenticator | OIDC", function (hooks) {
});

test("it can make a single logout", async function (assert) {
assert.expect(3);

const { endSessionEndpoint, afterLogoutUri } = getConfig(this.owner);
const subject = this.owner.lookup("authenticator:oidc");

subject._redirectToUrl = (url) => {
assert.ok(new RegExp(endSessionEndpoint).test(url));
assert.ok(
new RegExp(`post_logout_redirect_uri=${afterLogoutUri}`).test(url)
new RegExp(`post_logout_redirect_uri=${afterLogoutUri}`).test(url),
);
assert.ok(new RegExp("id_token_hint=myIdToken").test(url));
};
Expand Down
Loading

0 comments on commit 973ceb5

Please sign in to comment.