Skip to content

Commit

Permalink
options to get the dataset from the vc
Browse files Browse the repository at this point in the history
  • Loading branch information
garciafdezpatricia committed Jun 3, 2024
1 parent 8f0304d commit 05406e8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
21 changes: 14 additions & 7 deletions src/common/verify/isValidAccessGrant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import type {
import {
getIssuer,
getVerifiableCredentialApiConfiguration,
verifiableCredentialToDataset,
} from "@inrupt/solid-client-vc";
import { getBaseAccess } from "../../gConsent/util/getBaseAccessVerifiableCredential";
import { getSessionFetch } from "../util/getSessionFetch";
Expand All @@ -50,14 +51,20 @@ async function isValidAccessGrant(
} = {},
): Promise<{ checks: string[]; warnings: string[]; errors: string[] }> {
const fetcher = await getSessionFetch(options);

if (typeof vc !== "string" && !isUrl(vc.toString()) && !isDatasetCore(vc)) {
throw new Error(
"Verifiable Credential is not of valid types: string, URL, VerifiableCredential or DatasetWithId",
);
let validVC = null;
if (
typeof vc !== "string" &&
!isUrl(vc.toString()) &&
!isDatasetCore(vc) &&
!(vc instanceof URL) // avoid ts
) {
validVC = await verifiableCredentialToDataset(vc, {
includeVcProperties: true,
requireId: false,
});
}

const vcObject = await getBaseAccess(vc, options);
// validVc is null if the provided VC is of the supported types
const vcObject = await getBaseAccess(validVC ?? vc, options);

// Discover the access endpoint from the resource part of the Access Grant.
const verifierEndpoint =
Expand Down
19 changes: 12 additions & 7 deletions src/gConsent/discover/redirectToAccessManagementUi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
//

import type { UrlString, WebId } from "@inrupt/solid-client";
import type {
DatasetWithId,
VerifiableCredential,
import {
verifiableCredentialToDataset,
type DatasetWithId,
type VerifiableCredential,
} from "@inrupt/solid-client-vc";
import { getBaseAccess } from "../util/getBaseAccessVerifiableCredential";
import { getSessionFetch } from "../../common/util/getSessionFetch";
Expand Down Expand Up @@ -102,18 +103,22 @@ export async function redirectToAccessManagementUi(
options: RedirectToAccessManagementUiOptions = {},
): Promise<void> {
const fallbackUi = options.fallbackAccessManagementUi;
let validVC = null;

if (
typeof accessRequestVc !== "string" &&
!isUrl(accessRequestVc.toString()) &&
!isDatasetCore(accessRequestVc)
) {
throw new Error(
"Verifiable Credential is not of valid types: string, URL, VerifiableCredential or DatasetWithId",
);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
validVC = await verifiableCredentialToDataset(accessRequestVc, {
includeVcProperties: true,
requireId: false,
});
}

const requestVc = await getBaseAccess(accessRequestVc, {
const requestVc = await getBaseAccess(validVC ?? accessRequestVc, {
fetch: options.fetch,
});

Expand Down

0 comments on commit 05406e8

Please sign in to comment.