@_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,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Use this provider to authenticate with Discord.
|
|
3
|
+
*
|
|
4
|
+
* ```ts {5-8}
|
|
5
|
+
* import { DiscordProvider } from "@openauthjs/openauth/provider/discord"
|
|
6
|
+
*
|
|
7
|
+
* export default issuer({
|
|
8
|
+
* providers: {
|
|
9
|
+
* discord: DiscordProvider({
|
|
10
|
+
* clientID: "1234567890",
|
|
11
|
+
* clientSecret: "0987654321"
|
|
12
|
+
* })
|
|
13
|
+
* }
|
|
14
|
+
* })
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @packageDocumentation
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { Oauth2Provider, Oauth2WrappedConfig } from "./oauth2.js"
|
|
21
|
+
|
|
22
|
+
export interface DiscordConfig extends Oauth2WrappedConfig {}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Create a Discord OAuth2 provider.
|
|
26
|
+
*
|
|
27
|
+
* @param config - The config for the provider.
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* DiscordProvider({
|
|
31
|
+
* clientID: "1234567890",
|
|
32
|
+
* clientSecret: "0987654321"
|
|
33
|
+
* })
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export function DiscordProvider(config: DiscordConfig) {
|
|
37
|
+
return Oauth2Provider({
|
|
38
|
+
type: "discord",
|
|
39
|
+
...config,
|
|
40
|
+
endpoint: {
|
|
41
|
+
authorization: "https://discord.com/oauth2/authorize",
|
|
42
|
+
token: "https://discord.com/api/oauth2/token",
|
|
43
|
+
},
|
|
44
|
+
})
|
|
45
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Use this provider to authenticate with Facebook. Supports both OAuth2 and OIDC.
|
|
3
|
+
*
|
|
4
|
+
* #### Using OAuth
|
|
5
|
+
*
|
|
6
|
+
* ```ts {5-8}
|
|
7
|
+
* import { FacebookProvider } from "@openauthjs/openauth/provider/facebook"
|
|
8
|
+
*
|
|
9
|
+
* export default issuer({
|
|
10
|
+
* providers: {
|
|
11
|
+
* facebook: FacebookProvider({
|
|
12
|
+
* clientID: "1234567890",
|
|
13
|
+
* clientSecret: "0987654321"
|
|
14
|
+
* })
|
|
15
|
+
* }
|
|
16
|
+
* })
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* #### Using OIDC
|
|
20
|
+
*
|
|
21
|
+
* ```ts {5-7}
|
|
22
|
+
* import { FacebookOidcProvider } from "@openauthjs/openauth/provider/facebook"
|
|
23
|
+
*
|
|
24
|
+
* export default issuer({
|
|
25
|
+
* providers: {
|
|
26
|
+
* facebook: FacebookOidcProvider({
|
|
27
|
+
* clientID: "1234567890"
|
|
28
|
+
* })
|
|
29
|
+
* }
|
|
30
|
+
* })
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @packageDocumentation
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
import { Oauth2Provider, Oauth2WrappedConfig } from "./oauth2.js"
|
|
37
|
+
import { OidcProvider, OidcWrappedConfig } from "./oidc.js"
|
|
38
|
+
|
|
39
|
+
export interface FacebookConfig extends Oauth2WrappedConfig {}
|
|
40
|
+
export interface FacebookOidcConfig extends OidcWrappedConfig {}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Create a Facebook OAuth2 provider.
|
|
44
|
+
*
|
|
45
|
+
* @param config - The config for the provider.
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* FacebookProvider({
|
|
49
|
+
* clientID: "1234567890",
|
|
50
|
+
* clientSecret: "0987654321"
|
|
51
|
+
* })
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export function FacebookProvider(config: FacebookConfig) {
|
|
55
|
+
return Oauth2Provider({
|
|
56
|
+
...config,
|
|
57
|
+
type: "facebook",
|
|
58
|
+
endpoint: {
|
|
59
|
+
authorization: "https://www.facebook.com/v12.0/dialog/oauth",
|
|
60
|
+
token: "https://graph.facebook.com/v12.0/oauth/access_token",
|
|
61
|
+
},
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Create a Facebook OIDC provider.
|
|
67
|
+
*
|
|
68
|
+
* This is useful if you just want to verify the user's email address.
|
|
69
|
+
*
|
|
70
|
+
* @param config - The config for the provider.
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* FacebookOidcProvider({
|
|
74
|
+
* clientID: "1234567890"
|
|
75
|
+
* })
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export function FacebookOidcProvider(config: FacebookOidcConfig) {
|
|
79
|
+
return OidcProvider({
|
|
80
|
+
...config,
|
|
81
|
+
type: "facebook",
|
|
82
|
+
issuer: "https://graph.facebook.com",
|
|
83
|
+
})
|
|
84
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Use this provider to authenticate with Github.
|
|
3
|
+
*
|
|
4
|
+
* ```ts {5-8}
|
|
5
|
+
* import { GithubProvider } from "@openauthjs/openauth/provider/github"
|
|
6
|
+
*
|
|
7
|
+
* export default issuer({
|
|
8
|
+
* providers: {
|
|
9
|
+
* github: GithubProvider({
|
|
10
|
+
* clientID: "1234567890",
|
|
11
|
+
* clientSecret: "0987654321"
|
|
12
|
+
* })
|
|
13
|
+
* }
|
|
14
|
+
* })
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @packageDocumentation
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { Oauth2Provider, Oauth2WrappedConfig } from "./oauth2.js"
|
|
21
|
+
|
|
22
|
+
export interface GithubConfig extends Oauth2WrappedConfig {}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Create a Github OAuth2 provider.
|
|
26
|
+
*
|
|
27
|
+
* @param config - The config for the provider.
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* GithubProvider({
|
|
31
|
+
* clientID: "1234567890",
|
|
32
|
+
* clientSecret: "0987654321"
|
|
33
|
+
* })
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export function GithubProvider(config: GithubConfig) {
|
|
37
|
+
return Oauth2Provider({
|
|
38
|
+
...config,
|
|
39
|
+
type: "github",
|
|
40
|
+
endpoint: {
|
|
41
|
+
authorization: "https://github.com/login/oauth/authorize",
|
|
42
|
+
token: "https://github.com/login/oauth/access_token",
|
|
43
|
+
},
|
|
44
|
+
})
|
|
45
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Use this provider to authenticate with Google. Supports both OAuth2 and OIDC.
|
|
3
|
+
*
|
|
4
|
+
* #### Using OAuth
|
|
5
|
+
*
|
|
6
|
+
* ```ts {5-8}
|
|
7
|
+
* import { GoogleProvider } from "@openauthjs/openauth/provider/google"
|
|
8
|
+
*
|
|
9
|
+
* export default issuer({
|
|
10
|
+
* providers: {
|
|
11
|
+
* google: GoogleProvider({
|
|
12
|
+
* clientID: "1234567890",
|
|
13
|
+
* clientSecret: "0987654321"
|
|
14
|
+
* })
|
|
15
|
+
* }
|
|
16
|
+
* })
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* #### Using OIDC
|
|
20
|
+
*
|
|
21
|
+
* ```ts {5-7}
|
|
22
|
+
* import { GoogleOidcProvider } from "@openauthjs/openauth/provider/google"
|
|
23
|
+
*
|
|
24
|
+
* export default issuer({
|
|
25
|
+
* providers: {
|
|
26
|
+
* google: GoogleOidcProvider({
|
|
27
|
+
* clientID: "1234567890"
|
|
28
|
+
* })
|
|
29
|
+
* }
|
|
30
|
+
* })
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @packageDocumentation
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
import { Oauth2Provider, Oauth2WrappedConfig } from "./oauth2.js"
|
|
37
|
+
import { OidcProvider, OidcWrappedConfig } from "./oidc.js"
|
|
38
|
+
|
|
39
|
+
export interface GoogleConfig extends Oauth2WrappedConfig {}
|
|
40
|
+
export interface GoogleOidcConfig extends OidcWrappedConfig {}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Create a Google OAuth2 provider.
|
|
44
|
+
*
|
|
45
|
+
* @param config - The config for the provider.
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* GoogleProvider({
|
|
49
|
+
* clientID: "1234567890",
|
|
50
|
+
* clientSecret: "0987654321"
|
|
51
|
+
* })
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export function GoogleProvider(config: GoogleConfig) {
|
|
55
|
+
return Oauth2Provider({
|
|
56
|
+
...config,
|
|
57
|
+
type: "google",
|
|
58
|
+
endpoint: {
|
|
59
|
+
authorization: "https://accounts.google.com/o/oauth2/v2/auth",
|
|
60
|
+
token: "https://oauth2.googleapis.com/token",
|
|
61
|
+
jwks: "https://www.googleapis.com/oauth2/v3/certs",
|
|
62
|
+
},
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Create a Google OIDC provider.
|
|
68
|
+
*
|
|
69
|
+
* This is useful if you just want to verify the user's email address.
|
|
70
|
+
*
|
|
71
|
+
* @param config - The config for the provider.
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* GoogleOidcProvider({
|
|
75
|
+
* clientID: "1234567890"
|
|
76
|
+
* })
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export function GoogleOidcProvider(config: GoogleOidcConfig) {
|
|
80
|
+
return OidcProvider({
|
|
81
|
+
...config,
|
|
82
|
+
type: "google",
|
|
83
|
+
issuer: "https://accounts.google.com",
|
|
84
|
+
})
|
|
85
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Use this provider to authenticate with JumpCloud.
|
|
3
|
+
*
|
|
4
|
+
* ```ts {5-8}
|
|
5
|
+
* import { JumpCloudProvider } from "@openauthjs/openauth/provider/jumpcloud"
|
|
6
|
+
*
|
|
7
|
+
* export default issuer({
|
|
8
|
+
* providers: {
|
|
9
|
+
* jumpcloud: JumpCloudProvider({
|
|
10
|
+
* clientID: "1234567890",
|
|
11
|
+
* clientSecret: "0987654321"
|
|
12
|
+
* })
|
|
13
|
+
* }
|
|
14
|
+
* })
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @packageDocumentation
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { Oauth2Provider, Oauth2WrappedConfig } from "./oauth2.js"
|
|
21
|
+
|
|
22
|
+
export interface JumpCloudConfig extends Oauth2WrappedConfig {}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Create a JumpCloud OAuth2 provider.
|
|
26
|
+
*
|
|
27
|
+
* @param config - The config for the provider.
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* JumpCloudProvider({
|
|
31
|
+
* clientID: "1234567890",
|
|
32
|
+
* clientSecret: "0987654321"
|
|
33
|
+
* })
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export function JumpCloudProvider(config: JumpCloudConfig) {
|
|
37
|
+
return Oauth2Provider({
|
|
38
|
+
type: "jumpcloud",
|
|
39
|
+
...config,
|
|
40
|
+
endpoint: {
|
|
41
|
+
authorization: "https://oauth.id.jumpcloud.com/oauth2/auth",
|
|
42
|
+
token: "https://oauth.id.jumpcloud.com/oauth2/token",
|
|
43
|
+
},
|
|
44
|
+
})
|
|
45
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Use this provider to authenticate with a Keycloak server.
|
|
3
|
+
*
|
|
4
|
+
* ```ts {5-10}
|
|
5
|
+
* import { KeycloakProvider } from "@openauthjs/openauth/provider/keycloak"
|
|
6
|
+
*
|
|
7
|
+
* export default issuer({
|
|
8
|
+
* providers: {
|
|
9
|
+
* keycloak: KeycloakProvider({
|
|
10
|
+
* baseUrl: "https://your-keycloak-domain",
|
|
11
|
+
* realm: "your-realm",
|
|
12
|
+
* clientID: "1234567890",
|
|
13
|
+
* clientSecret: "0987654321"
|
|
14
|
+
* })
|
|
15
|
+
* }
|
|
16
|
+
* })
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @packageDocumentation
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { Oauth2Provider, Oauth2WrappedConfig } from "./oauth2.js"
|
|
23
|
+
|
|
24
|
+
export interface KeycloakConfig extends Oauth2WrappedConfig {
|
|
25
|
+
/**
|
|
26
|
+
* The base URL of the Keycloak server.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* {
|
|
31
|
+
* baseUrl: "https://your-keycloak-domain"
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
baseUrl: string
|
|
36
|
+
/**
|
|
37
|
+
* The realm in the Keycloak server to authenticate against.
|
|
38
|
+
*
|
|
39
|
+
* A realm in Keycloak is like a tenant or namespace that manages a set of
|
|
40
|
+
* users, credentials, roles, and groups.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* {
|
|
45
|
+
* realm: "your-realm"
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
realm: string
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Create a Keycloak OAuth2 provider.
|
|
54
|
+
*
|
|
55
|
+
* @param config - The config for the provider.
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* KeycloakProvider({
|
|
59
|
+
* baseUrl: "https://your-keycloak-domain",
|
|
60
|
+
* realm: "your-realm",
|
|
61
|
+
* clientID: "1234567890",
|
|
62
|
+
* clientSecret: "0987654321"
|
|
63
|
+
* })
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export function KeycloakProvider(config: KeycloakConfig) {
|
|
67
|
+
const baseConfig = {
|
|
68
|
+
...config,
|
|
69
|
+
endpoint: {
|
|
70
|
+
authorization: `${config.baseUrl}/realms/${config.realm}/protocol/openid-connect/auth`,
|
|
71
|
+
token: `${config.baseUrl}/realms/${config.realm}/protocol/openid-connect/token`,
|
|
72
|
+
},
|
|
73
|
+
}
|
|
74
|
+
return Oauth2Provider(baseConfig)
|
|
75
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Oauth2Provider, type Oauth2WrappedConfig } from "./oauth2.js"
|
|
2
|
+
|
|
3
|
+
export function LinkedInAdapter(config: Oauth2WrappedConfig) {
|
|
4
|
+
return Oauth2Provider({
|
|
5
|
+
...config,
|
|
6
|
+
type: "linkedin",
|
|
7
|
+
endpoint: {
|
|
8
|
+
authorization: "https://www.linkedin.com/oauth/v2/authorization",
|
|
9
|
+
token: "https://www.linkedin.com/oauth/v2/accessToken",
|
|
10
|
+
},
|
|
11
|
+
})
|
|
12
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Provider } from "./provider.js"
|
|
2
|
+
|
|
3
|
+
export interface M2MProviderConfig {
|
|
4
|
+
/**
|
|
5
|
+
* Callback to verify client credentials.
|
|
6
|
+
* Should return data about the client (e.g., associated User or Org ID).
|
|
7
|
+
* Returning undefined or throwing indicates invalid credentials.
|
|
8
|
+
*/
|
|
9
|
+
verify: (
|
|
10
|
+
clientID: string,
|
|
11
|
+
clientSecret: string,
|
|
12
|
+
params: Record<string, string>,
|
|
13
|
+
) => Promise<
|
|
14
|
+
| {
|
|
15
|
+
id: string
|
|
16
|
+
[key: string]: any
|
|
17
|
+
}
|
|
18
|
+
| undefined
|
|
19
|
+
>
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Creates a provider for Machine-to-Machine (M2M) authentication using the
|
|
24
|
+
* OAuth 2.0 `client_credentials` grant type.
|
|
25
|
+
*
|
|
26
|
+
* This provider does not have a UI and is intended for service-to-service
|
|
27
|
+
* communication where the client can securely store a secret.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* const m2m = M2MProvider({
|
|
32
|
+
* verify: async (clientID, clientSecret) => {
|
|
33
|
+
* const client = await db.clients.findUnique({ where: { clientID } })
|
|
34
|
+
* if (client && client.secret === clientSecret) return client
|
|
35
|
+
* }
|
|
36
|
+
* })
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export function M2MProvider(config: M2MProviderConfig): Provider<{
|
|
40
|
+
id: string
|
|
41
|
+
[key: string]: any
|
|
42
|
+
}> {
|
|
43
|
+
return {
|
|
44
|
+
type: "m2m",
|
|
45
|
+
init() {},
|
|
46
|
+
async client(input) {
|
|
47
|
+
const result = await config.verify(
|
|
48
|
+
input.clientID,
|
|
49
|
+
input.clientSecret,
|
|
50
|
+
input.params,
|
|
51
|
+
)
|
|
52
|
+
if (!result) throw new Error("Invalid client credentials")
|
|
53
|
+
return result
|
|
54
|
+
},
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Use this provider to authenticate with Microsoft. Supports both OAuth2 and OIDC.
|
|
3
|
+
*
|
|
4
|
+
* #### Using OAuth
|
|
5
|
+
*
|
|
6
|
+
* ```ts {5-9}
|
|
7
|
+
* import { MicrosoftProvider } from "@openauthjs/openauth/provider/microsoft"
|
|
8
|
+
*
|
|
9
|
+
* export default issuer({
|
|
10
|
+
* providers: {
|
|
11
|
+
* microsoft: MicrosoftProvider({
|
|
12
|
+
* tenant: "1234567890",
|
|
13
|
+
* clientID: "1234567890",
|
|
14
|
+
* clientSecret: "0987654321"
|
|
15
|
+
* })
|
|
16
|
+
* }
|
|
17
|
+
* })
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* #### Using OIDC
|
|
21
|
+
*
|
|
22
|
+
* ```ts {5-7}
|
|
23
|
+
* import { MicrosoftOidcProvider } from "@openauthjs/openauth/provider/microsoft"
|
|
24
|
+
*
|
|
25
|
+
* export default issuer({
|
|
26
|
+
* providers: {
|
|
27
|
+
* microsoft: MicrosoftOidcProvider({
|
|
28
|
+
* clientID: "1234567890"
|
|
29
|
+
* })
|
|
30
|
+
* }
|
|
31
|
+
* })
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @packageDocumentation
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
import { Oauth2Provider, Oauth2WrappedConfig } from "./oauth2.js"
|
|
38
|
+
import { OidcProvider, OidcWrappedConfig } from "./oidc.js"
|
|
39
|
+
|
|
40
|
+
export interface MicrosoftConfig extends Oauth2WrappedConfig {
|
|
41
|
+
/**
|
|
42
|
+
* The tenant ID of the Microsoft account.
|
|
43
|
+
*
|
|
44
|
+
* This is usually the same as the client ID.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* {
|
|
49
|
+
* tenant: "1234567890"
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
tenant: string
|
|
54
|
+
}
|
|
55
|
+
export interface MicrosoftOidcConfig extends OidcWrappedConfig {}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Create a Microsoft OAuth2 provider.
|
|
59
|
+
*
|
|
60
|
+
* @param config - The config for the provider.
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* MicrosoftProvider({
|
|
64
|
+
* tenant: "1234567890",
|
|
65
|
+
* clientID: "1234567890",
|
|
66
|
+
* clientSecret: "0987654321"
|
|
67
|
+
* })
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export function MicrosoftProvider(config: MicrosoftConfig) {
|
|
71
|
+
return Oauth2Provider({
|
|
72
|
+
...config,
|
|
73
|
+
type: "microsoft",
|
|
74
|
+
endpoint: {
|
|
75
|
+
authorization: `https://login.microsoftonline.com/${config?.tenant}/oauth2/v2.0/authorize`,
|
|
76
|
+
token: `https://login.microsoftonline.com/${config?.tenant}/oauth2/v2.0/token`,
|
|
77
|
+
},
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Create a Microsoft OIDC provider.
|
|
83
|
+
*
|
|
84
|
+
* This is useful if you just want to verify the user's email address.
|
|
85
|
+
*
|
|
86
|
+
* @param config - The config for the provider.
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* MicrosoftOidcProvider({
|
|
90
|
+
* clientID: "1234567890"
|
|
91
|
+
* })
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export function MicrosoftOidcProvider(config: MicrosoftOidcConfig) {
|
|
95
|
+
return OidcProvider({
|
|
96
|
+
...config,
|
|
97
|
+
type: "microsoft",
|
|
98
|
+
issuer: "https://graph.microsoft.com/oidc/userinfo",
|
|
99
|
+
})
|
|
100
|
+
}
|