sst 3.0.23 → 3.0.24
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/package.json +1 -1
- package/dist/auth/adapter/adapter.d.ts +0 -24
- package/dist/auth/adapter/adapter.js +0 -4
- package/dist/auth/adapter/apple.d.ts +0 -5
- package/dist/auth/adapter/apple.js +0 -22
- package/dist/auth/adapter/code.d.ts +0 -8
- package/dist/auth/adapter/code.js +0 -47
- package/dist/auth/adapter/facebook.d.ts +0 -5
- package/dist/auth/adapter/facebook.js +0 -27
- package/dist/auth/adapter/github.d.ts +0 -12
- package/dist/auth/adapter/github.js +0 -23
- package/dist/auth/adapter/google.d.ts +0 -17
- package/dist/auth/adapter/google.js +0 -22
- package/dist/auth/adapter/index.d.ts +0 -11
- package/dist/auth/adapter/index.js +0 -10
- package/dist/auth/adapter/link.d.ts +0 -6
- package/dist/auth/adapter/link.js +0 -27
- package/dist/auth/adapter/microsoft.d.ts +0 -11
- package/dist/auth/adapter/microsoft.js +0 -16
- package/dist/auth/adapter/oauth.d.ts +0 -33
- package/dist/auth/adapter/oauth.js +0 -79
- package/dist/auth/adapter/oidc.d.ts +0 -19
- package/dist/auth/adapter/oidc.js +0 -45
- package/dist/auth/adapter/spotify.d.ts +0 -12
- package/dist/auth/adapter/spotify.js +0 -22
- package/dist/auth/example/bun.d.ts +0 -2
- package/dist/auth/example/bun.js +0 -46
- package/dist/auth/handler.d.ts +0 -58
- package/dist/auth/handler.js +0 -207
- package/dist/auth/index.d.ts +0 -10
- package/dist/auth/index.js +0 -10
- package/dist/auth/session.d.ts +0 -25
- package/dist/auth/session.js +0 -28
- package/dist/aws/bus.d.ts +0 -24
- package/dist/aws/bus.js +0 -57
- package/dist/aws/client.d.ts +0 -3
- package/dist/aws/client.js +0 -7
- package/dist/aws/realtime.d.ts +0 -61
- package/dist/aws/realtime.js +0 -76
- package/dist/event/bus.d.ts +0 -20
- package/dist/event/bus.js +0 -57
- package/dist/event/destination.d.ts +0 -19
- package/dist/event/destination.js +0 -6
- package/dist/event/event.d.ts +0 -75
- package/dist/event/event.js +0 -43
- package/dist/event/index.d.ts +0 -75
- package/dist/event/index.js +0 -43
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -3
- package/dist/realtime/index.d.ts +0 -25
- package/dist/realtime/index.js +0 -24
- package/dist/resource.d.ts +0 -9
- package/dist/resource.js +0 -50
- package/dist/util/prettify.d.ts +0 -3
- package/dist/util/prettify.js +0 -1
- package/dist/vector/index.d.ts +0 -193
- package/dist/vector/index.js +0 -62
- package/dist/vector-client.d.ts +0 -186
- package/dist/vector-client.js +0 -41
package/package.json
CHANGED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
import type { Context, Hono } from "hono";
|
|
3
|
-
import { KeyLike } from "jose";
|
|
4
|
-
export type Adapter<Properties = any> = (route: AdapterRoute, options: AdapterOptions<Properties>) => void;
|
|
5
|
-
export type AdapterRoute = Hono;
|
|
6
|
-
export interface AdapterOptions<Properties> {
|
|
7
|
-
name: string;
|
|
8
|
-
algorithm: string;
|
|
9
|
-
encryption: {
|
|
10
|
-
publicKey: () => Promise<KeyLike>;
|
|
11
|
-
privateKey: () => Promise<KeyLike>;
|
|
12
|
-
};
|
|
13
|
-
signing: {
|
|
14
|
-
publicKey: () => Promise<KeyLike>;
|
|
15
|
-
privateKey: () => Promise<KeyLike>;
|
|
16
|
-
};
|
|
17
|
-
success: (ctx: Context, properties: Properties) => Promise<Response>;
|
|
18
|
-
forward: (ctx: Context, response: Response) => Response;
|
|
19
|
-
cookie: (ctx: Context, key: string, value: string, maxAge: number) => void;
|
|
20
|
-
}
|
|
21
|
-
export declare class AdapterError extends Error {
|
|
22
|
-
}
|
|
23
|
-
export declare class AdapterUnknownError extends AdapterError {
|
|
24
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { OauthBasicConfig } from "./oauth.js";
|
|
2
|
-
export declare const AppleAdapter: (config: OauthBasicConfig) => (routes: import("./adapter.js").AdapterRoute, ctx: import("./adapter.js").AdapterOptions<{
|
|
3
|
-
tokenset: import("openid-client").TokenSet;
|
|
4
|
-
client: import("openid-client").BaseClient;
|
|
5
|
-
}>) => Promise<void>;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Issuer } from "openid-client";
|
|
2
|
-
import { OauthAdapter } from "./oauth.js";
|
|
3
|
-
// This adapter support the OAuth flow with the response_mode "form_post" for now.
|
|
4
|
-
// More details about the flow:
|
|
5
|
-
// https://developer.apple.com/documentation/devicemanagement/user_enrollment/onboarding_users_with_account_sign-in/implementing_the_oauth2_authentication_user-enrollment_flow
|
|
6
|
-
//
|
|
7
|
-
// Also note that Apple's discover uri does not work for the OAuth flow, as the
|
|
8
|
-
// userinfo_endpoint are not included in the response.
|
|
9
|
-
// await Issuer.discover("https://appleid.apple.com/.well-known/openid-configuration/");
|
|
10
|
-
const issuer = await Issuer.discover("https://appleid.apple.com/.well-known/openid-configuration");
|
|
11
|
-
export const AppleAdapter =
|
|
12
|
-
/* @__PURE__ */
|
|
13
|
-
(config) => {
|
|
14
|
-
return OauthAdapter({
|
|
15
|
-
issuer,
|
|
16
|
-
...config,
|
|
17
|
-
params: {
|
|
18
|
-
...config.params,
|
|
19
|
-
response_mode: "form_post",
|
|
20
|
-
},
|
|
21
|
-
});
|
|
22
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
export declare function CodeAdapter(config: {
|
|
3
|
-
length?: number;
|
|
4
|
-
onCodeRequest: (code: string, claims: Record<string, any>, req: Request) => Promise<Response>;
|
|
5
|
-
onCodeInvalid: (code: string, claims: Record<string, any>, req: Request) => Promise<Response>;
|
|
6
|
-
}): (routes: import("./adapter.js").AdapterRoute, ctx: import("./adapter.js").AdapterOptions<{
|
|
7
|
-
claims: Record<string, string>;
|
|
8
|
-
}>) => void;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { deleteCookie, getCookie } from "hono/cookie";
|
|
2
|
-
import { UnknownStateError } from "../index.js";
|
|
3
|
-
import { CompactEncrypt, compactDecrypt } from "jose";
|
|
4
|
-
export function CodeAdapter(config) {
|
|
5
|
-
const length = config.length || 6;
|
|
6
|
-
function generate() {
|
|
7
|
-
const buffer = crypto.getRandomValues(new Uint8Array(length));
|
|
8
|
-
const otp = Array.from(buffer)
|
|
9
|
-
.map((byte) => byte % 10)
|
|
10
|
-
.join("");
|
|
11
|
-
return otp;
|
|
12
|
-
}
|
|
13
|
-
return function (routes, ctx) {
|
|
14
|
-
routes.get("/authorize", async (c) => {
|
|
15
|
-
const code = generate();
|
|
16
|
-
const claims = c.req.query();
|
|
17
|
-
delete claims["client_id"];
|
|
18
|
-
delete claims["redirect_uri"];
|
|
19
|
-
delete claims["response_type"];
|
|
20
|
-
delete claims["provider"];
|
|
21
|
-
const authorization = await new CompactEncrypt(new TextEncoder().encode(JSON.stringify({
|
|
22
|
-
claims,
|
|
23
|
-
code,
|
|
24
|
-
})))
|
|
25
|
-
.setProtectedHeader({ alg: "RSA-OAEP-512", enc: "A256GCM" })
|
|
26
|
-
.encrypt(await ctx.encryption.publicKey());
|
|
27
|
-
ctx.cookie(c, "authorization", authorization, 60 * 10);
|
|
28
|
-
return ctx.forward(c, await config.onCodeRequest(code, claims, c.req.raw));
|
|
29
|
-
});
|
|
30
|
-
routes.get("/callback", async (c) => {
|
|
31
|
-
const authorization = getCookie(c, "authorization");
|
|
32
|
-
if (!authorization)
|
|
33
|
-
throw new UnknownStateError();
|
|
34
|
-
const { code, claims } = JSON.parse(new TextDecoder().decode(await compactDecrypt(authorization, await ctx.encryption.privateKey()).then((value) => value.plaintext)));
|
|
35
|
-
if (!code || !claims) {
|
|
36
|
-
return ctx.forward(c, await config.onCodeInvalid(code, claims, c.req.raw));
|
|
37
|
-
}
|
|
38
|
-
const compare = c.req.query("code");
|
|
39
|
-
console.log("comparing", code, "to", compare);
|
|
40
|
-
if (code !== compare) {
|
|
41
|
-
return ctx.forward(c, await config.onCodeInvalid(code, claims, c.req.raw));
|
|
42
|
-
}
|
|
43
|
-
deleteCookie(c, "authorization");
|
|
44
|
-
return ctx.forward(c, await ctx.success(c, { claims }));
|
|
45
|
-
});
|
|
46
|
-
};
|
|
47
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { OauthBasicConfig } from "./oauth.js";
|
|
2
|
-
export declare const FacebookAdapter: (config: OauthBasicConfig) => (routes: import("./adapter.js").AdapterRoute, ctx: import("./adapter.js").AdapterOptions<{
|
|
3
|
-
tokenset: import("openid-client").TokenSet;
|
|
4
|
-
client: import("openid-client").BaseClient;
|
|
5
|
-
}>) => Promise<void>;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Issuer } from "openid-client";
|
|
2
|
-
import { OauthAdapter } from "./oauth.js";
|
|
3
|
-
// Facebook's OIDC flow returns "id_token" as uri hash in redirect uri. Hashes
|
|
4
|
-
// are not passed to Lambda event object. It is likely that Facebook only wants
|
|
5
|
-
// to support redirecting to a frontend uri.
|
|
6
|
-
//
|
|
7
|
-
// We are only going to support the OAuth flow for now. More details about the flow:
|
|
8
|
-
// https://developers.facebook.com/docs/facebook-login/guides/advanced/oidc-token
|
|
9
|
-
//
|
|
10
|
-
// Also note that Facebook's discover uri does not work for the OAuth flow, as the
|
|
11
|
-
// token_endpoint and userinfo_endpoint are not included in the response.
|
|
12
|
-
// await Issuer.discover("https://www.facebook.com/.well-known/openid-configuration/");
|
|
13
|
-
const issuer = new Issuer({
|
|
14
|
-
issuer: "https://www.facebook.com",
|
|
15
|
-
authorization_endpoint: "https://facebook.com/dialog/oauth/",
|
|
16
|
-
jwks_uri: "https://www.facebook.com/.well-known/oauth/openid/jwks/",
|
|
17
|
-
token_endpoint: "https://graph.facebook.com/oauth/access_token",
|
|
18
|
-
userinfo_endpoint: "https://graph.facebook.com/oauth/access_token",
|
|
19
|
-
});
|
|
20
|
-
export const FacebookAdapter =
|
|
21
|
-
/* @__PURE__ */
|
|
22
|
-
(config) => {
|
|
23
|
-
return OauthAdapter({
|
|
24
|
-
issuer,
|
|
25
|
-
...config,
|
|
26
|
-
});
|
|
27
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { OauthBasicConfig } from "./oauth.js";
|
|
2
|
-
import { OidcBasicConfig } from "./oidc.js";
|
|
3
|
-
type Config = ({
|
|
4
|
-
mode: "oauth";
|
|
5
|
-
} & OauthBasicConfig) | ({
|
|
6
|
-
mode: "oidc";
|
|
7
|
-
} & OidcBasicConfig);
|
|
8
|
-
export declare const GithubAdapter: (config: Config) => (routes: import("./adapter.js").AdapterRoute, ctx: import("./adapter.js").AdapterOptions<{
|
|
9
|
-
tokenset: import("openid-client").TokenSet;
|
|
10
|
-
client: import("openid-client").BaseClient;
|
|
11
|
-
}>) => Promise<void>;
|
|
12
|
-
export {};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Issuer } from "openid-client";
|
|
2
|
-
import { OauthAdapter } from "./oauth.js";
|
|
3
|
-
import { OidcAdapter } from "./oidc.js";
|
|
4
|
-
const issuer = new Issuer({
|
|
5
|
-
issuer: "https://github.com",
|
|
6
|
-
authorization_endpoint: "https://github.com/login/oauth/authorize",
|
|
7
|
-
token_endpoint: "https://github.com/login/oauth/access_token",
|
|
8
|
-
});
|
|
9
|
-
export const GithubAdapter =
|
|
10
|
-
/* @__PURE__ */
|
|
11
|
-
(config) => {
|
|
12
|
-
if (config.mode === "oauth") {
|
|
13
|
-
return OauthAdapter({
|
|
14
|
-
issuer,
|
|
15
|
-
...config,
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
return OidcAdapter({
|
|
19
|
-
issuer,
|
|
20
|
-
scope: "openid email profile",
|
|
21
|
-
...config,
|
|
22
|
-
});
|
|
23
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { OidcBasicConfig } from "./oidc.js";
|
|
2
|
-
import { OauthBasicConfig } from "./oauth.js";
|
|
3
|
-
type GooglePrompt = "none" | "consent" | "select_account";
|
|
4
|
-
type GoogleAccessType = "offline" | "online";
|
|
5
|
-
type GoogleConfig = (OauthBasicConfig & {
|
|
6
|
-
mode: "oauth";
|
|
7
|
-
prompt?: GooglePrompt;
|
|
8
|
-
accessType?: GoogleAccessType;
|
|
9
|
-
}) | (OidcBasicConfig & {
|
|
10
|
-
mode: "oidc";
|
|
11
|
-
prompt?: GooglePrompt;
|
|
12
|
-
});
|
|
13
|
-
export declare function GoogleAdapter(config: GoogleConfig): (routes: import("./adapter.js").AdapterRoute, ctx: import("./adapter.js").AdapterOptions<{
|
|
14
|
-
tokenset: import("openid-client").TokenSet;
|
|
15
|
-
client: import("openid-client").BaseClient;
|
|
16
|
-
}>) => Promise<void>;
|
|
17
|
-
export {};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Issuer } from "openid-client";
|
|
2
|
-
import { OidcAdapter } from "./oidc.js";
|
|
3
|
-
import { OauthAdapter } from "./oauth.js";
|
|
4
|
-
const issuer = await Issuer.discover("https://accounts.google.com");
|
|
5
|
-
export function GoogleAdapter(config) {
|
|
6
|
-
/* @__PURE__ */
|
|
7
|
-
if (config.mode === "oauth") {
|
|
8
|
-
return OauthAdapter({
|
|
9
|
-
issuer,
|
|
10
|
-
...config,
|
|
11
|
-
params: {
|
|
12
|
-
...(config.accessType && { access_type: config.accessType }),
|
|
13
|
-
...config.params,
|
|
14
|
-
},
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
return OidcAdapter({
|
|
18
|
-
issuer,
|
|
19
|
-
scope: "openid email profile",
|
|
20
|
-
...config,
|
|
21
|
-
});
|
|
22
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export * from "./oidc.js";
|
|
2
|
-
export * from "./google.js";
|
|
3
|
-
export * from "./link.js";
|
|
4
|
-
export * from "./github.js";
|
|
5
|
-
export * from "./facebook.js";
|
|
6
|
-
export * from "./microsoft.js";
|
|
7
|
-
export * from "./oauth.js";
|
|
8
|
-
export * from "./spotify.js";
|
|
9
|
-
export * from "./code.js";
|
|
10
|
-
export * from "./apple.js";
|
|
11
|
-
export type { Adapter } from "./adapter.js";
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export * from "./oidc.js";
|
|
2
|
-
export * from "./google.js";
|
|
3
|
-
export * from "./link.js";
|
|
4
|
-
export * from "./github.js";
|
|
5
|
-
export * from "./facebook.js";
|
|
6
|
-
export * from "./microsoft.js";
|
|
7
|
-
export * from "./oauth.js";
|
|
8
|
-
export * from "./spotify.js";
|
|
9
|
-
export * from "./code.js";
|
|
10
|
-
export * from "./apple.js";
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
export declare function LinkAdapter(config: {
|
|
3
|
-
onLink: (link: string, claims: Record<string, any>) => Promise<Response>;
|
|
4
|
-
}): (routes: import("./adapter.js").AdapterRoute, ctx: import("./adapter.js").AdapterOptions<{
|
|
5
|
-
claims: Record<string, string>;
|
|
6
|
-
}>) => void;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { SignJWT, jwtVerify } from "jose";
|
|
2
|
-
export function LinkAdapter(config) {
|
|
3
|
-
return function (routes, ctx) {
|
|
4
|
-
routes.get("/authorize", async (c) => {
|
|
5
|
-
const token = await new SignJWT(c.req.query())
|
|
6
|
-
.setProtectedHeader({ alg: ctx.algorithm })
|
|
7
|
-
.setExpirationTime("10m")
|
|
8
|
-
.sign(await ctx.signing.privateKey());
|
|
9
|
-
const url = new URL(new URL(c.req.url).origin);
|
|
10
|
-
url.pathname = `/${ctx.name}/callback`;
|
|
11
|
-
for (const key of url.searchParams.keys()) {
|
|
12
|
-
url.searchParams.delete(key);
|
|
13
|
-
}
|
|
14
|
-
url.searchParams.set("token", token);
|
|
15
|
-
const resp = ctx.forward(c, await config.onLink(url.toString(), c.req.query()));
|
|
16
|
-
return resp;
|
|
17
|
-
});
|
|
18
|
-
routes.get("/callback", async (c) => {
|
|
19
|
-
const token = c.req.query("token");
|
|
20
|
-
if (!token)
|
|
21
|
-
throw new Error("Missing token parameter");
|
|
22
|
-
const verified = await jwtVerify(token, await ctx.signing.publicKey());
|
|
23
|
-
const resp = await ctx.success(c, { claims: verified.payload });
|
|
24
|
-
return resp;
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { OidcBasicConfig } from "./oidc.js";
|
|
2
|
-
type MicrosoftConfig = OidcBasicConfig & {
|
|
3
|
-
mode: "oidc";
|
|
4
|
-
prompt?: "login" | "none" | "consent" | "select_account";
|
|
5
|
-
tenantID?: string;
|
|
6
|
-
};
|
|
7
|
-
export declare function MicrosoftAdapter(config: MicrosoftConfig): (routes: import("./adapter.js").AdapterRoute, ctx: import("./adapter.js").AdapterOptions<{
|
|
8
|
-
tokenset: import("openid-client").TokenSet;
|
|
9
|
-
client: import("openid-client").BaseClient;
|
|
10
|
-
}>) => Promise<void>;
|
|
11
|
-
export {};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Issuer } from "openid-client";
|
|
2
|
-
import { OidcAdapter } from "./oidc.js";
|
|
3
|
-
export function MicrosoftAdapter(config) {
|
|
4
|
-
const authority = config?.tenantID ?? "common";
|
|
5
|
-
const issuer = `https://login.microsoftonline.com/${authority}`;
|
|
6
|
-
return OidcAdapter({
|
|
7
|
-
issuer: new Issuer({
|
|
8
|
-
issuer: `${issuer}/v2.0`,
|
|
9
|
-
authorization_endpoint: `${issuer}/oauth2/v2.0/authorize`,
|
|
10
|
-
token_endpoint: `${issuer}/oauth2/v2.0/token`,
|
|
11
|
-
jwks_uri: `${issuer}/discovery/v2.0/keys`,
|
|
12
|
-
}),
|
|
13
|
-
scope: "openid email profile",
|
|
14
|
-
...config,
|
|
15
|
-
});
|
|
16
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { BaseClient, Issuer, TokenSet } from "openid-client";
|
|
2
|
-
import { AdapterError } from "./adapter.js";
|
|
3
|
-
export interface OauthBasicConfig {
|
|
4
|
-
/**
|
|
5
|
-
* The clientID provided by the third party oauth service
|
|
6
|
-
*/
|
|
7
|
-
clientID: string;
|
|
8
|
-
/**
|
|
9
|
-
* The clientSecret provided by the third party oauth service
|
|
10
|
-
*/
|
|
11
|
-
clientSecret: string;
|
|
12
|
-
/**
|
|
13
|
-
* Various scopes requested for the access token
|
|
14
|
-
*/
|
|
15
|
-
scope: string;
|
|
16
|
-
/**
|
|
17
|
-
* Determines whether users will be prompted for reauthentication and consent
|
|
18
|
-
*/
|
|
19
|
-
prompt?: string;
|
|
20
|
-
/**
|
|
21
|
-
* Additional parameters to be passed to the authorization endpoint
|
|
22
|
-
*/
|
|
23
|
-
params?: Record<string, string>;
|
|
24
|
-
}
|
|
25
|
-
export interface OauthConfig extends OauthBasicConfig {
|
|
26
|
-
issuer: Issuer;
|
|
27
|
-
}
|
|
28
|
-
export declare class OauthError extends AdapterError {
|
|
29
|
-
}
|
|
30
|
-
export declare const OauthAdapter: (config: OauthConfig) => (routes: import("./adapter.js").AdapterRoute, ctx: import("./adapter.js").AdapterOptions<{
|
|
31
|
-
tokenset: TokenSet;
|
|
32
|
-
client: BaseClient;
|
|
33
|
-
}>) => Promise<void>;
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { generators } from "openid-client";
|
|
2
|
-
import { AdapterError } from "./adapter.js";
|
|
3
|
-
import { getCookie } from "hono/cookie";
|
|
4
|
-
export class OauthError extends AdapterError {
|
|
5
|
-
}
|
|
6
|
-
export const OauthAdapter =
|
|
7
|
-
/* @__PURE__ */
|
|
8
|
-
(config) => {
|
|
9
|
-
return async function (routes, ctx) {
|
|
10
|
-
function getClient(c) {
|
|
11
|
-
const callback = c.req.url.replace(/authorize\/.*$/, "callback");
|
|
12
|
-
return [
|
|
13
|
-
callback,
|
|
14
|
-
new config.issuer.Client({
|
|
15
|
-
client_id: config.clientID,
|
|
16
|
-
client_secret: config.clientSecret,
|
|
17
|
-
redirect_uris: [callback],
|
|
18
|
-
response_types: ["code"],
|
|
19
|
-
}),
|
|
20
|
-
];
|
|
21
|
-
}
|
|
22
|
-
routes.get("/authorize", async (c) => {
|
|
23
|
-
const [_, client] = getClient(c);
|
|
24
|
-
const code_verifier = generators.codeVerifier();
|
|
25
|
-
const state = generators.state();
|
|
26
|
-
const code_challenge = generators.codeChallenge(code_verifier);
|
|
27
|
-
const url = client.authorizationUrl({
|
|
28
|
-
scope: config.scope,
|
|
29
|
-
code_challenge: code_challenge,
|
|
30
|
-
code_challenge_method: "S256",
|
|
31
|
-
state,
|
|
32
|
-
prompt: config.prompt,
|
|
33
|
-
...config.params,
|
|
34
|
-
});
|
|
35
|
-
ctx.cookie(c, "auth_code_verifier", code_verifier, 60 * 10);
|
|
36
|
-
ctx.cookie(c, "auth_state", state, 60 * 10);
|
|
37
|
-
return c.redirect(url);
|
|
38
|
-
});
|
|
39
|
-
routes.get("/callback", async (c) => {
|
|
40
|
-
const [callback, client] = getClient(c);
|
|
41
|
-
const query = c.req.query();
|
|
42
|
-
if (query.error) {
|
|
43
|
-
throw new OauthError(query.error);
|
|
44
|
-
}
|
|
45
|
-
const code_verifier = getCookie(c, "auth_code_verifier");
|
|
46
|
-
const state = getCookie(c, "auth_state");
|
|
47
|
-
const tokenset = await client[config.issuer.metadata.userinfo_endpoint
|
|
48
|
-
? "callback"
|
|
49
|
-
: "oauthCallback"](callback, query, {
|
|
50
|
-
code_verifier,
|
|
51
|
-
state,
|
|
52
|
-
});
|
|
53
|
-
return ctx.success(c, {
|
|
54
|
-
client,
|
|
55
|
-
tokenset,
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
// response_mode=form_post
|
|
59
|
-
routes.get("/callback", async (c) => {
|
|
60
|
-
const [callback, client] = getClient(c);
|
|
61
|
-
const form = await c.req.formData();
|
|
62
|
-
if (form.get("error")) {
|
|
63
|
-
throw new OauthError(form.get("error").toString());
|
|
64
|
-
}
|
|
65
|
-
const code_verifier = getCookie(c, "auth_code_verifier");
|
|
66
|
-
const state = getCookie(c, "auth_state");
|
|
67
|
-
const tokenset = await client[config.issuer.metadata.userinfo_endpoint
|
|
68
|
-
? "callback"
|
|
69
|
-
: "oauthCallback"](callback, Object.fromEntries(form), {
|
|
70
|
-
code_verifier,
|
|
71
|
-
state,
|
|
72
|
-
});
|
|
73
|
-
return ctx.success(c, {
|
|
74
|
-
client,
|
|
75
|
-
tokenset,
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
};
|
|
79
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { BaseClient, Issuer, TokenSet } from "openid-client";
|
|
2
|
-
export interface OidcBasicConfig {
|
|
3
|
-
/**
|
|
4
|
-
* The clientID provided by the third party oauth service
|
|
5
|
-
*/
|
|
6
|
-
clientID: string;
|
|
7
|
-
/**
|
|
8
|
-
* Determines whether users will be prompted for reauthentication and consent
|
|
9
|
-
*/
|
|
10
|
-
prompt?: string;
|
|
11
|
-
}
|
|
12
|
-
export interface OidcConfig extends OidcBasicConfig {
|
|
13
|
-
issuer: Issuer;
|
|
14
|
-
scope: string;
|
|
15
|
-
}
|
|
16
|
-
export declare const OidcAdapter: (config: OidcConfig) => (routes: import("./adapter.js").AdapterRoute, ctx: import("./adapter.js").AdapterOptions<{
|
|
17
|
-
tokenset: TokenSet;
|
|
18
|
-
client: BaseClient;
|
|
19
|
-
}>) => Promise<void>;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { generators } from "openid-client";
|
|
2
|
-
import { getCookie } from "hono/cookie";
|
|
3
|
-
export const OidcAdapter = /* @__PURE__ */ (config) => {
|
|
4
|
-
return async function (routes, ctx) {
|
|
5
|
-
routes.get("/authorize", async (c) => {
|
|
6
|
-
const callback = c.req.url.replace(/authorize\/.*$/, "callback");
|
|
7
|
-
const client = new config.issuer.Client({
|
|
8
|
-
client_id: config.clientID,
|
|
9
|
-
redirect_uris: [callback],
|
|
10
|
-
response_types: ["id_token"],
|
|
11
|
-
});
|
|
12
|
-
const nonce = generators.nonce();
|
|
13
|
-
const state = generators.state();
|
|
14
|
-
const url = client.authorizationUrl({
|
|
15
|
-
scope: config.scope,
|
|
16
|
-
response_mode: "form_post",
|
|
17
|
-
nonce,
|
|
18
|
-
state,
|
|
19
|
-
prompt: config.prompt,
|
|
20
|
-
});
|
|
21
|
-
ctx.cookie(c, "auth_nonce", nonce, 60 * 10);
|
|
22
|
-
ctx.cookie(c, "auth_state", state, 60 * 10);
|
|
23
|
-
return c.redirect(url);
|
|
24
|
-
});
|
|
25
|
-
routes.post("/callback", async (c) => {
|
|
26
|
-
const callback = c.req.url.replace(/authorize\/.*$/, "callback");
|
|
27
|
-
const client = new config.issuer.Client({
|
|
28
|
-
client_id: config.clientID,
|
|
29
|
-
redirect_uris: [callback],
|
|
30
|
-
response_types: ["id_token"],
|
|
31
|
-
});
|
|
32
|
-
const form = await c.req.formData();
|
|
33
|
-
const nonce = getCookie(c, "auth_nonce");
|
|
34
|
-
const state = getCookie(c, "auth_state");
|
|
35
|
-
const tokenset = await client.callback(callback, Object.fromEntries(form), {
|
|
36
|
-
nonce,
|
|
37
|
-
state,
|
|
38
|
-
});
|
|
39
|
-
return ctx.success(c, {
|
|
40
|
-
tokenset,
|
|
41
|
-
client,
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { OauthBasicConfig } from "./oauth.js";
|
|
2
|
-
/**
|
|
3
|
-
* The Spotify Adapter follows the PKCE flow outlined here:
|
|
4
|
-
* https://developer.spotify.com/documentation/web-api/tutorials/code-pkce-flow
|
|
5
|
-
*
|
|
6
|
-
* List of scopes available:
|
|
7
|
-
* https://developer.spotify.com/documentation/web-api/concepts/scopes
|
|
8
|
-
*/
|
|
9
|
-
export declare const SpotifyAdapter: (config: OauthBasicConfig) => (routes: import("./adapter.js").AdapterRoute, ctx: import("./adapter.js").AdapterOptions<{
|
|
10
|
-
tokenset: import("openid-client").TokenSet;
|
|
11
|
-
client: import("openid-client").BaseClient;
|
|
12
|
-
}>) => Promise<void>;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Issuer } from "openid-client";
|
|
2
|
-
import { OauthAdapter } from "./oauth.js";
|
|
3
|
-
const issuer = new Issuer({
|
|
4
|
-
issuer: "https://accounts.spotify.com",
|
|
5
|
-
authorization_endpoint: "https://accounts.spotify.com/authorize",
|
|
6
|
-
token_endpoint: "https://accounts.spotify.com/api/token",
|
|
7
|
-
});
|
|
8
|
-
/**
|
|
9
|
-
* The Spotify Adapter follows the PKCE flow outlined here:
|
|
10
|
-
* https://developer.spotify.com/documentation/web-api/tutorials/code-pkce-flow
|
|
11
|
-
*
|
|
12
|
-
* List of scopes available:
|
|
13
|
-
* https://developer.spotify.com/documentation/web-api/concepts/scopes
|
|
14
|
-
*/
|
|
15
|
-
export const SpotifyAdapter =
|
|
16
|
-
/* @__PURE__ */
|
|
17
|
-
(config) => {
|
|
18
|
-
return OauthAdapter({
|
|
19
|
-
issuer,
|
|
20
|
-
...config,
|
|
21
|
-
});
|
|
22
|
-
};
|
package/dist/auth/example/bun.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { AuthHandler } from "../handler.js";
|
|
2
|
-
import { LinkAdapter } from "../adapter/link.js";
|
|
3
|
-
import { createSessionBuilder } from "../session.js";
|
|
4
|
-
import { CodeAdapter } from "../adapter/index.js";
|
|
5
|
-
const sessions = createSessionBuilder();
|
|
6
|
-
export default AuthHandler({
|
|
7
|
-
providers: {
|
|
8
|
-
link: LinkAdapter({
|
|
9
|
-
async onLink(link, claims) {
|
|
10
|
-
return new Response(link, {
|
|
11
|
-
status: 200,
|
|
12
|
-
headers: { "Content-Type": "text/plain" },
|
|
13
|
-
});
|
|
14
|
-
},
|
|
15
|
-
}),
|
|
16
|
-
code: CodeAdapter({
|
|
17
|
-
onCodeRequest: async (code, claims) => {
|
|
18
|
-
return new Response("Your code is " + code, {
|
|
19
|
-
status: 200,
|
|
20
|
-
headers: { "Content-Type": "text/plain" },
|
|
21
|
-
});
|
|
22
|
-
},
|
|
23
|
-
onCodeInvalid: async (code, claims) => {
|
|
24
|
-
return new Response("Code is invalid " + code, {
|
|
25
|
-
status: 200,
|
|
26
|
-
headers: { "Content-Type": "text/plain" },
|
|
27
|
-
});
|
|
28
|
-
},
|
|
29
|
-
}),
|
|
30
|
-
},
|
|
31
|
-
callbacks: {
|
|
32
|
-
auth: {
|
|
33
|
-
async allowClient(input) {
|
|
34
|
-
return true;
|
|
35
|
-
},
|
|
36
|
-
async success(ctx, input) {
|
|
37
|
-
return ctx.session({
|
|
38
|
-
type: "user",
|
|
39
|
-
properties: {
|
|
40
|
-
email: input.claims.email,
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
});
|