firstly 0.0.10 → 0.0.12
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/CHANGELOG.md +16 -0
- package/esm/BaseEnum.d.ts +2 -0
- package/esm/BaseEnum.js +2 -0
- package/esm/FF_Fields.js +0 -1
- package/esm/ROUTES.d.ts +2 -2
- package/esm/ROUTES.js +10 -5
- package/esm/SqlDatabase/FF_LogToConsole.d.ts +1 -0
- package/esm/SqlDatabase/FF_LogToConsole.js +22 -16
- package/esm/api/index.d.ts +19 -21
- package/esm/api/index.js +72 -62
- package/esm/auth/{client/Auth.d.ts → AuthController.d.ts} +18 -25
- package/esm/auth/{client/Auth.js → AuthController.js} +48 -44
- package/esm/auth/{client/Entities.d.ts → Entities.d.ts} +4 -3
- package/esm/auth/{client/Entities.js → Entities.js} +7 -7
- package/esm/auth/README.md +0 -10
- package/esm/auth/index.d.ts +5 -149
- package/esm/auth/index.js +5 -316
- package/esm/auth/{AuthController.server.d.ts → server/AuthController.server.d.ts} +10 -10
- package/esm/auth/{AuthController.server.js → server/AuthController.server.js} +126 -164
- package/esm/auth/server/handleAuth.d.ts +2 -0
- package/esm/auth/server/handleAuth.js +140 -0
- package/esm/auth/server/helperDb.d.ts +10 -0
- package/esm/auth/server/helperDb.js +56 -0
- package/esm/auth/server/helperFirstly.d.ts +1 -0
- package/esm/auth/server/helperFirstly.js +8 -0
- package/esm/auth/server/helperOslo.d.ts +7 -0
- package/esm/auth/server/helperOslo.js +24 -0
- package/esm/auth/server/helperRemultServer.d.ts +5 -0
- package/esm/auth/server/helperRemultServer.js +44 -0
- package/esm/auth/{RoleHelpers.d.ts → server/helperRole.d.ts} +1 -1
- package/esm/auth/{RoleHelpers.js → server/helperRole.js} +1 -1
- package/esm/auth/server/index.d.ts +5 -0
- package/esm/auth/server/index.js +5 -0
- package/esm/auth/server/module.d.ts +238 -0
- package/esm/auth/server/module.js +184 -0
- package/esm/auth/{providers → server/providers}/github.d.ts +6 -5
- package/esm/auth/{providers → server/providers}/github.js +30 -21
- package/esm/auth/{providers/index.d.ts → server/providers/helperProvider.d.ts} +0 -2
- package/esm/auth/{providers/index.js → server/providers/helperProvider.js} +5 -6
- package/esm/auth/static/assets/{Page-BEFYPjis.d.ts → Page-Bb8bFlrP.d.ts} +1 -1
- package/esm/auth/static/assets/{Page-DtgkOCJs.js → Page-Bb8bFlrP.js} +1 -1
- package/esm/auth/static/assets/{Page-DtgkOCJs.d.ts → Page-BxomFlZ8.d.ts} +1 -1
- package/esm/auth/static/assets/{Page-BEFYPjis.js → Page-BxomFlZ8.js} +1 -1
- package/esm/auth/static/assets/Page-CaIYu0-y.d.ts +6 -0
- package/esm/auth/static/assets/Page-CaIYu0-y.js +19 -0
- package/esm/auth/static/assets/Page-MkYglNtu.css +1 -0
- package/esm/auth/static/assets/index-Bl0Bk5u0.d.ts +64 -0
- package/esm/auth/static/assets/index-Bl0Bk5u0.js +2 -0
- package/esm/auth/static/assets/{index-CR_3yNaJ.css → index-R27C_TlP.css} +1 -1
- package/esm/auth/static/index.html +2 -2
- package/esm/auth/types.d.ts +5 -0
- package/esm/bin/cmd.js +13 -22
- package/esm/cellsBuildor.js +6 -6
- package/esm/changeLog/index.d.ts +0 -36
- package/esm/changeLog/index.js +3 -43
- package/esm/changeLog/server/index.d.ts +36 -0
- package/esm/changeLog/server/index.js +42 -0
- package/esm/cron/{index.d.ts → server/index.d.ts} +1 -1
- package/esm/cron/server/index.js +103 -0
- package/esm/feedback/FeedbackController.js +3 -3
- package/esm/feedback/index.d.ts +0 -16
- package/esm/feedback/index.js +0 -11
- package/esm/feedback/server/index.d.ts +17 -0
- package/esm/feedback/server/index.js +13 -0
- package/esm/feedback/ui/DialogIssue.svelte +4 -2
- package/esm/feedback/ui/DialogIssues.svelte +13 -4
- package/esm/feedback/ui/DialogMilestones.svelte +1 -1
- package/esm/feedback/ui/Feedback.svelte +3 -1
- package/esm/helper.d.ts +0 -1
- package/esm/helper.js +3 -17
- package/esm/index.d.ts +3 -17
- package/esm/index.js +3 -4
- package/esm/mail/index.d.ts +2 -30
- package/esm/mail/index.js +2 -79
- package/esm/mail/server/index.d.ts +31 -0
- package/esm/mail/server/index.js +88 -0
- package/esm/storeItem.d.ts +4 -1
- package/esm/storeItem.js +8 -2
- package/esm/storeList.d.ts +5 -2
- package/esm/storeList.js +1 -1
- package/esm/sveltekit/server/index.d.ts +11 -0
- package/esm/sveltekit/server/index.js +21 -0
- package/esm/ui/Button.svelte +1 -1
- package/esm/ui/Clipboardable.svelte +5 -2
- package/esm/ui/Field.svelte +4 -1
- package/esm/ui/Loading.svelte +4 -1
- package/esm/ui/Tooltip.svelte +2 -2
- package/esm/ui/dialog/DialogForm.svelte +1 -1
- package/esm/ui/dialog/DialogPrimitive.svelte +1 -2
- package/esm/ui/dialog/dialog.d.ts +6 -3
- package/esm/ui/dialog/dialog.js +1 -1
- package/esm/ui/internals/FieldContainer.svelte +0 -1
- package/esm/ui/internals/Input.svelte +3 -1
- package/esm/ui/internals/Textarea.svelte +2 -2
- package/esm/vite/index.js +24 -25
- package/package.json +50 -38
- package/esm/auth/Adapter.d.ts +0 -10
- package/esm/auth/Adapter.js +0 -50
- package/esm/auth/client/index.d.ts +0 -7
- package/esm/auth/client/index.js +0 -7
- package/esm/auth/helper.d.ts +0 -6
- package/esm/auth/helper.js +0 -14
- package/esm/auth/providers/strava.d.ts +0 -30
- package/esm/auth/providers/strava.js +0 -60
- package/esm/auth/static/assets/Page-BGTO8LC5.css +0 -1
- package/esm/auth/static/assets/Page-Cfysx_UV.d.ts +0 -6
- package/esm/auth/static/assets/Page-Cfysx_UV.js +0 -18
- package/esm/auth/static/assets/index-QypqCYwC.d.ts +0 -63
- package/esm/auth/static/assets/index-QypqCYwC.js +0 -2
- package/esm/cron/index.js +0 -102
- package/esm/handle/index.d.ts +0 -7
- package/esm/handle/index.js +0 -40
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import bcrypt from 'bcrypt';
|
|
2
|
+
import { EntityError, remult } from 'remult';
|
|
3
|
+
import { red } from '@kitql/helpers';
|
|
4
|
+
import { getRelativePackagePath } from '@kitql/internals';
|
|
5
|
+
import { AuthController } from '..';
|
|
6
|
+
import { FF_Role } from '../..';
|
|
7
|
+
import { Module } from '../../api';
|
|
8
|
+
import { FF_Role_Auth, FFAuthAccount, FFAuthUser, FFAuthUserSession } from '../Entities';
|
|
9
|
+
import { AuthControllerServer } from './AuthController.server';
|
|
10
|
+
import { validateSessionToken } from './helperDb';
|
|
11
|
+
import { setSessionTokenCookie } from './helperRemultServer';
|
|
12
|
+
import { initRoleFromEnv } from './helperRole';
|
|
13
|
+
export let AUTH_OPTIONS = { ui: {} };
|
|
14
|
+
const buildUrlOrDefault = (base, userSetting, fallback) => {
|
|
15
|
+
if (userSetting === false) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
if (userSetting === undefined) {
|
|
19
|
+
return `${base}/${fallback}`;
|
|
20
|
+
}
|
|
21
|
+
return `${base}/${userSetting}`;
|
|
22
|
+
};
|
|
23
|
+
export const getSafeOptions = () => {
|
|
24
|
+
const signUp = AUTH_OPTIONS.signUp ?? true;
|
|
25
|
+
const base = AUTH_OPTIONS.ui === false ? 'NO_BASE_PATH' : (AUTH_OPTIONS.ui?.paths?.base ?? '/ff/auth');
|
|
26
|
+
const firstlyData = {
|
|
27
|
+
module: 'auth',
|
|
28
|
+
debug: AUTH_OPTIONS.debug,
|
|
29
|
+
props: {
|
|
30
|
+
ui: AUTH_OPTIONS.ui === false
|
|
31
|
+
? undefined
|
|
32
|
+
: {
|
|
33
|
+
paths: {
|
|
34
|
+
base,
|
|
35
|
+
sign_up: signUp
|
|
36
|
+
? buildUrlOrDefault(base, AUTH_OPTIONS.ui?.paths?.sign_up, 'sign-up')
|
|
37
|
+
: false,
|
|
38
|
+
sign_in: buildUrlOrDefault(base, AUTH_OPTIONS.ui?.paths?.sign_in, 'sign-in'),
|
|
39
|
+
forgot_password: buildUrlOrDefault(base, AUTH_OPTIONS.ui?.paths?.forgot_password, 'forgot-password'),
|
|
40
|
+
reset_password: buildUrlOrDefault(base, AUTH_OPTIONS.ui?.paths?.reset_password, 'reset-password'),
|
|
41
|
+
verify_email: buildUrlOrDefault(base, AUTH_OPTIONS.ui?.paths?.verify_email, 'verify-email'),
|
|
42
|
+
},
|
|
43
|
+
strings: {
|
|
44
|
+
app_name: AUTH_OPTIONS.ui?.strings?.app_name ?? '',
|
|
45
|
+
email: AUTH_OPTIONS.ui?.strings?.email ?? 'Email',
|
|
46
|
+
email_placeholder: AUTH_OPTIONS.ui?.strings?.email_placeholder ?? 'Your email address',
|
|
47
|
+
password: AUTH_OPTIONS.ui?.strings?.password ?? 'Password',
|
|
48
|
+
password_placeholder: AUTH_OPTIONS.ui?.strings?.password_placeholder ?? 'Your password',
|
|
49
|
+
confirm: AUTH_OPTIONS.ui?.strings?.confirm ?? 'Confirm',
|
|
50
|
+
reset: AUTH_OPTIONS.ui?.strings?.reset ?? 'Reset',
|
|
51
|
+
btn_sign_up: AUTH_OPTIONS.ui?.strings?.btn_sign_up ?? 'Sign up',
|
|
52
|
+
btn_sign_in: AUTH_OPTIONS.ui?.strings?.btn_sign_in ?? 'Sign in',
|
|
53
|
+
forgot_password: AUTH_OPTIONS.ui?.strings?.forgot_password ?? 'Forgot your password?',
|
|
54
|
+
send_password_reset_instructions: AUTH_OPTIONS.ui?.strings?.send_password_reset_instructions ??
|
|
55
|
+
'Send password reset instructions',
|
|
56
|
+
back_to_sign_in: AUTH_OPTIONS.ui?.strings?.back_to_sign_in ?? 'Back to sign in',
|
|
57
|
+
},
|
|
58
|
+
images: {
|
|
59
|
+
main: AUTH_OPTIONS.ui?.images?.main ?? '',
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
let uiStaticPath = AUTH_OPTIONS.uiStaticPath ?? '';
|
|
65
|
+
if (!AUTH_OPTIONS.uiStaticPath) {
|
|
66
|
+
const installedFirstlyPath = getRelativePackagePath('firstly');
|
|
67
|
+
if (installedFirstlyPath) {
|
|
68
|
+
uiStaticPath = `${installedFirstlyPath}/esm/auth/static/`;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
let redirectUrl = AUTH_OPTIONS.defaultRedirect ?? '/';
|
|
72
|
+
if (!redirectUrl.startsWith('/')) {
|
|
73
|
+
authModuleRaw.log.error(`Invalid redirect url ${red(redirectUrl)} (it should be a local one starting with /)`);
|
|
74
|
+
redirectUrl = '/';
|
|
75
|
+
}
|
|
76
|
+
let transformDbUserToClientUserToUse;
|
|
77
|
+
if (AUTH_OPTIONS.transformDbUserToClientUser) {
|
|
78
|
+
transformDbUserToClientUserToUse = AUTH_OPTIONS.transformDbUserToClientUser;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
// @ts-ignore (I'm not sure why cadb-my-doc is failing check here if I don't do this!)
|
|
82
|
+
transformDbUserToClientUserToUse = (session, user) => {
|
|
83
|
+
return {
|
|
84
|
+
id: user.id,
|
|
85
|
+
name: user.identifier,
|
|
86
|
+
roles: user.roles,
|
|
87
|
+
session: {
|
|
88
|
+
id: session.id,
|
|
89
|
+
expiresAt: session.expiresAt,
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function validatePassword(password) {
|
|
95
|
+
if (typeof password !== 'string' || password.length < 6 || password.length > 255) {
|
|
96
|
+
throw new EntityError({ message: 'Invalid password' });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function passwordHash(password) {
|
|
100
|
+
validatePassword(password);
|
|
101
|
+
return bcrypt.hashSync(password, AUTH_OPTIONS.providers?.password?.settings?.bcrypt?.saltRounds ?? 10);
|
|
102
|
+
}
|
|
103
|
+
function passwordVerify(password, hash) {
|
|
104
|
+
return bcrypt.compareSync(password, hash);
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
User: (AUTH_OPTIONS.customEntities?.User ?? FFAuthUser),
|
|
108
|
+
Session: (AUTH_OPTIONS.customEntities?.Session ??
|
|
109
|
+
FFAuthUserSession),
|
|
110
|
+
Account: (AUTH_OPTIONS.customEntities?.Account ?? FFAuthAccount),
|
|
111
|
+
signUp,
|
|
112
|
+
password: {
|
|
113
|
+
enabled: AUTH_OPTIONS.providers?.password ? true : false,
|
|
114
|
+
validatePassword: AUTH_OPTIONS.providers?.password?.settings?.bcrypt?.validatePassword ?? validatePassword,
|
|
115
|
+
passwordHash: AUTH_OPTIONS.providers?.password?.settings?.bcrypt?.passwordHash ?? passwordHash,
|
|
116
|
+
passwordVerify: AUTH_OPTIONS.providers?.password?.settings?.bcrypt?.passwordVerify ?? passwordVerify,
|
|
117
|
+
},
|
|
118
|
+
otp: { enabled: AUTH_OPTIONS.providers?.otp ? true : false },
|
|
119
|
+
verifiedMethod: AUTH_OPTIONS.verifiedMethod ?? 'auto',
|
|
120
|
+
redirectUrl,
|
|
121
|
+
firstlyData,
|
|
122
|
+
transformDbUserToClientUser: transformDbUserToClientUserToUse,
|
|
123
|
+
uiStaticPath,
|
|
124
|
+
session: {
|
|
125
|
+
expiresInMs: AUTH_OPTIONS.session?.expiresIn ?? 1000 * 60 * 60 * 24 * 30, // 30 days,
|
|
126
|
+
cookieName: AUTH_OPTIONS.session?.COOKIE_NAME ?? 'firstly_auth_session',
|
|
127
|
+
},
|
|
128
|
+
providers: AUTH_OPTIONS.providers,
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
export const authModuleRaw = new Module({
|
|
132
|
+
name: 'auth',
|
|
133
|
+
priority: -777,
|
|
134
|
+
});
|
|
135
|
+
/**
|
|
136
|
+
* To enable authentication in your app in a few lines of code.
|
|
137
|
+
* _Info: index: -777_
|
|
138
|
+
*/
|
|
139
|
+
export const auth = (o) => {
|
|
140
|
+
// TODO should work ?
|
|
141
|
+
// @ts-ignore
|
|
142
|
+
AUTH_OPTIONS = o;
|
|
143
|
+
const oSafe = getSafeOptions();
|
|
144
|
+
// Replace the direct assignments with the new _setImplementation method
|
|
145
|
+
AuthController._setAbstraction({
|
|
146
|
+
signOut: AuthControllerServer.signOut,
|
|
147
|
+
signInDemo: AuthControllerServer.signInDemo,
|
|
148
|
+
invite: AuthControllerServer.invite,
|
|
149
|
+
signUpPassword: AuthControllerServer.signUpPassword,
|
|
150
|
+
signInPassword: AuthControllerServer.signInPassword,
|
|
151
|
+
forgotPassword: AuthControllerServer.forgotPassword,
|
|
152
|
+
resetPassword: AuthControllerServer.resetPassword,
|
|
153
|
+
signInOTP: AuthControllerServer.signInOTP,
|
|
154
|
+
verifyOtp: AuthControllerServer.verifyOtp,
|
|
155
|
+
signInOAuthGetUrl: AuthControllerServer.signInOAuthGetUrl,
|
|
156
|
+
});
|
|
157
|
+
authModuleRaw.entities = [oSafe.User, oSafe.Session, oSafe.Account];
|
|
158
|
+
authModuleRaw.controllers = [AuthController];
|
|
159
|
+
authModuleRaw.initRequest = async (event) => {
|
|
160
|
+
// REMULT: storing user in local should probably be done in remult directly
|
|
161
|
+
if (event?.locals?.user) {
|
|
162
|
+
remult.user = event.locals.user;
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
const sessionId = event.cookies.get(oSafe.session.cookieName);
|
|
166
|
+
if (sessionId) {
|
|
167
|
+
const { user, freshSession } = await validateSessionToken(sessionId);
|
|
168
|
+
if (freshSession) {
|
|
169
|
+
setSessionTokenCookie(freshSession.sessionToken, freshSession.expiresAt);
|
|
170
|
+
}
|
|
171
|
+
remult.user = user;
|
|
172
|
+
if (event.locals) {
|
|
173
|
+
event.locals.user = user;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
authModuleRaw.initApi = async () => {
|
|
179
|
+
await initRoleFromEnv(authModuleRaw.log, oSafe.User, 'FF_ROLE_ADMIN', FF_Role.FF_Role_Admin);
|
|
180
|
+
await initRoleFromEnv(authModuleRaw.log, oSafe.User, 'FF_ROLE_AUTH_ADMIN', FF_Role_Auth.FF_Role_Auth_Admin);
|
|
181
|
+
};
|
|
182
|
+
return authModuleRaw;
|
|
183
|
+
};
|
|
184
|
+
export { initRoleFromEnv };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { GitHub } from 'arctic';
|
|
2
|
-
import { type FFOAuth2Provider } from '../';
|
|
1
|
+
import { GitHub, OAuth2Tokens } from 'arctic';
|
|
2
|
+
import { type FFOAuth2Provider, type OAuth2UserInfo, type ProviderAuthorizationURLOptions } from '../module';
|
|
3
3
|
/**
|
|
4
4
|
* ## GitHub OAuth2 provider
|
|
5
5
|
*
|
|
6
6
|
* 1. Get your **id** & **secret** from [GitHub (direct link)](https://github.com/settings/developers).
|
|
7
7
|
* 2. In GitHub, set your callback url to
|
|
8
|
-
* - [ ] dev: `http://
|
|
8
|
+
* - [ ] dev: `http://_YOUR_LOCAL_URL:PORT_/api/auth_callback`
|
|
9
9
|
* - [ ] prod: `https://MY_SUPER_SITE/api/auth_callback`
|
|
10
10
|
* 3. In your project add a `.env` file with the following:
|
|
11
11
|
* ```bash
|
|
@@ -25,6 +25,7 @@ export declare function github(options?: {
|
|
|
25
25
|
GITHUB_CLIENT_ID?: string;
|
|
26
26
|
GITHUB_CLIENT_SECRET?: string;
|
|
27
27
|
GITHUB_REDIRECT_URI?: string;
|
|
28
|
-
authorizationURLOptions?:
|
|
28
|
+
authorizationURLOptions?: ProviderAuthorizationURLOptions;
|
|
29
|
+
getUserInfo?: (tokens: OAuth2Tokens) => Promise<OAuth2UserInfo>;
|
|
29
30
|
log?: boolean;
|
|
30
|
-
}): FFOAuth2Provider<'github'
|
|
31
|
+
}): FFOAuth2Provider<GitHub, 'github'>;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { GitHub } from 'arctic';
|
|
1
|
+
import { GitHub, OAuth2Tokens } from 'arctic';
|
|
2
2
|
import { remult } from 'remult';
|
|
3
3
|
import { env } from '$env/dynamic/private';
|
|
4
|
-
import {
|
|
5
|
-
import {} from '
|
|
6
|
-
import { logAuth } from '../client';
|
|
4
|
+
import { authModuleRaw, } from '../module';
|
|
5
|
+
import { checkOAuthConfig } from './helperProvider';
|
|
7
6
|
//------------------------------
|
|
8
7
|
// For developers (future me ?), To do another OAuth2 provider:
|
|
9
8
|
// Replace GITHUB / Github / github
|
|
@@ -15,7 +14,7 @@ import { logAuth } from '../client';
|
|
|
15
14
|
*
|
|
16
15
|
* 1. Get your **id** & **secret** from [GitHub (direct link)](https://github.com/settings/developers).
|
|
17
16
|
* 2. In GitHub, set your callback url to
|
|
18
|
-
* - [ ] dev: `http://
|
|
17
|
+
* - [ ] dev: `http://_YOUR_LOCAL_URL:PORT_/api/auth_callback`
|
|
19
18
|
* - [ ] prod: `https://MY_SUPER_SITE/api/auth_callback`
|
|
20
19
|
* 3. In your project add a `.env` file with the following:
|
|
21
20
|
* ```bash
|
|
@@ -39,28 +38,38 @@ export function github(options) {
|
|
|
39
38
|
checkOAuthConfig(name, clientID, secret, urlForKeys, false);
|
|
40
39
|
return {
|
|
41
40
|
name,
|
|
42
|
-
isPKCE: false,
|
|
43
41
|
getArcticProvider: () => {
|
|
44
42
|
const redirectURI = options?.GITHUB_REDIRECT_URI ??
|
|
45
43
|
env.GITHUB_REDIRECT_URI ??
|
|
46
|
-
`${remult.context.url.origin}/api/auth_callback`;
|
|
44
|
+
`${remult.context.request.url.origin}/api/auth_callback`;
|
|
47
45
|
checkOAuthConfig(name, clientID, secret, urlForKeys, true);
|
|
48
|
-
|
|
46
|
+
const o = new GitHub(clientID, secret, redirectURI);
|
|
47
|
+
return o;
|
|
49
48
|
},
|
|
50
49
|
authorizationURLOptions: () => {
|
|
51
|
-
return options?.authorizationURLOptions ??
|
|
52
|
-
},
|
|
53
|
-
getUserInfo: async (tokens) => {
|
|
54
|
-
const res = await fetch('https://api.github.com/user', {
|
|
55
|
-
headers: {
|
|
56
|
-
Authorization: `Bearer ${tokens.accessToken}`,
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
const user = await res.json();
|
|
60
|
-
if (options?.log) {
|
|
61
|
-
logAuth.info(`user`, user);
|
|
62
|
-
}
|
|
63
|
-
return { raw: user, providerUserId: String(user.id), nameOptions: [user.login] };
|
|
50
|
+
return options?.authorizationURLOptions ?? [];
|
|
64
51
|
},
|
|
52
|
+
getUserInfo: options?.getUserInfo
|
|
53
|
+
? options.getUserInfo
|
|
54
|
+
: async (tokens) => {
|
|
55
|
+
const res = await fetch('https://api.github.com/user', {
|
|
56
|
+
headers: {
|
|
57
|
+
Authorization: `Bearer ${tokens.accessToken()}`,
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
const user = await res.json();
|
|
61
|
+
if ((options?.authorizationURLOptions ?? []).includes('user:email')) {
|
|
62
|
+
const res = await fetch('https://api.github.com/user/emails', {
|
|
63
|
+
headers: {
|
|
64
|
+
Authorization: `Bearer ${tokens.accessToken()}`,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
user.emails = await res.json();
|
|
68
|
+
}
|
|
69
|
+
if (options?.log) {
|
|
70
|
+
authModuleRaw.log.info(`user`, user);
|
|
71
|
+
}
|
|
72
|
+
return { raw: user, providerUserId: String(user.id), nameOptions: [user.login] };
|
|
73
|
+
},
|
|
65
74
|
};
|
|
66
75
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { EntityError } from 'remult';
|
|
1
2
|
import { cyan, gray, green, italic, yellow } from '@kitql/helpers';
|
|
2
|
-
import { mask } from '
|
|
3
|
-
import {
|
|
3
|
+
import { mask } from '../../../formats/strings';
|
|
4
|
+
import { authModuleRaw } from '../module';
|
|
4
5
|
export const checkOAuthConfig = (name, clientId, secret, urlForKeys, withThrow) => {
|
|
5
6
|
if (!clientId || !secret) {
|
|
6
7
|
const msg = `Wrong configuration for ${green(name)} provider.
|
|
@@ -15,12 +16,10 @@ export const checkOAuthConfig = (name, clientId, secret, urlForKeys, withThrow)
|
|
|
15
16
|
Check ${cyan(urlForKeys)} to generate your keys.
|
|
16
17
|
`;
|
|
17
18
|
if (withThrow) {
|
|
18
|
-
throw new
|
|
19
|
+
throw new EntityError({ message: msg });
|
|
19
20
|
}
|
|
20
21
|
else {
|
|
21
|
-
|
|
22
|
+
authModuleRaw.log.error(msg);
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
};
|
|
25
|
-
export { github } from './github';
|
|
26
|
-
export { strava } from './strava';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{S as l,b as d,a as f,d as i,h as m,M as p,t as u,n as r,z as h}from"./index-
|
|
1
|
+
import{S as l,b as d,a as f,d as i,h as m,M as p,t as u,n as r,z as h}from"./index-Bl0Bk5u0.js";function c(a){let e;const n={c:function(){e=p("Hello from files")},l:function(t){throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option")},m:function(t,o){u(t,e,o)},p:r,i:r,o:r,d:function(t){t&&h(e)}};return i("SvelteRegisterBlock",{block:n,id:c.name,type:"component",source:"",ctx:a}),n}function w(a,e){let{$$slots:n={},$$scope:s}=e;m("Page",n,[]);const t=[];return Object.keys(e).forEach(o=>{!~t.indexOf(o)&&o.slice(0,2)!=="$$"&&o!=="slot"&&console.warn(`<Page> was created with unknown prop '${o}'`)}),[]}class v extends l{constructor(e){super(e),d(this,e,w,c,f,{}),i("SvelteRegisterComponent",{component:this,tagName:"Page",options:e,id:c.name})}}export{v as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{S as l,b as d,a as f,d as i,h as m,M as p,t as u,n as r,z as h}from"./index-
|
|
1
|
+
import{S as l,b as d,a as f,d as i,h as m,M as p,t as u,n as r,z as h}from"./index-Bl0Bk5u0.js";function c(s){let e;const n={c:function(){e=p("Hello from admin")},l:function(t){throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option")},m:function(t,o){u(t,e,o)},p:r,i:r,o:r,d:function(t){t&&h(e)}};return i("SvelteRegisterBlock",{block:n,id:c.name,type:"component",source:"",ctx:s}),n}function w(s,e){let{$$slots:n={},$$scope:a}=e;m("Page",n,[]);const t=[];return Object.keys(e).forEach(o=>{!~t.indexOf(o)&&o.slice(0,2)!=="$$"&&o!=="slot"&&console.warn(`<Page> was created with unknown prop '${o}'`)}),[]}class v extends l{constructor(e){super(e),d(this,e,w,c,f,{}),i("SvelteRegisterComponent",{component:this,tagName:"Page",options:e,id:c.name})}}export{v as default};
|