@draftlab/auth 0.15.0 → 0.16.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/allow.js +26 -0
- package/dist/esm/client.js +254 -0
- package/dist/esm/core.js +597 -0
- package/dist/esm/css.d.js +0 -0
- package/dist/esm/error.js +88 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/keys.js +126 -0
- package/dist/esm/mutex.js +53 -0
- package/dist/esm/pkce.js +87 -0
- package/dist/esm/provider/apple.js +15 -0
- package/dist/esm/provider/code.js +62 -0
- package/dist/esm/provider/discord.js +15 -0
- package/dist/esm/provider/facebook.js +15 -0
- package/dist/esm/provider/github.js +15 -0
- package/dist/esm/provider/gitlab.js +15 -0
- package/dist/esm/provider/google.js +16 -0
- package/dist/esm/provider/linkedin.js +15 -0
- package/dist/esm/provider/magiclink.js +83 -0
- package/dist/esm/provider/microsoft.js +15 -0
- package/dist/esm/provider/oauth2.js +130 -0
- package/dist/esm/provider/password.js +331 -0
- package/dist/esm/provider/provider.js +18 -0
- package/dist/esm/provider/reddit.js +15 -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/vercel.js +17 -0
- package/dist/esm/random.js +40 -0
- package/dist/esm/revocation.js +27 -0
- package/dist/esm/storage/memory.js +110 -0
- package/dist/esm/storage/storage.js +56 -0
- package/dist/esm/storage/turso.js +93 -0
- package/dist/esm/storage/unstorage.js +78 -0
- package/dist/esm/subject.js +7 -0
- package/dist/esm/themes/theme.js +115 -0
- package/dist/esm/toolkit/client.js +119 -0
- package/dist/esm/toolkit/index.js +25 -0
- package/dist/esm/toolkit/providers/facebook.js +11 -0
- package/dist/esm/toolkit/providers/github.js +11 -0
- package/dist/esm/toolkit/providers/google.js +11 -0
- package/dist/esm/toolkit/providers/strategy.js +0 -0
- package/dist/esm/toolkit/storage.js +81 -0
- package/dist/esm/toolkit/utils.js +18 -0
- package/dist/esm/types.js +0 -0
- package/dist/esm/ui/base.js +478 -0
- package/dist/esm/ui/code.js +186 -0
- package/dist/esm/ui/form.js +46 -0
- package/dist/esm/ui/icon.js +242 -0
- package/dist/esm/ui/magiclink.js +158 -0
- package/dist/esm/ui/password.js +435 -0
- package/dist/esm/ui/select.js +102 -0
- package/dist/esm/util.js +59 -0
- package/dist/{allow.d.mts → types/allow.d.ts} +9 -11
- package/dist/types/allow.d.ts.map +1 -0
- package/dist/types/client.d.ts +462 -0
- package/dist/types/client.d.ts.map +1 -0
- package/dist/types/core.d.ts +113 -0
- package/dist/types/core.d.ts.map +1 -0
- package/dist/{error.d.mts → types/error.d.ts} +95 -97
- package/dist/types/error.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/{keys.d.mts → types/keys.d.ts} +20 -24
- package/dist/types/keys.d.ts.map +1 -0
- package/dist/types/mutex.d.ts +42 -0
- package/dist/types/mutex.d.ts.map +1 -0
- package/dist/{pkce.d.mts → types/pkce.d.ts} +10 -11
- package/dist/types/pkce.d.ts.map +1 -0
- package/dist/types/provider/apple.d.ts +197 -0
- package/dist/types/provider/apple.d.ts.map +1 -0
- package/dist/types/provider/code.d.ts +288 -0
- package/dist/types/provider/code.d.ts.map +1 -0
- package/dist/types/provider/discord.d.ts +206 -0
- package/dist/types/provider/discord.d.ts.map +1 -0
- package/dist/types/provider/facebook.d.ts +200 -0
- package/dist/types/provider/facebook.d.ts.map +1 -0
- package/dist/types/provider/github.d.ts +220 -0
- package/dist/types/provider/github.d.ts.map +1 -0
- package/dist/types/provider/gitlab.d.ts +180 -0
- package/dist/types/provider/gitlab.d.ts.map +1 -0
- package/dist/types/provider/google.d.ts +158 -0
- package/dist/types/provider/google.d.ts.map +1 -0
- package/dist/types/provider/linkedin.d.ts +190 -0
- package/dist/types/provider/linkedin.d.ts.map +1 -0
- package/dist/types/provider/magiclink.d.ts +141 -0
- package/dist/types/provider/magiclink.d.ts.map +1 -0
- package/dist/types/provider/microsoft.d.ts +247 -0
- package/dist/types/provider/microsoft.d.ts.map +1 -0
- package/dist/types/provider/oauth2.d.ts +229 -0
- package/dist/types/provider/oauth2.d.ts.map +1 -0
- package/dist/types/provider/password.d.ts +408 -0
- package/dist/types/provider/password.d.ts.map +1 -0
- package/dist/types/provider/provider.d.ts +226 -0
- package/dist/types/provider/provider.d.ts.map +1 -0
- package/dist/types/provider/reddit.d.ts +159 -0
- package/dist/types/provider/reddit.d.ts.map +1 -0
- package/dist/types/provider/slack.d.ts +171 -0
- package/dist/types/provider/slack.d.ts.map +1 -0
- package/dist/types/provider/spotify.d.ts +168 -0
- package/dist/types/provider/spotify.d.ts.map +1 -0
- package/dist/types/provider/twitch.d.ts +163 -0
- package/dist/types/provider/twitch.d.ts.map +1 -0
- package/dist/types/provider/vercel.d.ts +294 -0
- package/dist/types/provider/vercel.d.ts.map +1 -0
- package/dist/{random.d.mts → types/random.d.ts} +4 -6
- package/dist/types/random.d.ts.map +1 -0
- package/dist/types/revocation.d.ts +76 -0
- package/dist/types/revocation.d.ts.map +1 -0
- package/dist/{storage/memory.d.mts → types/storage/memory.d.ts} +17 -21
- package/dist/types/storage/memory.d.ts.map +1 -0
- package/dist/types/storage/storage.d.ts +177 -0
- package/dist/types/storage/storage.d.ts.map +1 -0
- package/dist/{storage/turso.d.mts → types/storage/turso.d.ts} +4 -8
- package/dist/types/storage/turso.d.ts.map +1 -0
- package/dist/{storage/unstorage.d.mts → types/storage/unstorage.d.ts} +12 -11
- package/dist/types/storage/unstorage.d.ts.map +1 -0
- package/dist/types/subject.d.ts +115 -0
- package/dist/types/subject.d.ts.map +1 -0
- package/dist/types/themes/theme.d.ts +207 -0
- package/dist/types/themes/theme.d.ts.map +1 -0
- package/dist/types/toolkit/client.d.ts +235 -0
- package/dist/types/toolkit/client.d.ts.map +1 -0
- package/dist/types/toolkit/index.d.ts +45 -0
- package/dist/types/toolkit/index.d.ts.map +1 -0
- package/dist/types/toolkit/providers/facebook.d.ts +8 -0
- package/dist/types/toolkit/providers/facebook.d.ts.map +1 -0
- package/dist/types/toolkit/providers/github.d.ts +8 -0
- package/dist/types/toolkit/providers/github.d.ts.map +1 -0
- package/dist/types/toolkit/providers/google.d.ts +8 -0
- package/dist/types/toolkit/providers/google.d.ts.map +1 -0
- package/dist/types/toolkit/providers/strategy.d.ts +38 -0
- package/dist/types/toolkit/providers/strategy.d.ts.map +1 -0
- package/dist/{toolkit/storage.d.mts → types/toolkit/storage.d.ts} +37 -39
- package/dist/types/toolkit/storage.d.ts.map +1 -0
- package/dist/{toolkit/utils.d.mts → types/toolkit/utils.d.ts} +2 -4
- package/dist/types/toolkit/utils.d.ts.map +1 -0
- package/dist/types/types.d.ts +92 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/ui/base.d.ts +18 -0
- package/dist/types/ui/base.d.ts.map +1 -0
- package/dist/types/ui/code.d.ts +43 -0
- package/dist/types/ui/code.d.ts.map +1 -0
- package/dist/types/ui/form.d.ts +24 -0
- package/dist/types/ui/form.d.ts.map +1 -0
- package/dist/types/ui/icon.d.ts +60 -0
- package/dist/types/ui/icon.d.ts.map +1 -0
- package/dist/types/ui/magiclink.d.ts +41 -0
- package/dist/types/ui/magiclink.d.ts.map +1 -0
- package/dist/types/ui/password.d.ts +43 -0
- package/dist/types/ui/password.d.ts.map +1 -0
- package/dist/types/ui/select.d.ts +33 -0
- package/dist/types/ui/select.d.ts.map +1 -0
- package/dist/{util.d.mts → types/util.d.ts} +11 -13
- package/dist/types/util.d.ts.map +1 -0
- package/package.json +10 -16
- package/dist/adapters/node.d.mts +0 -18
- package/dist/adapters/node.mjs +0 -69
- package/dist/allow.mjs +0 -63
- package/dist/client.d.mts +0 -456
- package/dist/client.mjs +0 -283
- package/dist/core.d.mts +0 -110
- package/dist/core.mjs +0 -595
- package/dist/error.mjs +0 -237
- package/dist/index.d.mts +0 -2
- package/dist/index.mjs +0 -3
- package/dist/keys.mjs +0 -146
- package/dist/mutex.d.mts +0 -44
- package/dist/mutex.mjs +0 -110
- package/dist/pkce.mjs +0 -157
- package/dist/provider/apple.d.mts +0 -111
- package/dist/provider/apple.mjs +0 -164
- package/dist/provider/code.d.mts +0 -228
- package/dist/provider/code.mjs +0 -246
- package/dist/provider/discord.d.mts +0 -146
- package/dist/provider/discord.mjs +0 -156
- package/dist/provider/facebook.d.mts +0 -142
- package/dist/provider/facebook.mjs +0 -150
- package/dist/provider/github.d.mts +0 -140
- package/dist/provider/github.mjs +0 -169
- package/dist/provider/gitlab.d.mts +0 -106
- package/dist/provider/gitlab.mjs +0 -147
- package/dist/provider/google.d.mts +0 -112
- package/dist/provider/google.mjs +0 -109
- package/dist/provider/linkedin.d.mts +0 -132
- package/dist/provider/linkedin.mjs +0 -142
- package/dist/provider/magiclink.d.mts +0 -89
- package/dist/provider/magiclink.mjs +0 -143
- package/dist/provider/microsoft.d.mts +0 -178
- package/dist/provider/microsoft.mjs +0 -177
- package/dist/provider/oauth2.d.mts +0 -176
- package/dist/provider/oauth2.mjs +0 -222
- package/dist/provider/passkey.d.mts +0 -104
- package/dist/provider/passkey.mjs +0 -320
- package/dist/provider/password.d.mts +0 -412
- package/dist/provider/password.mjs +0 -363
- package/dist/provider/provider.d.mts +0 -227
- package/dist/provider/provider.mjs +0 -44
- package/dist/provider/reddit.d.mts +0 -107
- package/dist/provider/reddit.mjs +0 -127
- package/dist/provider/slack.d.mts +0 -114
- package/dist/provider/slack.mjs +0 -138
- package/dist/provider/spotify.d.mts +0 -113
- package/dist/provider/spotify.mjs +0 -135
- package/dist/provider/totp.d.mts +0 -112
- package/dist/provider/totp.mjs +0 -191
- package/dist/provider/twitch.d.mts +0 -108
- package/dist/provider/twitch.mjs +0 -131
- package/dist/provider/vercel.d.mts +0 -177
- package/dist/provider/vercel.mjs +0 -230
- package/dist/random.mjs +0 -86
- package/dist/revocation.d.mts +0 -55
- package/dist/revocation.mjs +0 -63
- package/dist/router/context.d.mts +0 -21
- package/dist/router/context.mjs +0 -193
- package/dist/router/cookies.d.mts +0 -8
- package/dist/router/cookies.mjs +0 -13
- package/dist/router/index.d.mts +0 -21
- package/dist/router/index.mjs +0 -107
- package/dist/router/matcher.d.mts +0 -15
- package/dist/router/matcher.mjs +0 -76
- package/dist/router/middleware/cors.d.mts +0 -15
- package/dist/router/middleware/cors.mjs +0 -114
- package/dist/router/safe-request.d.mts +0 -52
- package/dist/router/safe-request.mjs +0 -160
- package/dist/router/types.d.mts +0 -67
- package/dist/router/types.mjs +0 -1
- package/dist/router/variables.d.mts +0 -12
- package/dist/router/variables.mjs +0 -20
- package/dist/storage/memory.mjs +0 -125
- package/dist/storage/storage.d.mts +0 -179
- package/dist/storage/storage.mjs +0 -104
- package/dist/storage/turso.mjs +0 -117
- package/dist/storage/unstorage.mjs +0 -103
- package/dist/subject.d.mts +0 -62
- package/dist/subject.mjs +0 -36
- package/dist/themes/theme.d.mts +0 -209
- package/dist/themes/theme.mjs +0 -120
- package/dist/toolkit/client.d.mts +0 -169
- package/dist/toolkit/client.mjs +0 -209
- package/dist/toolkit/index.d.mts +0 -9
- package/dist/toolkit/index.mjs +0 -9
- package/dist/toolkit/providers/facebook.d.mts +0 -12
- package/dist/toolkit/providers/facebook.mjs +0 -16
- package/dist/toolkit/providers/github.d.mts +0 -12
- package/dist/toolkit/providers/github.mjs +0 -16
- package/dist/toolkit/providers/google.d.mts +0 -12
- package/dist/toolkit/providers/google.mjs +0 -20
- package/dist/toolkit/providers/strategy.d.mts +0 -40
- package/dist/toolkit/providers/strategy.mjs +0 -1
- package/dist/toolkit/storage.mjs +0 -157
- package/dist/toolkit/utils.mjs +0 -30
- package/dist/types.d.mts +0 -94
- package/dist/types.mjs +0 -1
- package/dist/ui/base.d.mts +0 -30
- package/dist/ui/base.mjs +0 -407
- package/dist/ui/code.d.mts +0 -43
- package/dist/ui/code.mjs +0 -173
- package/dist/ui/form.d.mts +0 -32
- package/dist/ui/form.mjs +0 -49
- package/dist/ui/icon.d.mts +0 -58
- package/dist/ui/icon.mjs +0 -247
- package/dist/ui/magiclink.d.mts +0 -41
- package/dist/ui/magiclink.mjs +0 -152
- package/dist/ui/passkey.d.mts +0 -27
- package/dist/ui/passkey.mjs +0 -323
- package/dist/ui/password.d.mts +0 -42
- package/dist/ui/password.mjs +0 -402
- package/dist/ui/select.d.mts +0 -34
- package/dist/ui/select.mjs +0 -98
- package/dist/ui/totp.d.mts +0 -34
- package/dist/ui/totp.mjs +0 -270
- package/dist/util.mjs +0 -128
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import { Oauth2Provider } from "./oauth2.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/provider/facebook.ts
|
|
4
|
-
/**
|
|
5
|
-
* Facebook OAuth 2.0 authentication provider for Draft Auth.
|
|
6
|
-
* Provides access tokens for calling Facebook Graph API on behalf of users.
|
|
7
|
-
*
|
|
8
|
-
* ## Quick Setup
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* import { FacebookProvider } from "@draftlab/auth/provider/facebook"
|
|
12
|
-
*
|
|
13
|
-
* export default issuer({
|
|
14
|
-
* basePath: "/auth", // Important for callback URL
|
|
15
|
-
* providers: {
|
|
16
|
-
* facebook: FacebookProvider({
|
|
17
|
-
* clientID: process.env.FACEBOOK_APP_ID,
|
|
18
|
-
* clientSecret: process.env.FACEBOOK_APP_SECRET,
|
|
19
|
-
* scopes: ["email", "public_profile", "user_friends"]
|
|
20
|
-
* })
|
|
21
|
-
* }
|
|
22
|
-
* })
|
|
23
|
-
* ```
|
|
24
|
-
*
|
|
25
|
-
* **Callback URL Pattern**: `{baseURL}{basePath}/{provider}/callback`
|
|
26
|
-
* - Development: `http://localhost:3000/auth/facebook/callback`
|
|
27
|
-
* - Production: `https://yourapp.com/auth/facebook/callback`
|
|
28
|
-
*
|
|
29
|
-
* Register this URL in your Facebook App Dashboard.
|
|
30
|
-
*
|
|
31
|
-
* ## Configuration Options
|
|
32
|
-
*
|
|
33
|
-
* - Access tokens for Facebook Graph API calls
|
|
34
|
-
* - Support for various Facebook permissions
|
|
35
|
-
* - Access to user data, posts, friends, etc.
|
|
36
|
-
*
|
|
37
|
-
* ## Common Facebook Permissions
|
|
38
|
-
*
|
|
39
|
-
* - `public_profile` - Basic profile information (name, picture, etc.)
|
|
40
|
-
* - `email` - User's email address
|
|
41
|
-
* - `user_friends` - List of user's friends who also use your app
|
|
42
|
-
* - `user_posts` - User's posts on their timeline
|
|
43
|
-
* - `user_photos` - User's photos and albums
|
|
44
|
-
* - `pages_read_engagement` - Read engagement data for Pages
|
|
45
|
-
*
|
|
46
|
-
* ## User Data Access
|
|
47
|
-
*
|
|
48
|
-
* ```ts
|
|
49
|
-
* success: async (ctx, value) => {
|
|
50
|
-
* if (value.provider === "facebook") {
|
|
51
|
-
* const accessToken = value.tokenset.access
|
|
52
|
-
*
|
|
53
|
-
* // Fetch user profile from Graph API
|
|
54
|
-
* const profileResponse = await fetch(
|
|
55
|
-
* `https://graph.facebook.com/me?fields=id,name,email,picture&access_token=${accessToken}`
|
|
56
|
-
* )
|
|
57
|
-
* const profile = await profileResponse.json()
|
|
58
|
-
*
|
|
59
|
-
* // User info: `${profile.name} (${profile.email})`
|
|
60
|
-
* // Facebook ID: profile.id
|
|
61
|
-
* }
|
|
62
|
-
* }
|
|
63
|
-
* ```
|
|
64
|
-
*
|
|
65
|
-
* @packageDocumentation
|
|
66
|
-
*/
|
|
67
|
-
/**
|
|
68
|
-
* Creates a Facebook OAuth 2.0 authentication provider.
|
|
69
|
-
* Use this when you need access tokens to call Facebook Graph API on behalf of the user.
|
|
70
|
-
*
|
|
71
|
-
* @param config - Facebook OAuth 2.0 configuration
|
|
72
|
-
* @returns OAuth 2.0 provider configured for Facebook
|
|
73
|
-
*
|
|
74
|
-
* @example
|
|
75
|
-
* ```ts
|
|
76
|
-
* // Basic Facebook authentication
|
|
77
|
-
* const basicFacebook = FacebookProvider({
|
|
78
|
-
* clientID: process.env.FACEBOOK_APP_ID,
|
|
79
|
-
* clientSecret: process.env.FACEBOOK_APP_SECRET,
|
|
80
|
-
* scopes: ["email", "public_profile"]
|
|
81
|
-
* })
|
|
82
|
-
*
|
|
83
|
-
* // Facebook with extended permissions
|
|
84
|
-
* const extendedFacebook = FacebookProvider({
|
|
85
|
-
* clientID: process.env.FACEBOOK_APP_ID,
|
|
86
|
-
* clientSecret: process.env.FACEBOOK_APP_SECRET,
|
|
87
|
-
* scopes: [
|
|
88
|
-
* "email",
|
|
89
|
-
* "public_profile",
|
|
90
|
-
* "user_friends",
|
|
91
|
-
* "user_posts",
|
|
92
|
-
* "user_photos"
|
|
93
|
-
* ],
|
|
94
|
-
* query: {
|
|
95
|
-
* display: "popup",
|
|
96
|
-
* auth_type: "rerequest" // Force permission approval
|
|
97
|
-
* }
|
|
98
|
-
* })
|
|
99
|
-
*
|
|
100
|
-
* // Using the access token for Graph API calls
|
|
101
|
-
* export default issuer({
|
|
102
|
-
* providers: { facebook: extendedFacebook },
|
|
103
|
-
* success: async (ctx, value) => {
|
|
104
|
-
* if (value.provider === "facebook") {
|
|
105
|
-
* const token = value.tokenset.access
|
|
106
|
-
*
|
|
107
|
-
* // Get user profile with custom fields
|
|
108
|
-
* const profileRes = await fetch(
|
|
109
|
-
* `https://graph.facebook.com/me?fields=id,name,email,picture.width(200),friends&access_token=${token}`
|
|
110
|
-
* )
|
|
111
|
-
* const profile = await profileRes.json()
|
|
112
|
-
*
|
|
113
|
-
* // Get user's posts (if permission granted)
|
|
114
|
-
* const postsRes = await fetch(
|
|
115
|
-
* `https://graph.facebook.com/me/posts?access_token=${token}`
|
|
116
|
-
* )
|
|
117
|
-
* const posts = await postsRes.json()
|
|
118
|
-
*
|
|
119
|
-
* return ctx.subject("user", {
|
|
120
|
-
* facebookId: profile.id,
|
|
121
|
-
* name: profile.name,
|
|
122
|
-
* email: profile.email,
|
|
123
|
-
* picture: profile.picture?.data?.url,
|
|
124
|
-
* friendsCount: profile.friends?.summary?.total_count || 0,
|
|
125
|
-
* postsCount: posts.data?.length || 0
|
|
126
|
-
* })
|
|
127
|
-
* }
|
|
128
|
-
* }
|
|
129
|
-
* })
|
|
130
|
-
* ```
|
|
131
|
-
*
|
|
132
|
-
* **Callback URL Pattern**: `{baseURL}{basePath}/{provider}/callback`
|
|
133
|
-
* - Development: `http://localhost:3000/auth/facebook/callback`
|
|
134
|
-
* - Production: `https://yourapp.com/auth/facebook/callback`
|
|
135
|
-
*
|
|
136
|
-
* Register this URL in your Facebook App Dashboard.
|
|
137
|
-
*/
|
|
138
|
-
const FacebookProvider = (config) => {
|
|
139
|
-
return Oauth2Provider({
|
|
140
|
-
...config,
|
|
141
|
-
type: "facebook",
|
|
142
|
-
endpoint: {
|
|
143
|
-
authorization: "https://www.facebook.com/v18.0/dialog/oauth",
|
|
144
|
-
token: "https://graph.facebook.com/v18.0/oauth/access_token"
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
//#endregion
|
|
150
|
-
export { FacebookProvider };
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { Provider } from "./provider.mjs";
|
|
2
|
-
import { Oauth2UserData, Oauth2WrappedConfig } from "./oauth2.mjs";
|
|
3
|
-
|
|
4
|
-
//#region src/provider/github.d.ts
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Configuration options for GitHub OAuth 2.0 provider.
|
|
8
|
-
* Extends the base OAuth 2.0 configuration with GitHub-specific documentation.
|
|
9
|
-
*/
|
|
10
|
-
interface GithubConfig extends Oauth2WrappedConfig {
|
|
11
|
-
/**
|
|
12
|
-
* GitHub OAuth App client ID or GitHub App client ID.
|
|
13
|
-
* Found in your GitHub App settings or OAuth App settings.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```ts
|
|
17
|
-
* {
|
|
18
|
-
* clientID: "Iv1.a629723000043722" // OAuth App
|
|
19
|
-
* // or
|
|
20
|
-
* clientID: "Iv23liAG5t7VwMkUsKTi" // GitHub App
|
|
21
|
-
* }
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
readonly clientID: string;
|
|
25
|
-
/**
|
|
26
|
-
* GitHub OAuth App client secret or GitHub App client secret.
|
|
27
|
-
* Keep this secure and never expose it to client-side code.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```ts
|
|
31
|
-
* {
|
|
32
|
-
* clientSecret: process.env.GITHUB_CLIENT_SECRET
|
|
33
|
-
* }
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
readonly clientSecret: string;
|
|
37
|
-
/**
|
|
38
|
-
* GitHub OAuth scopes to request access for.
|
|
39
|
-
* Determines what data and actions your app can access.
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* ```ts
|
|
43
|
-
* {
|
|
44
|
-
* scopes: [
|
|
45
|
-
* "user:email", // Access user email addresses
|
|
46
|
-
* "read:user", // Read user profile info
|
|
47
|
-
* "public_repo", // Access public repositories
|
|
48
|
-
* "read:org" // Read organization membership
|
|
49
|
-
* ]
|
|
50
|
-
* }
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
|
-
readonly scopes: string[];
|
|
54
|
-
/**
|
|
55
|
-
* Additional query parameters for GitHub OAuth authorization.
|
|
56
|
-
* Useful for GitHub-specific options like restricting to organizations.
|
|
57
|
-
*
|
|
58
|
-
* @example
|
|
59
|
-
* ```ts
|
|
60
|
-
* {
|
|
61
|
-
* query: {
|
|
62
|
-
* allow_signup: "false", // Disable new account creation
|
|
63
|
-
* login: "suggested-username" // Pre-fill username field
|
|
64
|
-
* }
|
|
65
|
-
* }
|
|
66
|
-
* ```
|
|
67
|
-
*/
|
|
68
|
-
readonly query?: Record<string, string>;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Creates a GitHub OAuth 2.0 authentication provider.
|
|
72
|
-
* Supports both GitHub OAuth Apps and GitHub Apps for user authentication.
|
|
73
|
-
*
|
|
74
|
-
* @param config - GitHub OAuth 2.0 configuration
|
|
75
|
-
* @returns OAuth 2.0 provider configured for GitHub
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* ```ts
|
|
79
|
-
* // Basic GitHub authentication
|
|
80
|
-
* const basicGithub = GithubProvider({
|
|
81
|
-
* clientID: process.env.GITHUB_CLIENT_ID,
|
|
82
|
-
* clientSecret: process.env.GITHUB_CLIENT_SECRET
|
|
83
|
-
* })
|
|
84
|
-
*
|
|
85
|
-
* // GitHub with specific scopes
|
|
86
|
-
* const githubWithScopes = GithubProvider({
|
|
87
|
-
* clientID: process.env.GITHUB_CLIENT_ID,
|
|
88
|
-
* clientSecret: process.env.GITHUB_CLIENT_SECRET,
|
|
89
|
-
* scopes: [
|
|
90
|
-
* "user:email",
|
|
91
|
-
* "read:user",
|
|
92
|
-
* "public_repo",
|
|
93
|
-
* "read:org"
|
|
94
|
-
* ]
|
|
95
|
-
* })
|
|
96
|
-
*
|
|
97
|
-
* // GitHub with custom authorization options
|
|
98
|
-
* const restrictedGithub = GithubProvider({
|
|
99
|
-
* clientID: process.env.GITHUB_CLIENT_ID,
|
|
100
|
-
* clientSecret: process.env.GITHUB_CLIENT_SECRET,
|
|
101
|
-
* scopes: ["user:email", "read:user"],
|
|
102
|
-
* query: {
|
|
103
|
-
* allow_signup: "false" // Don't allow new GitHub account creation
|
|
104
|
-
* }
|
|
105
|
-
* })
|
|
106
|
-
*
|
|
107
|
-
* // Using the access token to fetch data
|
|
108
|
-
* export default issuer({
|
|
109
|
-
* providers: { github: githubWithScopes },
|
|
110
|
-
* success: async (ctx, value) => {
|
|
111
|
-
* if (value.provider === "github") {
|
|
112
|
-
* const token = value.tokenset.access
|
|
113
|
-
*
|
|
114
|
-
* // Get user profile
|
|
115
|
-
* const userRes = await fetch('https://api.github.com/user', {
|
|
116
|
-
* headers: { Authorization: `Bearer ${token}` }
|
|
117
|
-
* })
|
|
118
|
-
* const user = await userRes.json()
|
|
119
|
-
*
|
|
120
|
-
* // Get user repositories (if repo scope granted)
|
|
121
|
-
* const reposRes = await fetch('https://api.github.com/user/repos', {
|
|
122
|
-
* headers: { Authorization: `Bearer ${token}` }
|
|
123
|
-
* })
|
|
124
|
-
* const repos = await reposRes.json()
|
|
125
|
-
*
|
|
126
|
-
* return ctx.subject("user", {
|
|
127
|
-
* githubId: user.id,
|
|
128
|
-
* username: user.login,
|
|
129
|
-
* email: user.email,
|
|
130
|
-
* name: user.name,
|
|
131
|
-
* repoCount: repos.length
|
|
132
|
-
* })
|
|
133
|
-
* }
|
|
134
|
-
* }
|
|
135
|
-
* })
|
|
136
|
-
* ```
|
|
137
|
-
*/
|
|
138
|
-
declare const GithubProvider: (config: GithubConfig) => Provider<Oauth2UserData>;
|
|
139
|
-
//#endregion
|
|
140
|
-
export { GithubConfig, GithubProvider };
|
package/dist/provider/github.mjs
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import { Oauth2Provider } from "./oauth2.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/provider/github.ts
|
|
4
|
-
/**
|
|
5
|
-
* GitHub authentication provider for Draft Auth.
|
|
6
|
-
* Implements OAuth 2.0 flow for authenticating users with their GitHub accounts.
|
|
7
|
-
*
|
|
8
|
-
* ## Quick Setup
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* import { GithubProvider } from "@draftlab/auth/provider/github"
|
|
12
|
-
*
|
|
13
|
-
* export default issuer({
|
|
14
|
-
* basePath: "/auth", // Important for callback URL
|
|
15
|
-
* providers: {
|
|
16
|
-
* github: GithubProvider({
|
|
17
|
-
* clientID: process.env.GITHUB_CLIENT_ID,
|
|
18
|
-
* clientSecret: process.env.GITHUB_CLIENT_SECRET,
|
|
19
|
-
* scopes: ["user:email", "read:user"]
|
|
20
|
-
* })
|
|
21
|
-
* }
|
|
22
|
-
* })
|
|
23
|
-
* ```
|
|
24
|
-
*
|
|
25
|
-
* **Callback URL Pattern**: `{baseURL}{basePath}/{provider}/callback`
|
|
26
|
-
* - Development: `http://localhost:3000/auth/github/callback`
|
|
27
|
-
* - Production: `https://yourapp.com/auth/github/callback`
|
|
28
|
-
*
|
|
29
|
-
* Register this URL in your GitHub App/OAuth App settings.
|
|
30
|
-
*
|
|
31
|
-
* ## GitHub App vs OAuth App
|
|
32
|
-
*
|
|
33
|
-
* This provider works with both GitHub OAuth Apps and GitHub Apps:
|
|
34
|
-
*
|
|
35
|
-
* ### OAuth App (Recommended for user authentication)
|
|
36
|
-
* ```ts
|
|
37
|
-
* GithubProvider({
|
|
38
|
-
* clientID: "your-oauth-app-client-id",
|
|
39
|
-
* clientSecret: "your-oauth-app-client-secret",
|
|
40
|
-
* scopes: ["user:email", "read:user"]
|
|
41
|
-
* })
|
|
42
|
-
* ```
|
|
43
|
-
*
|
|
44
|
-
* ### GitHub App (For organization-level integrations)
|
|
45
|
-
* ```ts
|
|
46
|
-
* GithubProvider({
|
|
47
|
-
* clientID: "your-github-app-client-id",
|
|
48
|
-
* clientSecret: "your-github-app-client-secret",
|
|
49
|
-
* scopes: ["user:email", "read:user", "repo"]
|
|
50
|
-
* })
|
|
51
|
-
* ```
|
|
52
|
-
*
|
|
53
|
-
* ## Common Scopes
|
|
54
|
-
*
|
|
55
|
-
* - `user:email` - Access user's email addresses
|
|
56
|
-
* - `read:user` - Read user profile information
|
|
57
|
-
* - `repo` - Access public and private repositories
|
|
58
|
-
* - `public_repo` - Access public repositories only
|
|
59
|
-
* - `read:org` - Read organization membership
|
|
60
|
-
* - `gist` - Create and update gists
|
|
61
|
-
*
|
|
62
|
-
* ## User Data Access
|
|
63
|
-
*
|
|
64
|
-
* ```ts
|
|
65
|
-
* success: async (ctx, value) => {
|
|
66
|
-
* if (value.provider === "github") {
|
|
67
|
-
* const accessToken = value.tokenset.access
|
|
68
|
-
*
|
|
69
|
-
* // Fetch user information
|
|
70
|
-
* const userResponse = await fetch('https://api.github.com/user', {
|
|
71
|
-
* headers: { Authorization: `Bearer ${accessToken}` }
|
|
72
|
-
* })
|
|
73
|
-
* const user = await userResponse.json()
|
|
74
|
-
*
|
|
75
|
-
* // Fetch user emails (requires user:email scope)
|
|
76
|
-
* const emailsResponse = await fetch('https://api.github.com/user/emails', {
|
|
77
|
-
* headers: { Authorization: `Bearer ${accessToken}` }
|
|
78
|
-
* })
|
|
79
|
-
* const emails = await emailsResponse.json()
|
|
80
|
-
*
|
|
81
|
-
* // User info: `${user.login} (${user.name})`
|
|
82
|
-
* // Primary email: emails.find(e => e.primary)?.email
|
|
83
|
-
* }
|
|
84
|
-
* }
|
|
85
|
-
* ```
|
|
86
|
-
*
|
|
87
|
-
* @packageDocumentation
|
|
88
|
-
*/
|
|
89
|
-
/**
|
|
90
|
-
* Creates a GitHub OAuth 2.0 authentication provider.
|
|
91
|
-
* Supports both GitHub OAuth Apps and GitHub Apps for user authentication.
|
|
92
|
-
*
|
|
93
|
-
* @param config - GitHub OAuth 2.0 configuration
|
|
94
|
-
* @returns OAuth 2.0 provider configured for GitHub
|
|
95
|
-
*
|
|
96
|
-
* @example
|
|
97
|
-
* ```ts
|
|
98
|
-
* // Basic GitHub authentication
|
|
99
|
-
* const basicGithub = GithubProvider({
|
|
100
|
-
* clientID: process.env.GITHUB_CLIENT_ID,
|
|
101
|
-
* clientSecret: process.env.GITHUB_CLIENT_SECRET
|
|
102
|
-
* })
|
|
103
|
-
*
|
|
104
|
-
* // GitHub with specific scopes
|
|
105
|
-
* const githubWithScopes = GithubProvider({
|
|
106
|
-
* clientID: process.env.GITHUB_CLIENT_ID,
|
|
107
|
-
* clientSecret: process.env.GITHUB_CLIENT_SECRET,
|
|
108
|
-
* scopes: [
|
|
109
|
-
* "user:email",
|
|
110
|
-
* "read:user",
|
|
111
|
-
* "public_repo",
|
|
112
|
-
* "read:org"
|
|
113
|
-
* ]
|
|
114
|
-
* })
|
|
115
|
-
*
|
|
116
|
-
* // GitHub with custom authorization options
|
|
117
|
-
* const restrictedGithub = GithubProvider({
|
|
118
|
-
* clientID: process.env.GITHUB_CLIENT_ID,
|
|
119
|
-
* clientSecret: process.env.GITHUB_CLIENT_SECRET,
|
|
120
|
-
* scopes: ["user:email", "read:user"],
|
|
121
|
-
* query: {
|
|
122
|
-
* allow_signup: "false" // Don't allow new GitHub account creation
|
|
123
|
-
* }
|
|
124
|
-
* })
|
|
125
|
-
*
|
|
126
|
-
* // Using the access token to fetch data
|
|
127
|
-
* export default issuer({
|
|
128
|
-
* providers: { github: githubWithScopes },
|
|
129
|
-
* success: async (ctx, value) => {
|
|
130
|
-
* if (value.provider === "github") {
|
|
131
|
-
* const token = value.tokenset.access
|
|
132
|
-
*
|
|
133
|
-
* // Get user profile
|
|
134
|
-
* const userRes = await fetch('https://api.github.com/user', {
|
|
135
|
-
* headers: { Authorization: `Bearer ${token}` }
|
|
136
|
-
* })
|
|
137
|
-
* const user = await userRes.json()
|
|
138
|
-
*
|
|
139
|
-
* // Get user repositories (if repo scope granted)
|
|
140
|
-
* const reposRes = await fetch('https://api.github.com/user/repos', {
|
|
141
|
-
* headers: { Authorization: `Bearer ${token}` }
|
|
142
|
-
* })
|
|
143
|
-
* const repos = await reposRes.json()
|
|
144
|
-
*
|
|
145
|
-
* return ctx.subject("user", {
|
|
146
|
-
* githubId: user.id,
|
|
147
|
-
* username: user.login,
|
|
148
|
-
* email: user.email,
|
|
149
|
-
* name: user.name,
|
|
150
|
-
* repoCount: repos.length
|
|
151
|
-
* })
|
|
152
|
-
* }
|
|
153
|
-
* }
|
|
154
|
-
* })
|
|
155
|
-
* ```
|
|
156
|
-
*/
|
|
157
|
-
const GithubProvider = (config) => {
|
|
158
|
-
return Oauth2Provider({
|
|
159
|
-
...config,
|
|
160
|
-
type: "github",
|
|
161
|
-
endpoint: {
|
|
162
|
-
authorization: "https://github.com/login/oauth/authorize",
|
|
163
|
-
token: "https://github.com/login/oauth/access_token"
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
//#endregion
|
|
169
|
-
export { GithubProvider };
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { Provider } from "./provider.mjs";
|
|
2
|
-
import { Oauth2UserData, Oauth2WrappedConfig } from "./oauth2.mjs";
|
|
3
|
-
|
|
4
|
-
//#region src/provider/gitlab.d.ts
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Configuration options for GitLab OAuth 2.0 provider.
|
|
8
|
-
* Extends the base OAuth 2.0 configuration with GitLab-specific documentation.
|
|
9
|
-
*/
|
|
10
|
-
interface GitlabConfig extends Oauth2WrappedConfig {
|
|
11
|
-
/**
|
|
12
|
-
* GitLab application client ID.
|
|
13
|
-
* Get this from your GitLab application settings.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```ts
|
|
17
|
-
* {
|
|
18
|
-
* clientID: "abcdef123456"
|
|
19
|
-
* }
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
readonly clientID: string;
|
|
23
|
-
/**
|
|
24
|
-
* GitLab application client secret.
|
|
25
|
-
* Keep this secure and never expose it to client-side code.
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* ```ts
|
|
29
|
-
* {
|
|
30
|
-
* clientSecret: process.env.GITLAB_CLIENT_SECRET
|
|
31
|
-
* }
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
readonly clientSecret: string;
|
|
35
|
-
/**
|
|
36
|
-
* GitLab OAuth scopes to request access for.
|
|
37
|
-
* Determines what data and actions your app can access.
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```ts
|
|
41
|
-
* {
|
|
42
|
-
* scopes: [
|
|
43
|
-
* "read_user", // Access user profile
|
|
44
|
-
* "read_api", // Read-access to API
|
|
45
|
-
* "read_repository" // Access repositories
|
|
46
|
-
* ]
|
|
47
|
-
* }
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
readonly scopes: string[];
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Creates a GitLab OAuth 2.0 authentication provider.
|
|
54
|
-
* Allows users to authenticate using their GitLab accounts (gitlab.com or self-hosted).
|
|
55
|
-
*
|
|
56
|
-
* @param config - GitLab OAuth 2.0 configuration
|
|
57
|
-
* @returns OAuth 2.0 provider configured for GitLab
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```ts
|
|
61
|
-
* // Basic GitLab.com authentication
|
|
62
|
-
* const basicGitlab = GitlabProvider({
|
|
63
|
-
* clientID: process.env.GITLAB_CLIENT_ID,
|
|
64
|
-
* clientSecret: process.env.GITLAB_CLIENT_SECRET
|
|
65
|
-
* })
|
|
66
|
-
*
|
|
67
|
-
* // GitLab with read access
|
|
68
|
-
* const gitlabWithRead = GitlabProvider({
|
|
69
|
-
* clientID: process.env.GITLAB_CLIENT_ID,
|
|
70
|
-
* clientSecret: process.env.GITLAB_CLIENT_SECRET,
|
|
71
|
-
* scopes: ["read_user", "read_api"]
|
|
72
|
-
* })
|
|
73
|
-
*
|
|
74
|
-
* // Using the access token to fetch user data
|
|
75
|
-
* export default issuer({
|
|
76
|
-
* providers: { gitlab: gitlabWithRead },
|
|
77
|
-
* success: async (ctx, value) => {
|
|
78
|
-
* if (value.provider === "gitlab") {
|
|
79
|
-
* const token = value.tokenset.access
|
|
80
|
-
*
|
|
81
|
-
* const userRes = await fetch('https://gitlab.com/api/v4/user', {
|
|
82
|
-
* headers: { Authorization: `Bearer ${token}` }
|
|
83
|
-
* })
|
|
84
|
-
* const user = await userRes.json()
|
|
85
|
-
*
|
|
86
|
-
* return ctx.subject("user", {
|
|
87
|
-
* gitlabId: user.id,
|
|
88
|
-
* username: user.username,
|
|
89
|
-
* email: user.email,
|
|
90
|
-
* name: user.name,
|
|
91
|
-
* avatar: user.avatar_url
|
|
92
|
-
* })
|
|
93
|
-
* }
|
|
94
|
-
* }
|
|
95
|
-
* })
|
|
96
|
-
* ```
|
|
97
|
-
*
|
|
98
|
-
* **Callback URL Pattern**: `{baseURL}{basePath}/{provider}/callback`
|
|
99
|
-
* - Development: `http://localhost:3000/auth/gitlab/callback`
|
|
100
|
-
* - Production: `https://yourapp.com/auth/gitlab/callback`
|
|
101
|
-
*
|
|
102
|
-
* Register this URL in your GitLab Application settings.
|
|
103
|
-
*/
|
|
104
|
-
declare const GitlabProvider: (config: GitlabConfig) => Provider<Oauth2UserData>;
|
|
105
|
-
//#endregion
|
|
106
|
-
export { GitlabConfig, GitlabProvider };
|
package/dist/provider/gitlab.mjs
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { Oauth2Provider } from "./oauth2.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/provider/gitlab.ts
|
|
4
|
-
/**
|
|
5
|
-
* GitLab authentication provider for Draft Auth.
|
|
6
|
-
* Implements OAuth 2.0 flow for authenticating users with their GitLab accounts.
|
|
7
|
-
*
|
|
8
|
-
* ## Quick Setup
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* import { GitlabProvider } from "@draftlab/auth/provider/gitlab"
|
|
12
|
-
*
|
|
13
|
-
* export default issuer({
|
|
14
|
-
* basePath: "/auth", // Important for callback URL
|
|
15
|
-
* providers: {
|
|
16
|
-
* gitlab: GitlabProvider({
|
|
17
|
-
* clientID: process.env.GITLAB_CLIENT_ID,
|
|
18
|
-
* clientSecret: process.env.GITLAB_CLIENT_SECRET,
|
|
19
|
-
* scopes: ["read_user", "read_api"]
|
|
20
|
-
* })
|
|
21
|
-
* }
|
|
22
|
-
* })
|
|
23
|
-
* ```
|
|
24
|
-
*
|
|
25
|
-
* **Callback URL Pattern**: `{baseURL}{basePath}/{provider}/callback`
|
|
26
|
-
* - Development: `http://localhost:3000/auth/gitlab/callback`
|
|
27
|
-
* - Production: `https://yourapp.com/auth/gitlab/callback`
|
|
28
|
-
*
|
|
29
|
-
* Register this URL in your GitLab Application settings.
|
|
30
|
-
*
|
|
31
|
-
* ## Common Scopes
|
|
32
|
-
*
|
|
33
|
-
* - `read_user` - Access user profile
|
|
34
|
-
* - `read_api` - Read-access to the API
|
|
35
|
-
* - `read_repository` - Access to project repositories
|
|
36
|
-
* - `write_repository` - Write access to repositories
|
|
37
|
-
* - `api` - Full API access
|
|
38
|
-
* - `read_user_email` - Access user email
|
|
39
|
-
*
|
|
40
|
-
* ## Self-Hosted GitLab
|
|
41
|
-
*
|
|
42
|
-
* For self-hosted GitLab instances, you can override the endpoint URLs:
|
|
43
|
-
*
|
|
44
|
-
* ```ts
|
|
45
|
-
* const selfHostedGitlab = Oauth2Provider({
|
|
46
|
-
* clientID: process.env.GITLAB_CLIENT_ID,
|
|
47
|
-
* clientSecret: process.env.GITLAB_CLIENT_SECRET,
|
|
48
|
-
* scopes: ["read_user"],
|
|
49
|
-
* type: "gitlab",
|
|
50
|
-
* endpoint: {
|
|
51
|
-
* authorization: "https://your-gitlab.com/oauth/authorize",
|
|
52
|
-
* token: "https://your-gitlab.com/oauth/token"
|
|
53
|
-
* }
|
|
54
|
-
* })
|
|
55
|
-
* ```
|
|
56
|
-
*
|
|
57
|
-
* **Callback URL Pattern**: `{baseURL}{basePath}/{provider}/callback`
|
|
58
|
-
* - Development: `http://localhost:3000/auth/gitlab/callback`
|
|
59
|
-
* - Production: `https://yourapp.com/auth/gitlab/callback`
|
|
60
|
-
*
|
|
61
|
-
* Register this URL in your GitLab Application settings.
|
|
62
|
-
*
|
|
63
|
-
* ## User Data Access
|
|
64
|
-
*
|
|
65
|
-
* ```ts
|
|
66
|
-
* success: async (ctx, value) => {
|
|
67
|
-
* if (value.provider === "gitlab") {
|
|
68
|
-
* const accessToken = value.tokenset.access
|
|
69
|
-
*
|
|
70
|
-
* // Fetch user information
|
|
71
|
-
* const userResponse = await fetch('https://gitlab.com/api/v4/user', {
|
|
72
|
-
* headers: { Authorization: `Bearer ${accessToken}` }
|
|
73
|
-
* })
|
|
74
|
-
* const user = await userResponse.json()
|
|
75
|
-
*
|
|
76
|
-
* // User info: id, username, email, name, avatar_url
|
|
77
|
-
* }
|
|
78
|
-
* }
|
|
79
|
-
* ```
|
|
80
|
-
*
|
|
81
|
-
* @packageDocumentation
|
|
82
|
-
*/
|
|
83
|
-
/**
|
|
84
|
-
* Creates a GitLab OAuth 2.0 authentication provider.
|
|
85
|
-
* Allows users to authenticate using their GitLab accounts (gitlab.com or self-hosted).
|
|
86
|
-
*
|
|
87
|
-
* @param config - GitLab OAuth 2.0 configuration
|
|
88
|
-
* @returns OAuth 2.0 provider configured for GitLab
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* ```ts
|
|
92
|
-
* // Basic GitLab.com authentication
|
|
93
|
-
* const basicGitlab = GitlabProvider({
|
|
94
|
-
* clientID: process.env.GITLAB_CLIENT_ID,
|
|
95
|
-
* clientSecret: process.env.GITLAB_CLIENT_SECRET
|
|
96
|
-
* })
|
|
97
|
-
*
|
|
98
|
-
* // GitLab with read access
|
|
99
|
-
* const gitlabWithRead = GitlabProvider({
|
|
100
|
-
* clientID: process.env.GITLAB_CLIENT_ID,
|
|
101
|
-
* clientSecret: process.env.GITLAB_CLIENT_SECRET,
|
|
102
|
-
* scopes: ["read_user", "read_api"]
|
|
103
|
-
* })
|
|
104
|
-
*
|
|
105
|
-
* // Using the access token to fetch user data
|
|
106
|
-
* export default issuer({
|
|
107
|
-
* providers: { gitlab: gitlabWithRead },
|
|
108
|
-
* success: async (ctx, value) => {
|
|
109
|
-
* if (value.provider === "gitlab") {
|
|
110
|
-
* const token = value.tokenset.access
|
|
111
|
-
*
|
|
112
|
-
* const userRes = await fetch('https://gitlab.com/api/v4/user', {
|
|
113
|
-
* headers: { Authorization: `Bearer ${token}` }
|
|
114
|
-
* })
|
|
115
|
-
* const user = await userRes.json()
|
|
116
|
-
*
|
|
117
|
-
* return ctx.subject("user", {
|
|
118
|
-
* gitlabId: user.id,
|
|
119
|
-
* username: user.username,
|
|
120
|
-
* email: user.email,
|
|
121
|
-
* name: user.name,
|
|
122
|
-
* avatar: user.avatar_url
|
|
123
|
-
* })
|
|
124
|
-
* }
|
|
125
|
-
* }
|
|
126
|
-
* })
|
|
127
|
-
* ```
|
|
128
|
-
*
|
|
129
|
-
* **Callback URL Pattern**: `{baseURL}{basePath}/{provider}/callback`
|
|
130
|
-
* - Development: `http://localhost:3000/auth/gitlab/callback`
|
|
131
|
-
* - Production: `https://yourapp.com/auth/gitlab/callback`
|
|
132
|
-
*
|
|
133
|
-
* Register this URL in your GitLab Application settings.
|
|
134
|
-
*/
|
|
135
|
-
const GitlabProvider = (config) => {
|
|
136
|
-
return Oauth2Provider({
|
|
137
|
-
...config,
|
|
138
|
-
type: "gitlab",
|
|
139
|
-
endpoint: {
|
|
140
|
-
authorization: "https://gitlab.com/oauth/authorize",
|
|
141
|
-
token: "https://gitlab.com/oauth/token"
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
//#endregion
|
|
147
|
-
export { GitlabProvider };
|