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

WIP: PoC demo app auth works with oidc-client-ts #2206

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default class AuthorizationCodeWithPkceOidcHandler
const storage = this.storageUtility;

try {
const signingRequest = await oidcClientLibrary.createSigninRequest();
const signingRequest = await oidcClientLibrary.createSigninRequest({});
await Promise.all([
// We use the OAuth 'state' value (which should be crypto-random) as
// the key in our storage to store our actual SessionID. We do this
Expand All @@ -96,8 +96,7 @@ export default class AuthorizationCodeWithPkceOidcHandler
// that session ID can be any developer-specified value, and therefore
// may not be appropriate (since the OAuth 'state' value should really
// be an unguessable crypto-random value).
// eslint-disable-next-line no-underscore-dangle
storage.setForUser(signingRequest.state._id, {
storage.setForUser(signingRequest.state.id, {
sessionId: oidcLoginOptions.sessionId,
}),

Expand All @@ -106,8 +105,7 @@ export default class AuthorizationCodeWithPkceOidcHandler
// our session ID is unnecessary, but it provides a slightly cleaner
// separation of concerns.
storage.setForUser(oidcLoginOptions.sessionId, {
// eslint-disable-next-line no-underscore-dangle
codeVerifier: signingRequest.state._code_verifier,
codeVerifier: signingRequest.state.code_verifier ?? "",
issuer: oidcLoginOptions.issuer.toString(),
// The redirect URL is read after redirect, so it must be stored now.
redirectUrl: oidcLoginOptions.redirectUrl,
Expand Down
172 changes: 41 additions & 131 deletions packages/oidc/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/oidc/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@inrupt/oidc-client-ext",
"version": "1.12.1",
"description": "A module extending oidc-client-js with new features, such as dynamic client registration and DPoP support.",
"description": "A module extending oidc-client-ts with new features, such as dynamic client registration and DPoP support.",
"homepage": "https://github.com/inrupt/solid-client-authn-js/tree/main/packages/oidc/",
"bugs": "https://github.com/inrupt/solid-client-authn-js/issues",
"main": "dist/index.js",
Expand Down Expand Up @@ -29,11 +29,11 @@
"cross-fetch": "^3.1.5"
},
"dependencies": {
"@inrupt/oidc-client": "^1.11.6",
"@inrupt/solid-client-authn-core": "^1.12.1",
"@types/jest": "^27.0.3",
"@types/uuid": "^8.3.0",
"jose": "^4.3.7",
"oidc-client-ts": "^2.0.5",
"uuid": "^8.3.1"
},
"publishConfig": {
Expand Down
7 changes: 5 additions & 2 deletions packages/oidc/src/cleanup/cleanup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/

import { jest, it, describe, expect } from "@jest/globals";
import { OidcClient } from "@inrupt/oidc-client";
import { OidcClient, OidcClientSettings } from "oidc-client-ts";
import { removeOidcQueryParam, clearOidcPersistentStorage } from "./cleanup";

jest.mock("@inrupt/oidc-client", () => {
Expand Down Expand Up @@ -71,7 +71,10 @@ describe("clearOidcPersistentStorage", () => {
it("clears oidc-client storage", async () => {
// This is a bad test, but we can only test for internal behaviour of oidc-client,
// or test that the 'clearStaleState' function is called, which is done here.
const clearSpy = jest.spyOn(new OidcClient({}), "clearStaleState");
const clearSpy = jest.spyOn(
new OidcClient({} as OidcClientSettings),
"clearStaleState"
);
await clearOidcPersistentStorage();
expect(clearSpy).toHaveBeenCalled();
});
Expand Down
7 changes: 5 additions & 2 deletions packages/oidc/src/cleanup/cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import { OidcClient, WebStorageStateStore } from "@inrupt/oidc-client";
import { OidcClient } from "oidc-client-ts";

/**
* Removes OIDC-specific query parameters from a given URL (state, code...), and
Expand Down Expand Up @@ -52,8 +52,11 @@ export async function clearOidcPersistentStorage(): Promise<void> {
// for a hash '#' fragment!).
// eslint-disable-next-line camelcase
response_mode: "query",
redirect_uri: "",
authority: "",
client_id: "",
});
await client.clearStaleState(new WebStorageStateStore({}));
await client.clearStaleState();
const myStorage = window.localStorage;
const itemsToRemove = [];
for (let i = 0; i <= myStorage.length; i += 1) {
Expand Down
Loading