Skip to content

Commit 36934e8

Browse files
committed
temporary header against CORS, not the right solution
1 parent 0ba8846 commit 36934e8

File tree

6 files changed

+18
-7
lines changed

6 files changed

+18
-7
lines changed

packages/uma/config/routes/policies.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"@type": "HttpHandlerRoute",
99
"methods": [
1010
"GET",
11-
"POST"
11+
"POST",
12+
"OPTIONS"
1213
],
1314
"handler": {
1415
"@type": "PolicyRequestHandler",

packages/uma/src/routes/Policy.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class PolicyRequestHandler extends HttpHandler {
3131
*/
3232
protected getCredentials(request: HttpHandlerRequest): string {
3333
const header = request.headers['authorization'];
34-
if (typeof header !== 'string') {
34+
if (typeof header !== 'string' && request.method !== "OPTIONS") {
3535
throw new BadRequestHttpError('Missing Authorization header');
3636
}
3737
return header;
@@ -53,6 +53,15 @@ export class PolicyRequestHandler extends HttpHandler {
5353
case 'DELETE': return deletePolicy(request, store, this.storage, client, this.baseUrl);
5454
case 'PATCH': return editPolicy(request, store, this.storage, client, this.baseUrl);
5555
case 'PUT': return rewritePolicy(request, store, this.storage, client, this.baseUrl);
56+
case 'OPTIONS': return {
57+
status: 204,
58+
headers: {
59+
// this is only for the url without <encodedId>
60+
'Access-Control-Allow-Origin': 'http://localhost:5173',
61+
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
62+
'Access-Control-Allow-Headers': 'Authorization, Content-Type',
63+
}
64+
}
5665
default: throw new MethodNotAllowedHttpError();
5766
}
5867
}

packages/uma/src/util/routeSpecific/policies/CreatePolicies.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export async function addPolicies(request: HttpHandlerRequest, store: Store, sto
118118

119119

120120
return {
121-
status: 201
121+
status: 201,
122+
headers: { 'access-control-allow-origin': 'http://localhost:5173' }
122123
}
123124
}

packages/uma/src/util/routeSpecific/policies/DeletePolicies.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export async function deleteOnePolicy(policyId: string, store: Store, storage: U
6161

6262
// Delete succesful
6363
return {
64-
status: 200
64+
status: 200,
65+
headers: { 'access-control-allow-origin': 'http://localhost:5173' }
6566
}
6667
}

packages/uma/src/util/routeSpecific/policies/GetPolicies.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { HttpHandlerRequest, HttpHandlerResponse } from "../../http/models/HttpHandler";
22
import { Quad, Store } from "n3";
33
import { odrlAssigner, relations, namedNode, quadsToText, checkBaseURL, retrieveID } from "./PolicyUtil";
4-
import { MethodNotAllowedHttpError } from "@solid/community-server";
54

65

76
/**
@@ -104,7 +103,7 @@ async function getOnePolicy(policyId: string, store: Store, clientId: string): P
104103
return {
105104
status: 204,
106105
headers: {
107-
'content-type': 'text/turtle',
106+
'content-type': 'text/turtle', 'access-control-allow-origin': 'http://localhost:5173'
108107
},
109108
body: '',
110109
}

packages/uma/src/util/routeSpecific/policies/PolicyUtil.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export async function quadsToText(quads: Quad[]): Promise<HttpHandlerResponse<an
5454
} else {
5555
resolve({
5656
status: 200,
57-
headers: { 'content-type': 'text/turtle' },
57+
headers: { 'content-type': 'text/turtle', 'access-control-allow-origin': 'http://localhost:5173' },
5858
body: result
5959
});
6060
}

0 commit comments

Comments
 (0)