@_mustachio/openauth 0.6.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/esm/client.js +186 -0
- package/dist/esm/css.d.js +0 -0
- package/dist/esm/error.js +73 -0
- package/dist/esm/index.js +14 -0
- package/dist/esm/issuer.js +558 -0
- package/dist/esm/jwt.js +16 -0
- package/dist/esm/keys.js +113 -0
- package/dist/esm/pkce.js +35 -0
- package/dist/esm/provider/apple.js +28 -0
- package/dist/esm/provider/arctic.js +43 -0
- package/dist/esm/provider/code.js +58 -0
- package/dist/esm/provider/cognito.js +16 -0
- package/dist/esm/provider/discord.js +15 -0
- package/dist/esm/provider/facebook.js +24 -0
- package/dist/esm/provider/github.js +15 -0
- package/dist/esm/provider/google.js +25 -0
- package/dist/esm/provider/index.js +3 -0
- package/dist/esm/provider/jumpcloud.js +15 -0
- package/dist/esm/provider/keycloak.js +15 -0
- package/dist/esm/provider/linkedin.js +15 -0
- package/dist/esm/provider/m2m.js +17 -0
- package/dist/esm/provider/microsoft.js +24 -0
- package/dist/esm/provider/oauth2.js +119 -0
- package/dist/esm/provider/oidc.js +69 -0
- package/dist/esm/provider/passkey.js +315 -0
- package/dist/esm/provider/password.js +306 -0
- package/dist/esm/provider/provider.js +10 -0
- package/dist/esm/provider/slack.js +15 -0
- package/dist/esm/provider/spotify.js +15 -0
- package/dist/esm/provider/twitch.js +15 -0
- package/dist/esm/provider/x.js +16 -0
- package/dist/esm/provider/yahoo.js +15 -0
- package/dist/esm/random.js +27 -0
- package/dist/esm/storage/aws.js +39 -0
- package/dist/esm/storage/cloudflare.js +42 -0
- package/dist/esm/storage/dynamo.js +116 -0
- package/dist/esm/storage/memory.js +88 -0
- package/dist/esm/storage/storage.js +36 -0
- package/dist/esm/subject.js +7 -0
- package/dist/esm/ui/base.js +407 -0
- package/dist/esm/ui/code.js +151 -0
- package/dist/esm/ui/form.js +43 -0
- package/dist/esm/ui/icon.js +92 -0
- package/dist/esm/ui/passkey.js +329 -0
- package/dist/esm/ui/password.js +338 -0
- package/dist/esm/ui/select.js +187 -0
- package/dist/esm/ui/theme.js +115 -0
- package/dist/esm/util.js +54 -0
- package/dist/types/client.d.ts +466 -0
- package/dist/types/client.d.ts.map +1 -0
- package/dist/types/error.d.ts +77 -0
- package/dist/types/error.d.ts.map +1 -0
- package/dist/types/index.d.ts +20 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/issuer.d.ts +465 -0
- package/dist/types/issuer.d.ts.map +1 -0
- package/dist/types/jwt.d.ts +6 -0
- package/dist/types/jwt.d.ts.map +1 -0
- package/dist/types/keys.d.ts +18 -0
- package/dist/types/keys.d.ts.map +1 -0
- package/dist/types/pkce.d.ts +7 -0
- package/dist/types/pkce.d.ts.map +1 -0
- package/dist/types/provider/apple.d.ts +108 -0
- package/dist/types/provider/apple.d.ts.map +1 -0
- package/dist/types/provider/arctic.d.ts +16 -0
- package/dist/types/provider/arctic.d.ts.map +1 -0
- package/dist/types/provider/code.d.ts +74 -0
- package/dist/types/provider/code.d.ts.map +1 -0
- package/dist/types/provider/cognito.d.ts +64 -0
- package/dist/types/provider/cognito.d.ts.map +1 -0
- package/dist/types/provider/discord.d.ts +38 -0
- package/dist/types/provider/discord.d.ts.map +1 -0
- package/dist/types/provider/facebook.d.ts +74 -0
- package/dist/types/provider/facebook.d.ts.map +1 -0
- package/dist/types/provider/github.d.ts +38 -0
- package/dist/types/provider/github.d.ts.map +1 -0
- package/dist/types/provider/google.d.ts +74 -0
- package/dist/types/provider/google.d.ts.map +1 -0
- package/dist/types/provider/index.d.ts +4 -0
- package/dist/types/provider/index.d.ts.map +1 -0
- package/dist/types/provider/jumpcloud.d.ts +38 -0
- package/dist/types/provider/jumpcloud.d.ts.map +1 -0
- package/dist/types/provider/keycloak.d.ts +67 -0
- package/dist/types/provider/keycloak.d.ts.map +1 -0
- package/dist/types/provider/linkedin.d.ts +6 -0
- package/dist/types/provider/linkedin.d.ts.map +1 -0
- package/dist/types/provider/m2m.d.ts +34 -0
- package/dist/types/provider/m2m.d.ts.map +1 -0
- package/dist/types/provider/microsoft.d.ts +89 -0
- package/dist/types/provider/microsoft.d.ts.map +1 -0
- package/dist/types/provider/oauth2.d.ts +133 -0
- package/dist/types/provider/oauth2.d.ts.map +1 -0
- package/dist/types/provider/oidc.d.ts +91 -0
- package/dist/types/provider/oidc.d.ts.map +1 -0
- package/dist/types/provider/passkey.d.ts +143 -0
- package/dist/types/provider/passkey.d.ts.map +1 -0
- package/dist/types/provider/password.d.ts +210 -0
- package/dist/types/provider/password.d.ts.map +1 -0
- package/dist/types/provider/provider.d.ts +29 -0
- package/dist/types/provider/provider.d.ts.map +1 -0
- package/dist/types/provider/slack.d.ts +59 -0
- package/dist/types/provider/slack.d.ts.map +1 -0
- package/dist/types/provider/spotify.d.ts +38 -0
- package/dist/types/provider/spotify.d.ts.map +1 -0
- package/dist/types/provider/twitch.d.ts +38 -0
- package/dist/types/provider/twitch.d.ts.map +1 -0
- package/dist/types/provider/x.d.ts +38 -0
- package/dist/types/provider/x.d.ts.map +1 -0
- package/dist/types/provider/yahoo.d.ts +38 -0
- package/dist/types/provider/yahoo.d.ts.map +1 -0
- package/dist/types/random.d.ts +3 -0
- package/dist/types/random.d.ts.map +1 -0
- package/dist/types/storage/aws.d.ts +4 -0
- package/dist/types/storage/aws.d.ts.map +1 -0
- package/dist/types/storage/cloudflare.d.ts +34 -0
- package/dist/types/storage/cloudflare.d.ts.map +1 -0
- package/dist/types/storage/dynamo.d.ts +65 -0
- package/dist/types/storage/dynamo.d.ts.map +1 -0
- package/dist/types/storage/memory.d.ts +49 -0
- package/dist/types/storage/memory.d.ts.map +1 -0
- package/dist/types/storage/storage.d.ts +15 -0
- package/dist/types/storage/storage.d.ts.map +1 -0
- package/dist/types/subject.d.ts +122 -0
- package/dist/types/subject.d.ts.map +1 -0
- package/dist/types/ui/base.d.ts +5 -0
- package/dist/types/ui/base.d.ts.map +1 -0
- package/dist/types/ui/code.d.ts +104 -0
- package/dist/types/ui/code.d.ts.map +1 -0
- package/dist/types/ui/form.d.ts +6 -0
- package/dist/types/ui/form.d.ts.map +1 -0
- package/dist/types/ui/icon.d.ts +6 -0
- package/dist/types/ui/icon.d.ts.map +1 -0
- package/dist/types/ui/passkey.d.ts +5 -0
- package/dist/types/ui/passkey.d.ts.map +1 -0
- package/dist/types/ui/password.d.ts +139 -0
- package/dist/types/ui/password.d.ts.map +1 -0
- package/dist/types/ui/select.d.ts +55 -0
- package/dist/types/ui/select.d.ts.map +1 -0
- package/dist/types/ui/theme.d.ts +207 -0
- package/dist/types/ui/theme.d.ts.map +1 -0
- package/dist/types/util.d.ts +8 -0
- package/dist/types/util.d.ts.map +1 -0
- package/package.json +51 -0
- package/src/client.ts +749 -0
- package/src/css.d.ts +4 -0
- package/src/error.ts +120 -0
- package/src/index.ts +26 -0
- package/src/issuer.ts +1302 -0
- package/src/jwt.ts +17 -0
- package/src/keys.ts +139 -0
- package/src/pkce.ts +40 -0
- package/src/provider/apple.ts +127 -0
- package/src/provider/arctic.ts +66 -0
- package/src/provider/code.ts +227 -0
- package/src/provider/cognito.ts +74 -0
- package/src/provider/discord.ts +45 -0
- package/src/provider/facebook.ts +84 -0
- package/src/provider/github.ts +45 -0
- package/src/provider/google.ts +85 -0
- package/src/provider/index.ts +3 -0
- package/src/provider/jumpcloud.ts +45 -0
- package/src/provider/keycloak.ts +75 -0
- package/src/provider/linkedin.ts +12 -0
- package/src/provider/m2m.ts +56 -0
- package/src/provider/microsoft.ts +100 -0
- package/src/provider/oauth2.ts +297 -0
- package/src/provider/oidc.ts +179 -0
- package/src/provider/passkey.ts +655 -0
- package/src/provider/password.ts +672 -0
- package/src/provider/provider.ts +33 -0
- package/src/provider/slack.ts +67 -0
- package/src/provider/spotify.ts +45 -0
- package/src/provider/twitch.ts +45 -0
- package/src/provider/x.ts +46 -0
- package/src/provider/yahoo.ts +45 -0
- package/src/random.ts +24 -0
- package/src/storage/aws.ts +59 -0
- package/src/storage/cloudflare.ts +77 -0
- package/src/storage/dynamo.ts +193 -0
- package/src/storage/memory.ts +135 -0
- package/src/storage/storage.ts +46 -0
- package/src/subject.ts +130 -0
- package/src/ui/base.tsx +118 -0
- package/src/ui/code.tsx +215 -0
- package/src/ui/form.tsx +40 -0
- package/src/ui/icon.tsx +95 -0
- package/src/ui/passkey.tsx +321 -0
- package/src/ui/password.tsx +405 -0
- package/src/ui/select.tsx +221 -0
- package/src/ui/theme.ts +319 -0
- package/src/ui/ui.css +252 -0
- package/src/util.ts +58 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Use this to connect authentication providers that support OAuth 2.0.
|
|
3
|
+
*
|
|
4
|
+
* ```ts {5-12}
|
|
5
|
+
* import { Oauth2Provider } from "@openauthjs/openauth/provider/oauth2"
|
|
6
|
+
*
|
|
7
|
+
* export default issuer({
|
|
8
|
+
* providers: {
|
|
9
|
+
* oauth2: Oauth2Provider({
|
|
10
|
+
* clientID: "1234567890",
|
|
11
|
+
* clientSecret: "0987654321",
|
|
12
|
+
* endpoint: {
|
|
13
|
+
* authorization: "https://auth.myserver.com/authorize",
|
|
14
|
+
* token: "https://auth.myserver.com/token"
|
|
15
|
+
* }
|
|
16
|
+
* })
|
|
17
|
+
* }
|
|
18
|
+
* })
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
*
|
|
22
|
+
* @packageDocumentation
|
|
23
|
+
*/
|
|
24
|
+
import { Provider } from "./provider.js";
|
|
25
|
+
export interface Oauth2Config {
|
|
26
|
+
/**
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
type?: string;
|
|
30
|
+
/**
|
|
31
|
+
* The client ID.
|
|
32
|
+
*
|
|
33
|
+
* This is just a string to identify your app.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* {
|
|
38
|
+
* clientID: "my-client"
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
clientID: string;
|
|
43
|
+
/**
|
|
44
|
+
* The client secret.
|
|
45
|
+
*
|
|
46
|
+
* This is a private key that's used to authenticate your app. It should be kept secret.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* {
|
|
51
|
+
* clientSecret: "0987654321"
|
|
52
|
+
* }
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
clientSecret: string;
|
|
56
|
+
/**
|
|
57
|
+
* The URLs of the authorization and token endpoints.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* {
|
|
62
|
+
* endpoint: {
|
|
63
|
+
* authorization: "https://auth.myserver.com/authorize",
|
|
64
|
+
* token: "https://auth.myserver.com/token",
|
|
65
|
+
* jwks: "https://auth.myserver.com/auth/keys"
|
|
66
|
+
* }
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
endpoint: {
|
|
71
|
+
/**
|
|
72
|
+
* The URL of the authorization endpoint.
|
|
73
|
+
*/
|
|
74
|
+
authorization: string;
|
|
75
|
+
/**
|
|
76
|
+
* The URL of the token endpoint.
|
|
77
|
+
*/
|
|
78
|
+
token: string;
|
|
79
|
+
/**
|
|
80
|
+
* The URL of the JWKS endpoint.
|
|
81
|
+
*/
|
|
82
|
+
jwks?: string;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* A list of OAuth scopes that you want to request.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* {
|
|
90
|
+
* scopes: ["email", "profile"]
|
|
91
|
+
* }
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
scopes: string[];
|
|
95
|
+
/**
|
|
96
|
+
* Whether to use PKCE (Proof Key for Code Exchange) for the authorization code flow.
|
|
97
|
+
* Some providers like x.com require this.
|
|
98
|
+
* @default false
|
|
99
|
+
*/
|
|
100
|
+
pkce?: boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Any additional parameters that you want to pass to the authorization endpoint.
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* {
|
|
106
|
+
* query: {
|
|
107
|
+
* access_type: "offline",
|
|
108
|
+
* prompt: "consent"
|
|
109
|
+
* }
|
|
110
|
+
* }
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
query?: Record<string, string>;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* @internal
|
|
117
|
+
*/
|
|
118
|
+
export type Oauth2WrappedConfig = Omit<Oauth2Config, "endpoint" | "name">;
|
|
119
|
+
/**
|
|
120
|
+
* @internal
|
|
121
|
+
*/
|
|
122
|
+
export interface Oauth2Token {
|
|
123
|
+
access: string;
|
|
124
|
+
refresh: string;
|
|
125
|
+
expiry: number;
|
|
126
|
+
id?: Record<string, any>;
|
|
127
|
+
raw: Record<string, any>;
|
|
128
|
+
}
|
|
129
|
+
export declare function Oauth2Provider(config: Oauth2Config): Provider<{
|
|
130
|
+
tokenset: Oauth2Token;
|
|
131
|
+
clientID: string;
|
|
132
|
+
}>;
|
|
133
|
+
//# sourceMappingURL=oauth2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth2.d.ts","sourceRoot":"","sources":["../../../src/provider/oauth2.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAMH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;;;;;;;;;;OAWG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB;;;;;;;;;;;OAWG;IACH,YAAY,EAAE,MAAM,CAAA;IACpB;;;;;;;;;;;;;OAaG;IACH,QAAQ,EAAE;QACR;;WAEG;QACH,aAAa,EAAE,MAAM,CAAA;QACrB;;WAEG;QACH,KAAK,EAAE,MAAM,CAAA;QACb;;WAEG;QACH,IAAI,CAAC,EAAE,MAAM,CAAA;KACd,CAAA;IACD;;;;;;;;;OASG;IACH,MAAM,EAAE,MAAM,EAAE,CAAA;IAChB;;;;OAIG;IACH,IAAI,CAAC,EAAE,OAAO,CAAA;IACd;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC/B;AAED;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,IAAI,CAAC,YAAY,EAAE,UAAU,GAAG,MAAM,CAAC,CAAA;AAEzE;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;IACd,EAAE,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACxB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CACzB;AAQD,wBAAgB,cAAc,CAC5B,MAAM,EAAE,YAAY,GACnB,QAAQ,CAAC;IAAE,QAAQ,EAAE,WAAW,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAuJvD"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Use this to connect authentication providers that support OIDC.
|
|
3
|
+
*
|
|
4
|
+
* ```ts {5-8}
|
|
5
|
+
* import { OidcProvider } from "@openauthjs/openauth/provider/oidc"
|
|
6
|
+
*
|
|
7
|
+
* export default issuer({
|
|
8
|
+
* providers: {
|
|
9
|
+
* oauth2: OidcProvider({
|
|
10
|
+
* clientId: "1234567890",
|
|
11
|
+
* issuer: "https://auth.myserver.com"
|
|
12
|
+
* })
|
|
13
|
+
* }
|
|
14
|
+
* })
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
*
|
|
18
|
+
* @packageDocumentation
|
|
19
|
+
*/
|
|
20
|
+
import { Provider } from "./provider.js";
|
|
21
|
+
import { JWTPayload } from "hono/utils/jwt/types";
|
|
22
|
+
export interface OidcConfig {
|
|
23
|
+
/**
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
type?: string;
|
|
27
|
+
/**
|
|
28
|
+
* The client ID.
|
|
29
|
+
*
|
|
30
|
+
* This is just a string to identify your app.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* {
|
|
35
|
+
* clientID: "my-client"
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
clientID: string;
|
|
40
|
+
/**
|
|
41
|
+
* The URL of your authorization server.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* {
|
|
46
|
+
* issuer: "https://auth.myserver.com"
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
issuer: string;
|
|
51
|
+
/**
|
|
52
|
+
* A list of OIDC scopes that you want to request.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* {
|
|
57
|
+
* scopes: ["openid", "profile", "email"]
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
scopes?: string[];
|
|
62
|
+
/**
|
|
63
|
+
* Any additional parameters that you want to pass to the authorization endpoint.
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* {
|
|
67
|
+
* query: {
|
|
68
|
+
* prompt: "consent"
|
|
69
|
+
* }
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
query?: Record<string, string>;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* @internal
|
|
77
|
+
*/
|
|
78
|
+
export type OidcWrappedConfig = Omit<OidcConfig, "issuer" | "name">;
|
|
79
|
+
/**
|
|
80
|
+
* @internal
|
|
81
|
+
*/
|
|
82
|
+
export interface IdTokenResponse {
|
|
83
|
+
idToken: string;
|
|
84
|
+
claims: Record<string, any>;
|
|
85
|
+
raw: Record<string, any>;
|
|
86
|
+
}
|
|
87
|
+
export declare function OidcProvider(config: OidcConfig): Provider<{
|
|
88
|
+
id: JWTPayload;
|
|
89
|
+
clientID: string;
|
|
90
|
+
}>;
|
|
91
|
+
//# sourceMappingURL=oidc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oidc.d.ts","sourceRoot":"","sources":["../../../src/provider/oidc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAKH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAGjD,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;;;;;;;;;;OAWG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB;;;;;;;;;OASG;IACH,MAAM,EAAE,MAAM,CAAA;IACd;;;;;;;;;OASG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB;;;;;;;;;;OAUG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC/B;AAED;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,UAAU,EAAE,QAAQ,GAAG,MAAM,CAAC,CAAA;AAQnE;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC3B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CACzB;AAED,wBAAgB,YAAY,CAC1B,MAAM,EAAE,UAAU,GACjB,QAAQ,CAAC;IAAE,EAAE,EAAE,UAAU,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CA2EhD"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configures a provider that supports passkey (WebAuthn) authentication.
|
|
3
|
+
*
|
|
4
|
+
* ```ts
|
|
5
|
+
* import { PasskeyProvider } from "@openauthjs/openauth/provider/passkey"
|
|
6
|
+
*
|
|
7
|
+
* export default issuer({
|
|
8
|
+
* providers: {
|
|
9
|
+
* passkey: PasskeyProvider({
|
|
10
|
+
* rpName: "My Application",
|
|
11
|
+
* rpID: "example.com", // optional - can also be passed in as a query parameter (see the UI)
|
|
12
|
+
* origin: "https://example.com", // optional - can also be passed in as a query parameter (see the UI)
|
|
13
|
+
* userCanRegisterPasskey: async (userId, req) => { // optional
|
|
14
|
+
* // Check if the user is allowed to register a passkey
|
|
15
|
+
* return true
|
|
16
|
+
* }
|
|
17
|
+
* })
|
|
18
|
+
* },
|
|
19
|
+
* // ...
|
|
20
|
+
* })
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* PasskeyProvider implements WebAuthn (Web Authentication) to enable passwordless
|
|
24
|
+
* authentication using biometrics, mobile devices, or security keys. It handles
|
|
25
|
+
* the complete flow for registering new passkeys and authenticating with them.
|
|
26
|
+
*
|
|
27
|
+
* The provider requires configuration of:
|
|
28
|
+
* - Relying Party information (rpName, rpID)
|
|
29
|
+
* - Origin validation
|
|
30
|
+
* - UI handlers for authorization and registration
|
|
31
|
+
*
|
|
32
|
+
* It automatically manages:
|
|
33
|
+
* - Challenge generation
|
|
34
|
+
* - Credential storage
|
|
35
|
+
* - Registration verification
|
|
36
|
+
* - Authentication verification
|
|
37
|
+
*
|
|
38
|
+
* This implementation is powered by [@simplewebauthn/server](https://simplewebauthn.dev),
|
|
39
|
+
* which provides the core WebAuthn functionality for passkey authentication.
|
|
40
|
+
*
|
|
41
|
+
* @packageDocumentation
|
|
42
|
+
*/
|
|
43
|
+
import type { AuthenticatorTransportFuture, CredentialDeviceType, Base64URLString, AuthenticatorSelectionCriteria } from "@simplewebauthn/server";
|
|
44
|
+
import type { Provider } from "./provider.js";
|
|
45
|
+
/**
|
|
46
|
+
* User model for passkey authentication.
|
|
47
|
+
* Contains the core user data needed for WebAuthn operations.
|
|
48
|
+
*/
|
|
49
|
+
export type UserModel = {
|
|
50
|
+
id: string;
|
|
51
|
+
username: string;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Original PasskeyModel structure for in-memory use.
|
|
55
|
+
* Represents a registered credential with public key as Uint8Array.
|
|
56
|
+
*/
|
|
57
|
+
export type PasskeyModel = {
|
|
58
|
+
id: string;
|
|
59
|
+
publicKey: Uint8Array;
|
|
60
|
+
userId: string;
|
|
61
|
+
webauthnUserID: string;
|
|
62
|
+
counter: number;
|
|
63
|
+
deviceType: CredentialDeviceType;
|
|
64
|
+
backedUp: boolean;
|
|
65
|
+
transports?: AuthenticatorTransportFuture[];
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* PasskeyModel version for KV storage with publicKey as string.
|
|
69
|
+
* Used for storing credentials in a key-value store.
|
|
70
|
+
*/
|
|
71
|
+
export type PasskeyModelStored = Omit<PasskeyModel, "publicKey"> & {
|
|
72
|
+
publicKey: string;
|
|
73
|
+
};
|
|
74
|
+
declare const DEFAULT_COPY: {
|
|
75
|
+
error_user_not_allowed: string;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Configuration for the PasskeyProvider.
|
|
79
|
+
* Defines how the passkey authentication flow should behave.
|
|
80
|
+
*/
|
|
81
|
+
export interface PasskeyProviderConfig {
|
|
82
|
+
/**
|
|
83
|
+
* Custom authorization handler that generates the UI for authorization.
|
|
84
|
+
*/
|
|
85
|
+
authorize: (req: Request) => Promise<Response>;
|
|
86
|
+
/**
|
|
87
|
+
* Custom registration handler that generates the UI for registration.
|
|
88
|
+
*/
|
|
89
|
+
register: (req: Request) => Promise<Response>;
|
|
90
|
+
/**
|
|
91
|
+
* The human-readable name of the relying party (your application).
|
|
92
|
+
*/
|
|
93
|
+
rpName: string;
|
|
94
|
+
/**
|
|
95
|
+
* The ID of the relying party, typically the domain name without protocol.
|
|
96
|
+
*/
|
|
97
|
+
rpID?: string;
|
|
98
|
+
/**
|
|
99
|
+
* The origin URL(s) that are allowed to initiate WebAuthn ceremonies.
|
|
100
|
+
*/
|
|
101
|
+
origin?: string | string[];
|
|
102
|
+
/**
|
|
103
|
+
* Optional function to check if a user is allowed to register a passkey.
|
|
104
|
+
*/
|
|
105
|
+
userCanRegisterPasskey?: (userId: string, req: Request) => Promise<boolean>;
|
|
106
|
+
/**
|
|
107
|
+
* Optional WebAuthn authenticator selection criteria.
|
|
108
|
+
*/
|
|
109
|
+
authenticatorSelection?: AuthenticatorSelectionCriteria;
|
|
110
|
+
/**
|
|
111
|
+
* Optional attestation type.
|
|
112
|
+
*/
|
|
113
|
+
attestationType?: "none" | "direct" | "enterprise";
|
|
114
|
+
/**
|
|
115
|
+
* Optional timeout for challenges in milliseconds.
|
|
116
|
+
*/
|
|
117
|
+
timeout?: number;
|
|
118
|
+
/**
|
|
119
|
+
* Custom copy texts for error messages and UI elements.
|
|
120
|
+
*/
|
|
121
|
+
copy?: Partial<typeof DEFAULT_COPY>;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Creates a passkey (WebAuthn) authentication provider.
|
|
125
|
+
*
|
|
126
|
+
* This provider enables passwordless authentication using biometrics, hardware security
|
|
127
|
+
* keys, or platform authenticators. It implements the Web Authentication (WebAuthn) standard.
|
|
128
|
+
*
|
|
129
|
+
* It handles:
|
|
130
|
+
* - Passkey registration (creating new credentials)
|
|
131
|
+
* - Authentication with existing passkeys
|
|
132
|
+
* - Secure storage of credentials
|
|
133
|
+
* - Challenge verification
|
|
134
|
+
*
|
|
135
|
+
* @param config Configuration options for the passkey provider
|
|
136
|
+
* @returns A Provider instance configured for passkey authentication
|
|
137
|
+
*/
|
|
138
|
+
export declare function PasskeyProvider(config: PasskeyProviderConfig): Provider<{
|
|
139
|
+
userId: string;
|
|
140
|
+
credentialId?: Base64URLString;
|
|
141
|
+
}>;
|
|
142
|
+
export {};
|
|
143
|
+
//# sourceMappingURL=passkey.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"passkey.d.ts","sourceRoot":"","sources":["../../../src/provider/passkey.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAEH,OAAO,KAAK,EACV,4BAA4B,EAC5B,oBAAoB,EACpB,eAAe,EACf,8BAA8B,EAM/B,MAAM,wBAAwB,CAAA;AAQ/B,OAAO,KAAK,EAAE,QAAQ,EAAkC,MAAM,eAAe,CAAA;AAyD7E;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,EAAE,EAAE,MAAM,CAAA;IACV,QAAQ,EAAE,MAAM,CAAA;CAEjB,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,EAAE,EAAE,MAAM,CAAA;IACV,SAAS,EAAE,UAAU,CAAA;IACrB,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,EAAE,MAAM,CAAA;IACtB,OAAO,EAAE,MAAM,CAAA;IACf,UAAU,EAAE,oBAAoB,CAAA;IAChC,QAAQ,EAAE,OAAO,CAAA;IACjB,UAAU,CAAC,EAAE,4BAA4B,EAAE,CAAA;CAC5C,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,IAAI,CAAC,YAAY,EAAE,WAAW,CAAC,GAAG;IACjE,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAqBD,QAAA,MAAM,YAAY;;CAGjB,CAAA;AAED;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,SAAS,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;IAE9C;;OAEG;IACH,QAAQ,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;IAE7C;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IAEd;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAE1B;;OAEG;IACH,sBAAsB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IAE3E;;OAEG;IACH,sBAAsB,CAAC,EAAE,8BAA8B,CAAA;IAEvD;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,YAAY,CAAA;IAElD;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC,OAAO,YAAY,CAAC,CAAA;CACpC;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,qBAAqB,GAC5B,QAAQ,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,eAAe,CAAA;CAAE,CAAC,CAsZ9D"}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { Provider } from "./provider.js";
|
|
2
|
+
import { v1 } from "@standard-schema/spec";
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export interface PasswordHasher<T> {
|
|
7
|
+
hash(password: string): Promise<T>;
|
|
8
|
+
verify(password: string, compare: T): Promise<boolean>;
|
|
9
|
+
}
|
|
10
|
+
export interface PasswordConfig {
|
|
11
|
+
/**
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
length?: number;
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
hasher?: PasswordHasher<any>;
|
|
19
|
+
/**
|
|
20
|
+
* The request handler to generate the UI for the login screen.
|
|
21
|
+
*
|
|
22
|
+
* Takes the standard [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
|
|
23
|
+
* and optionally [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData)
|
|
24
|
+
* ojects.
|
|
25
|
+
*
|
|
26
|
+
* In case of an error, this is called again with the `error`.
|
|
27
|
+
*
|
|
28
|
+
* Expects the [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) object
|
|
29
|
+
* in return.
|
|
30
|
+
*/
|
|
31
|
+
login: (req: Request, form?: FormData, error?: PasswordLoginError) => Promise<Response>;
|
|
32
|
+
/**
|
|
33
|
+
* The request handler to generate the UI for the register screen.
|
|
34
|
+
*
|
|
35
|
+
* Takes the standard [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
|
|
36
|
+
* and optionally [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData)
|
|
37
|
+
* ojects.
|
|
38
|
+
*
|
|
39
|
+
* Also passes in the current `state` of the flow and any `error` that occurred.
|
|
40
|
+
*
|
|
41
|
+
* Expects the [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) object
|
|
42
|
+
* in return.
|
|
43
|
+
*/
|
|
44
|
+
register: (req: Request, state: PasswordRegisterState, form?: FormData, error?: PasswordRegisterError) => Promise<Response>;
|
|
45
|
+
/**
|
|
46
|
+
* The request handler to generate the UI for the change password screen.
|
|
47
|
+
*
|
|
48
|
+
* Takes the standard [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
|
|
49
|
+
* and optionally [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData)
|
|
50
|
+
* ojects.
|
|
51
|
+
*
|
|
52
|
+
* Also passes in the current `state` of the flow and any `error` that occurred.
|
|
53
|
+
*
|
|
54
|
+
* Expects the [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) object
|
|
55
|
+
* in return.
|
|
56
|
+
*/
|
|
57
|
+
change: (req: Request, state: PasswordChangeState, form?: FormData, error?: PasswordChangeError) => Promise<Response>;
|
|
58
|
+
/**
|
|
59
|
+
* Callback to send the confirmation pin code to the user.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* {
|
|
64
|
+
* sendCode: async (email, code) => {
|
|
65
|
+
* // Send an email with the code
|
|
66
|
+
* }
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
sendCode: (email: string, code: string) => Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Callback to validate the password on sign up and password reset.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* {
|
|
77
|
+
* validatePassword: (password) => {
|
|
78
|
+
* return password.length < 8 ? "Password must be at least 8 characters" : undefined
|
|
79
|
+
* }
|
|
80
|
+
* }
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
validatePassword?: v1.StandardSchema | ((password: string) => Promise<string | undefined> | string | undefined);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The states that can happen on the register screen.
|
|
87
|
+
*
|
|
88
|
+
* | State | Description |
|
|
89
|
+
* | ----- | ----------- |
|
|
90
|
+
* | `start` | The user is asked to enter their email address and password to start the flow. |
|
|
91
|
+
* | `code` | The user needs to enter the pin code to verify their email. |
|
|
92
|
+
*/
|
|
93
|
+
export type PasswordRegisterState = {
|
|
94
|
+
type: "start";
|
|
95
|
+
} | {
|
|
96
|
+
type: "code";
|
|
97
|
+
code: string;
|
|
98
|
+
email: string;
|
|
99
|
+
password: string;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* The errors that can happen on the register screen.
|
|
103
|
+
*
|
|
104
|
+
* | Error | Description |
|
|
105
|
+
* | ----- | ----------- |
|
|
106
|
+
* | `email_taken` | The email is already taken. |
|
|
107
|
+
* | `invalid_email` | The email is invalid. |
|
|
108
|
+
* | `invalid_code` | The code is invalid. |
|
|
109
|
+
* | `invalid_password` | The password is invalid. |
|
|
110
|
+
* | `password_mismatch` | The passwords do not match. |
|
|
111
|
+
*/
|
|
112
|
+
export type PasswordRegisterError = {
|
|
113
|
+
type: "invalid_code";
|
|
114
|
+
} | {
|
|
115
|
+
type: "email_taken";
|
|
116
|
+
} | {
|
|
117
|
+
type: "invalid_email";
|
|
118
|
+
} | {
|
|
119
|
+
type: "invalid_password";
|
|
120
|
+
} | {
|
|
121
|
+
type: "password_mismatch";
|
|
122
|
+
} | {
|
|
123
|
+
type: "validation_error";
|
|
124
|
+
message?: string;
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* The state of the password change flow.
|
|
128
|
+
*
|
|
129
|
+
* | State | Description |
|
|
130
|
+
* | ----- | ----------- |
|
|
131
|
+
* | `start` | The user is asked to enter their email address to start the flow. |
|
|
132
|
+
* | `code` | The user needs to enter the pin code to verify their email. |
|
|
133
|
+
* | `update` | The user is asked to enter their new password and confirm it. |
|
|
134
|
+
*/
|
|
135
|
+
export type PasswordChangeState = {
|
|
136
|
+
type: "start";
|
|
137
|
+
redirect: string;
|
|
138
|
+
} | {
|
|
139
|
+
type: "code";
|
|
140
|
+
code: string;
|
|
141
|
+
email: string;
|
|
142
|
+
redirect: string;
|
|
143
|
+
} | {
|
|
144
|
+
type: "update";
|
|
145
|
+
redirect: string;
|
|
146
|
+
email: string;
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* The errors that can happen on the change password screen.
|
|
150
|
+
*
|
|
151
|
+
* | Error | Description |
|
|
152
|
+
* | ----- | ----------- |
|
|
153
|
+
* | `invalid_email` | The email is invalid. |
|
|
154
|
+
* | `invalid_code` | The code is invalid. |
|
|
155
|
+
* | `invalid_password` | The password is invalid. |
|
|
156
|
+
* | `password_mismatch` | The passwords do not match. |
|
|
157
|
+
*/
|
|
158
|
+
export type PasswordChangeError = {
|
|
159
|
+
type: "invalid_email";
|
|
160
|
+
} | {
|
|
161
|
+
type: "invalid_code";
|
|
162
|
+
} | {
|
|
163
|
+
type: "invalid_password";
|
|
164
|
+
} | {
|
|
165
|
+
type: "password_mismatch";
|
|
166
|
+
} | {
|
|
167
|
+
type: "validation_error";
|
|
168
|
+
message: string;
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* The errors that can happen on the login screen.
|
|
172
|
+
*
|
|
173
|
+
* | Error | Description |
|
|
174
|
+
* | ----- | ----------- |
|
|
175
|
+
* | `invalid_email` | The email is invalid. |
|
|
176
|
+
* | `invalid_password` | The password is invalid. |
|
|
177
|
+
*/
|
|
178
|
+
export type PasswordLoginError = {
|
|
179
|
+
type: "invalid_password";
|
|
180
|
+
} | {
|
|
181
|
+
type: "invalid_email";
|
|
182
|
+
};
|
|
183
|
+
export declare function PasswordProvider(config: PasswordConfig): Provider<{
|
|
184
|
+
email: string;
|
|
185
|
+
}>;
|
|
186
|
+
/**
|
|
187
|
+
* @internal
|
|
188
|
+
*/
|
|
189
|
+
export declare function PBKDF2Hasher(opts?: {
|
|
190
|
+
iterations?: number;
|
|
191
|
+
}): PasswordHasher<{
|
|
192
|
+
hash: string;
|
|
193
|
+
salt: string;
|
|
194
|
+
iterations: number;
|
|
195
|
+
}>;
|
|
196
|
+
/**
|
|
197
|
+
* @internal
|
|
198
|
+
*/
|
|
199
|
+
export declare function ScryptHasher(opts?: {
|
|
200
|
+
N?: number;
|
|
201
|
+
r?: number;
|
|
202
|
+
p?: number;
|
|
203
|
+
}): PasswordHasher<{
|
|
204
|
+
hash: string;
|
|
205
|
+
salt: string;
|
|
206
|
+
N: number;
|
|
207
|
+
r: number;
|
|
208
|
+
p: number;
|
|
209
|
+
}>;
|
|
210
|
+
//# sourceMappingURL=password.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"password.d.ts","sourceRoot":"","sources":["../../../src/provider/password.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Context, Hono } from "hono";
|
|
2
|
+
import { StorageAdapter } from "../storage/storage.js";
|
|
3
|
+
export type ProviderRoute = Hono;
|
|
4
|
+
export interface Provider<Properties = any> {
|
|
5
|
+
type: string;
|
|
6
|
+
init: (route: ProviderRoute, options: ProviderOptions<Properties>) => void;
|
|
7
|
+
client?: (input: {
|
|
8
|
+
clientID: string;
|
|
9
|
+
clientSecret: string;
|
|
10
|
+
params: Record<string, string>;
|
|
11
|
+
}) => Promise<Properties>;
|
|
12
|
+
}
|
|
13
|
+
export interface ProviderOptions<Properties> {
|
|
14
|
+
name: string;
|
|
15
|
+
success: (ctx: Context, properties: Properties, opts?: {
|
|
16
|
+
invalidate?: (subject: string) => Promise<void>;
|
|
17
|
+
}) => Promise<Response>;
|
|
18
|
+
forward: (ctx: Context, response: Response) => Response;
|
|
19
|
+
set: <T>(ctx: Context, key: string, maxAge: number, value: T) => Promise<void>;
|
|
20
|
+
get: <T>(ctx: Context, key: string) => Promise<T>;
|
|
21
|
+
unset: (ctx: Context, key: string) => Promise<void>;
|
|
22
|
+
invalidate: (subject: string) => Promise<void>;
|
|
23
|
+
storage: StorageAdapter;
|
|
24
|
+
}
|
|
25
|
+
export declare class ProviderError extends Error {
|
|
26
|
+
}
|
|
27
|
+
export declare class ProviderUnknownError extends ProviderError {
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/provider/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAEtD,MAAM,MAAM,aAAa,GAAG,IAAI,CAAA;AAEhC,MAAM,WAAW,QAAQ,CAAC,UAAU,GAAG,GAAG;IACxC,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,CAAC,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,eAAe,CAAC,UAAU,CAAC,KAAK,IAAI,CAAA;IAC1E,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE;QACf,QAAQ,EAAE,MAAM,CAAA;QAChB,YAAY,EAAE,MAAM,CAAA;QACpB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAC/B,KAAK,OAAO,CAAC,UAAU,CAAC,CAAA;CAC1B;AAED,MAAM,WAAW,eAAe,CAAC,UAAU;IACzC,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,CACP,GAAG,EAAE,OAAO,EACZ,UAAU,EAAE,UAAU,EACtB,IAAI,CAAC,EAAE;QACL,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;KAChD,KACE,OAAO,CAAC,QAAQ,CAAC,CAAA;IACtB,OAAO,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,KAAK,QAAQ,CAAA;IACvD,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAC9E,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,CAAA;IACjD,KAAK,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACnD,UAAU,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAC9C,OAAO,EAAE,cAAc,CAAA;CACxB;AACD,qBAAa,aAAc,SAAQ,KAAK;CAAG;AAC3C,qBAAa,oBAAqB,SAAQ,aAAa;CAAG"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Use this provider to authenticate with Slack.
|
|
3
|
+
*
|
|
4
|
+
* ```ts {5-10}
|
|
5
|
+
* import { SlackProvider } from "@openauthjs/openauth/provider/slack"
|
|
6
|
+
*
|
|
7
|
+
* export default issuer({
|
|
8
|
+
* providers: {
|
|
9
|
+
* slack: SlackProvider({
|
|
10
|
+
* team: "T1234567890",
|
|
11
|
+
* clientID: "1234567890",
|
|
12
|
+
* clientSecret: "0987654321",
|
|
13
|
+
* scopes: ["openid", "email", "profile"]
|
|
14
|
+
* })
|
|
15
|
+
* }
|
|
16
|
+
* })
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @packageDocumentation
|
|
20
|
+
*/
|
|
21
|
+
import { Oauth2WrappedConfig } from "./oauth2.js";
|
|
22
|
+
export interface SlackConfig extends Oauth2WrappedConfig {
|
|
23
|
+
/**
|
|
24
|
+
* The workspace the user is intending to authenticate.
|
|
25
|
+
*
|
|
26
|
+
* If that workspace has been previously authenticated, the user will be signed in directly,
|
|
27
|
+
* bypassing the consent screen.
|
|
28
|
+
*/
|
|
29
|
+
team: string;
|
|
30
|
+
/**
|
|
31
|
+
* The scopes to request from the user.
|
|
32
|
+
*
|
|
33
|
+
* | Scope | Description |
|
|
34
|
+
* |-|-|
|
|
35
|
+
* | `email` | Grants permission to access the user's email address. |
|
|
36
|
+
* | `profile` | Grants permission to access the user's profile information. |
|
|
37
|
+
* | `openid` | Grants permission to use OpenID Connect to verify the user's identity. |
|
|
38
|
+
*/
|
|
39
|
+
scopes: ("email" | "profile" | "openid")[];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Creates a [Slack OAuth2 provider](https://api.slack.com/authentication/sign-in-with-slack).
|
|
43
|
+
*
|
|
44
|
+
* @param {SlackConfig} config - The config for the provider.
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* SlackProvider({
|
|
48
|
+
* team: "T1234567890",
|
|
49
|
+
* clientID: "1234567890",
|
|
50
|
+
* clientSecret: "0987654321",
|
|
51
|
+
* scopes: ["openid", "email", "profile"]
|
|
52
|
+
* })
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare function SlackProvider(config: SlackConfig): import("./provider.js").Provider<{
|
|
56
|
+
tokenset: import("./oauth2.js").Oauth2Token;
|
|
57
|
+
clientID: string;
|
|
58
|
+
}>;
|
|
59
|
+
//# sourceMappingURL=slack.d.ts.map
|