@neuroncloud/ido-next 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/package.json +33 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { IdoClient, Tokens } from "@neuroncloud/ido-node";
|
|
2
|
+
export type NextClientFactory = (request: Request) => IdoClient | Promise<IdoClient>;
|
|
3
|
+
export type NextRouteHandler = (request: Request, context?: unknown) => Response | Promise<Response>;
|
|
4
|
+
export interface CallbackRouteOptions {
|
|
5
|
+
createClient: NextClientFactory;
|
|
6
|
+
onTokens: (tokens: Tokens, request: Request) => void | Promise<void>;
|
|
7
|
+
redirectTo?: string | ((request: Request) => string);
|
|
8
|
+
}
|
|
9
|
+
export interface AuthenticatedRouteOptions {
|
|
10
|
+
createClient: NextClientFactory;
|
|
11
|
+
onUnauthorized?: (request: Request) => Response | Promise<Response>;
|
|
12
|
+
}
|
|
13
|
+
export declare function createCallbackRoute(options: CallbackRouteOptions): NextRouteHandler;
|
|
14
|
+
export declare function requireAuthentication(handler: NextRouteHandler, options: AuthenticatedRouteOptions): NextRouteHandler;
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/D,MAAM,MAAM,iBAAiB,GAAG,CAC9B,OAAO,EAAE,OAAO,KACb,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AAEpC,MAAM,MAAM,gBAAgB,GAAG,CAC7B,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,OAAO,KACd,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAElC,MAAM,WAAW,oBAAoB;IACnC,YAAY,EAAE,iBAAiB,CAAC;IAChC,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrE,UAAU,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,OAAO,EAAE,OAAO,KAAK,MAAM,CAAC,CAAC;CACtD;AAED,MAAM,WAAW,yBAAyB;IACxC,YAAY,EAAE,iBAAiB,CAAC;IAChC,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CACrE;AAED,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,oBAAoB,GAC5B,gBAAgB,CAclB;AAED,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE,yBAAyB,GACjC,gBAAgB,CAelB"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export function createCallbackRoute(options) {
|
|
2
|
+
return async (request) => {
|
|
3
|
+
const client = await options.createClient(request);
|
|
4
|
+
await client.start();
|
|
5
|
+
const tokens = await client.handleRedirect({ url: request.url });
|
|
6
|
+
await options.onTokens(tokens, request);
|
|
7
|
+
const redirectTo = typeof options.redirectTo === "function"
|
|
8
|
+
? options.redirectTo(request)
|
|
9
|
+
: options.redirectTo;
|
|
10
|
+
return Response.redirect(new URL(redirectTo ?? "/", request.url));
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export function requireAuthentication(handler, options) {
|
|
14
|
+
return async (request, context) => {
|
|
15
|
+
const client = await options.createClient(request);
|
|
16
|
+
await client.start();
|
|
17
|
+
if (await client.isAuthenticated()) {
|
|
18
|
+
return handler(request, context);
|
|
19
|
+
}
|
|
20
|
+
if (options.onUnauthorized) {
|
|
21
|
+
return options.onUnauthorized(request);
|
|
22
|
+
}
|
|
23
|
+
return Response.json({ error: "unauthorized" }, { status: 401 });
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAsBA,MAAM,UAAU,mBAAmB,CACjC,OAA6B;IAE7B,OAAO,KAAK,EAAE,OAAO,EAAE,EAAE;QACvB,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QACnD,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;QACrB,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;QACjE,MAAM,OAAO,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAExC,MAAM,UAAU,GACd,OAAO,OAAO,CAAC,UAAU,KAAK,UAAU;YACtC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC;YAC7B,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC;QAEzB,OAAO,QAAQ,CAAC,QAAQ,CAAC,IAAI,GAAG,CAAC,UAAU,IAAI,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;IACpE,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,qBAAqB,CACnC,OAAyB,EACzB,OAAkC;IAElC,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE;QAChC,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QACnD,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;QAErB,IAAI,MAAM,MAAM,CAAC,eAAe,EAAE,EAAE,CAAC;YACnC,OAAO,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACnC,CAAC;QAED,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;YAC3B,OAAO,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QACzC,CAAC;QAED,OAAO,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;IACnE,CAAC,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@neuroncloud/ido-next",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": ["dist"],
|
|
14
|
+
"sideEffects": false,
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc -p tsconfig.json",
|
|
17
|
+
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@neuroncloud/ido-node": "0.1.0"
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"next": ">=14"
|
|
24
|
+
},
|
|
25
|
+
"peerDependenciesMeta": {
|
|
26
|
+
"next": {
|
|
27
|
+
"optional": true
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
}
|
|
33
|
+
}
|