Skip to content

Commit

Permalink
Sharing resource initiated by the app (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
elf-pavlik authored Apr 17, 2023
2 parents fafc667 + 8f27605 commit 3bb5244
Show file tree
Hide file tree
Showing 43 changed files with 939 additions and 146 deletions.
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
. "$(dirname "$0")/_/husky.sh"

npx pretty-quick --staged
npx eslint packages/*/src
39 changes: 20 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,31 @@
"./packages/*"
],
"devDependencies": {
"@jest/globals": "^29.0.3 ",
"@types/jest": "^29.0.3",
"@typescript-eslint/eslint-plugin": "^4.26.0",
"@typescript-eslint/parser": "^4.26.0",
"eslint": "^7.27.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2",
"@jest/globals": "^29.5.0 ",
"@types/jest": "^29.5.0",
"@typescript-eslint/eslint-plugin": "^5.58.0",
"@typescript-eslint/parser": "^5.58.0",
"eslint": "^8.38.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-monorepo": "^0.3.2",
"husky": "^7.0.1",
"jest": "^29.0.3",
"jest-mock": "^29.0.3",
"jest-rdf": "^1.7.0",
"lerna": "^4.0.0",
"prettier": "^2.3.2",
"pretty-quick": "^3.1.1",
"rimraf": "^3.0.2",
"ts-jest": "^29.0.1",
"typescript": "^4.8.3"
"husky": "^8.0.3",
"jest": "^29.5.0",
"jest-mock": "^29.5.0",
"jest-rdf": "^1.8.0",
"lerna": "^6.6.1",
"prettier": "^2.8.7",
"pretty-quick": "^3.1.3",
"rimraf": "^5.0.0",
"ts-jest": "^29.1.0",
"typescript": "^5.0.4"
},
"scripts": {
"prepare": "husky install"
},
"volta": {
"node": "16.14.0"
"node": "18.15.0",
"yarn": "1.22.19"
}
}
9 changes: 5 additions & 4 deletions packages/application/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,21 @@
"test": "test"
},
"scripts": {
"build": "npm run clean && npm run build:cjs && npm run build:mjs && sh fixup.sh",
"build": "npm run build:cjs && npm run build:mjs && sh fixup.sh",
"build:cjs": "tsc -b tsconfig-cjs.json",
"build:mjs": "tsc -b tsconfig-mjs.json",
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
"clean": "rimraf dist tsconfig.tsbuildinfo"
"clean": "rimraf dist tsconfig.tsbuildinfo",
"publish": "npm run clean && npm run build"
},
"dependencies": {
"@janeirodigital/interop-data-model": "^1.0.0-rc.17",
"@janeirodigital/interop-namespaces": "^1.0.0-rc.17",
"@janeirodigital/interop-utils": "^1.0.0-rc.17",
"n3": "^1.11.0"
"n3": "^1.16.4"
},
"devDependencies": {
"@janeirodigital/interop-test-utils": "^1.0.0-rc.17",
"@rdfjs/types": "^1.0.1"
"@rdfjs/types": "^1.1.0"
}
}
23 changes: 12 additions & 11 deletions packages/application/src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,20 @@ export class Application {
if (applicationRegistrationIri) {
this.hasApplicationRegistration = await this.factory.readable.applicationRegistration(applicationRegistrationIri);
}
if (!applicationRegistrationIri || !this.hasApplicationRegistration?.hasAccessGrant.granted) {
this.authorizationRedirectEndpoint = await discoverAuthorizationRedirectEndpoint(
this.authorizationAgentIri,
this.rawFetch
);
}
this.authorizationRedirectEndpoint = await discoverAuthorizationRedirectEndpoint(
this.authorizationAgentIri,
this.rawFetch
);
}

// eslint-disable-next-line consistent-return
get authorizationRedirectUri(): string | undefined {
if (this.authorizationRedirectEndpoint) {
return `${this.authorizationRedirectEndpoint}?client_id=${this.applicationId}`;
}
get authorizationRedirectUri(): string {
return `${this.authorizationRedirectEndpoint}?client_id=${encodeURIComponent(this.applicationId)}`;
}

getShareUri(resourceIri: string): string {
return `${this.authorizationRedirectEndpoint}?resource=${encodeURIComponent(
resourceIri
)}&client_id=${encodeURIComponent(this.applicationId)}`;
}

static async build(
Expand Down
31 changes: 17 additions & 14 deletions packages/application/test/application-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,6 @@ describe('applicatrion registration exists', () => {
expect(app.hasApplicationRegistration).toBeInstanceOf(ReadableApplicationRegistration);
});

test('should have authorizationRedirectEndpoint undefined', async () => {
mocked.mockResolvedValueOnce(await statelessFetch(webId)).mockResolvedValueOnce(responseMock);
const app = await Application.build(webId, applicationId, { fetch: mocked, randomUUID });
expect(app.authorizationRedirectEndpoint).toBeUndefined();
});

test('should have authorizationRedirectUri undefined', async () => {
mocked.mockResolvedValueOnce(await statelessFetch(webId)).mockResolvedValueOnce(responseMock);
const app = await Application.build(webId, applicationId, { fetch: mocked, randomUUID });
expect(app.authorizationRedirectUri).toBeUndefined();
});

test('should have dataOwners getter', async () => {
mocked.mockResolvedValueOnce(await statelessFetch(webId)).mockResolvedValueOnce(responseMock);
const app = await Application.build(webId, applicationId, { fetch: mocked, randomUUID });
Expand All @@ -51,7 +39,7 @@ describe('applicatrion registration exists', () => {
}
});
});
describe('applicatrion registration does not exist', () => {
describe('discovery helpers', () => {
const expectedRedirectUriBase = 'https://auth.example/authorize';
const mocked = jest.fn(statelessFetch);
const responseMock = { ok: true, headers: { get: (): null => null } } as unknown as RdfResponse;
Expand All @@ -72,12 +60,27 @@ describe('applicatrion registration does not exist', () => {
test('should have correct authorizationRedirectUri', async () => {
mocked.mockResolvedValueOnce(await statelessFetch(webId)).mockResolvedValueOnce(responseMock);
const app = await Application.build(webId, applicationId, { fetch: mocked, randomUUID });
expect(app.authorizationRedirectUri).toBe(`${expectedRedirectUriBase}?client_id=${applicationId}`);
expect(app.authorizationRedirectUri).toBe(
`${expectedRedirectUriBase}?client_id=${encodeURIComponent(applicationId)}`
);
});

test('should have dataOwners getter returning an empty array', async () => {
mocked.mockResolvedValueOnce(await statelessFetch(webId)).mockResolvedValueOnce(responseMock);
const app = await Application.build(webId, applicationId, { fetch: mocked, randomUUID });
expect(app.dataOwners).toHaveLength(0);
});

// TODO: refactor to be independent from order of query parameters
test('should provide shareUri', async () => {
mocked.mockResolvedValueOnce(await statelessFetch(webId)).mockResolvedValueOnce(responseMock);
const app = await Application.build(webId, applicationId, { fetch: mocked, randomUUID });
const resourceUri = 'some-resource-uri';
const shareUri = app.getShareUri(resourceUri);
expect(shareUri).toBe(
`${expectedRedirectUriBase}?resource=${encodeURIComponent(resourceUri)}&client_id=${encodeURIComponent(
applicationId
)}`
);
});
});
9 changes: 5 additions & 4 deletions packages/authorization-agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,21 @@
"test": "test"
},
"scripts": {
"build": "npm run clean && npm run build:cjs && npm run build:mjs && sh fixup.sh",
"build": "npm run build:cjs && npm run build:mjs && sh fixup.sh",
"build:cjs": "tsc -b tsconfig-cjs.json",
"build:mjs": "tsc -b tsconfig-mjs.json",
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
"clean": "rimraf dist tsconfig.tsbuildinfo"
"clean": "rimraf dist tsconfig.tsbuildinfo",
"publish": "npm run clean && npm run build"
},
"dependencies": {
"@janeirodigital/interop-data-model": "^1.0.0-rc.17",
"@janeirodigital/interop-namespaces": "^1.0.0-rc.17",
"@janeirodigital/interop-utils": "^1.0.0-rc.17",
"n3": "^1.11.0"
"n3": "^1.16.4"
},
"devDependencies": {
"@janeirodigital/interop-test-utils": "^1.0.0-rc.17",
"@rdfjs/types": "^1.0.1"
"@rdfjs/types": "^1.1.0"
}
}
Loading

0 comments on commit 3bb5244

Please sign in to comment.