acebase-server 1.16.2 → 1.17.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/README.md +180 -10
- package/build-vars.js +2 -1
- package/dist/cjs/auth.js +88 -88
- package/dist/cjs/cluster.js +56 -56
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +24 -24
- package/dist/cjs/logger.js +73 -73
- package/dist/cjs/middleware/404.js +14 -14
- package/dist/cjs/middleware/admin-only.js +28 -28
- package/dist/cjs/middleware/cache.js +14 -14
- package/dist/cjs/middleware/connection.js +49 -49
- package/dist/cjs/middleware/context.js +20 -20
- package/dist/cjs/middleware/cors.js +50 -50
- package/dist/cjs/middleware/swagger.js +17 -17
- package/dist/cjs/middleware/user.js +57 -57
- package/dist/cjs/oauth-providers/dropbox.js +109 -109
- package/dist/cjs/oauth-providers/facebook.js +85 -85
- package/dist/cjs/oauth-providers/google.js +119 -119
- package/dist/cjs/oauth-providers/index.js +26 -26
- package/dist/cjs/oauth-providers/instagram.js +80 -80
- package/dist/cjs/oauth-providers/oauth-provider.js +20 -20
- package/dist/cjs/oauth-providers/spotify.js +113 -113
- package/dist/cjs/routes/auth-change-password.js +87 -87
- package/dist/cjs/routes/auth-delete.js +52 -52
- package/dist/cjs/routes/auth-forgot-password.js +77 -77
- package/dist/cjs/routes/auth-reset-password.js +97 -97
- package/dist/cjs/routes/auth-signin.js +46 -46
- package/dist/cjs/routes/auth-signout.js +61 -61
- package/dist/cjs/routes/auth-signup.js +142 -142
- package/dist/cjs/routes/auth-state.js +25 -25
- package/dist/cjs/routes/auth-update.js +131 -131
- package/dist/cjs/routes/auth-verify-email.js +71 -71
- package/dist/cjs/routes/auth.js +57 -54
- package/dist/cjs/routes/data-exists.js +33 -33
- package/dist/cjs/routes/data-export.js +48 -48
- package/dist/cjs/routes/data-get.js +70 -66
- package/dist/cjs/routes/data-import.js +54 -54
- package/dist/cjs/routes/data-index-create.js +42 -42
- package/dist/cjs/routes/data-index-delete.js +33 -33
- package/dist/cjs/routes/data-index-list.js +31 -31
- package/dist/cjs/routes/data-query.js +80 -70
- package/dist/cjs/routes/data-reflect.js +97 -86
- package/dist/cjs/routes/data-schema-get.js +36 -36
- package/dist/cjs/routes/data-schema-set.js +30 -30
- package/dist/cjs/routes/data-schema-test.js +43 -43
- package/dist/cjs/routes/data-schemas-list.js +32 -32
- package/dist/cjs/routes/data-set.js +85 -75
- package/dist/cjs/routes/data-sync-changes.js +81 -67
- package/dist/cjs/routes/data-sync-mutations.js +81 -67
- package/dist/cjs/routes/data-transaction.js +159 -139
- package/dist/cjs/routes/data-update.js +86 -75
- package/dist/cjs/routes/data.js +62 -62
- package/dist/cjs/routes/docs.js +258 -251
- package/dist/cjs/routes/meta-info.js +63 -63
- package/dist/cjs/routes/meta-logs.js +49 -49
- package/dist/cjs/routes/meta-ping.js +11 -11
- package/dist/cjs/routes/meta-stats.js +27 -27
- package/dist/cjs/routes/meta.js +19 -19
- package/dist/cjs/routes/oauth2-init.js +54 -54
- package/dist/cjs/routes/oauth2-refresh.js +42 -42
- package/dist/cjs/routes/oauth2-signin.js +265 -265
- package/dist/cjs/routes/webmanager.js +26 -26
- package/dist/cjs/rules.js +380 -167
- package/dist/cjs/sandbox.js +28 -0
- package/dist/cjs/schema/user.js +24 -24
- package/dist/cjs/server.js +415 -407
- package/dist/cjs/settings/email.js +2 -2
- package/dist/cjs/settings/index.js +175 -172
- package/dist/cjs/shared/clients.js +26 -26
- package/dist/cjs/shared/email.js +2 -2
- package/dist/cjs/shared/env.js +2 -2
- package/dist/cjs/shared/error.js +33 -33
- package/dist/cjs/shared/http.js +28 -28
- package/dist/cjs/shared/password.js +45 -45
- package/dist/cjs/shared/rootpath.js +16 -16
- package/dist/cjs/shared/signin.js +143 -143
- package/dist/cjs/shared/simple-fetch.js +76 -76
- package/dist/cjs/shared/tokens.js +79 -79
- package/dist/cjs/shared/validate.js +61 -61
- package/dist/cjs/start.js +53 -53
- package/dist/cjs/test.js +10 -10
- package/dist/cjs/websocket/index.js +331 -319
- package/dist/cjs/websocket/manager.js +15 -15
- package/dist/cjs/websocket/socket.io.js +76 -76
- package/dist/esm/auth.js +75 -75
- package/dist/esm/cluster.js +54 -54
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +4 -4
- package/dist/esm/logger.js +51 -51
- package/dist/esm/middleware/404.js +10 -10
- package/dist/esm/middleware/admin-only.js +24 -24
- package/dist/esm/middleware/cache.js +10 -10
- package/dist/esm/middleware/connection.js +45 -45
- package/dist/esm/middleware/context.js +16 -16
- package/dist/esm/middleware/cors.js +44 -44
- package/dist/esm/middleware/swagger.js +13 -13
- package/dist/esm/middleware/user.js +44 -44
- package/dist/esm/oauth-providers/dropbox.js +90 -90
- package/dist/esm/oauth-providers/facebook.js +66 -66
- package/dist/esm/oauth-providers/google.js +96 -96
- package/dist/esm/oauth-providers/index.js +18 -18
- package/dist/esm/oauth-providers/instagram.js +61 -61
- package/dist/esm/oauth-providers/oauth-provider.js +16 -16
- package/dist/esm/oauth-providers/spotify.js +92 -92
- package/dist/esm/routes/auth-change-password.js +72 -72
- package/dist/esm/routes/auth-delete.js +37 -37
- package/dist/esm/routes/auth-forgot-password.js +62 -62
- package/dist/esm/routes/auth-reset-password.js +81 -81
- package/dist/esm/routes/auth-signin.js +33 -33
- package/dist/esm/routes/auth-signout.js +47 -47
- package/dist/esm/routes/auth-signup.js +127 -127
- package/dist/esm/routes/auth-state.js +12 -12
- package/dist/esm/routes/auth-update.js +116 -116
- package/dist/esm/routes/auth-verify-email.js +57 -57
- package/dist/esm/routes/auth.js +53 -50
- package/dist/esm/routes/data-exists.js +20 -20
- package/dist/esm/routes/data-export.js +35 -35
- package/dist/esm/routes/data-get.js +56 -52
- package/dist/esm/routes/data-import.js +41 -41
- package/dist/esm/routes/data-index-create.js +28 -28
- package/dist/esm/routes/data-index-delete.js +20 -20
- package/dist/esm/routes/data-index-list.js +18 -18
- package/dist/esm/routes/data-query.js +66 -56
- package/dist/esm/routes/data-reflect.js +83 -72
- package/dist/esm/routes/data-schema-get.js +23 -23
- package/dist/esm/routes/data-schema-set.js +17 -17
- package/dist/esm/routes/data-schema-test.js +29 -29
- package/dist/esm/routes/data-schemas-list.js +19 -19
- package/dist/esm/routes/data-set.js +70 -60
- package/dist/esm/routes/data-sync-changes.js +67 -53
- package/dist/esm/routes/data-sync-mutations.js +67 -53
- package/dist/esm/routes/data-transaction.js +142 -123
- package/dist/esm/routes/data-update.js +71 -60
- package/dist/esm/routes/data.js +58 -58
- package/dist/esm/routes/docs.js +252 -245
- package/dist/esm/routes/meta-info.js +59 -59
- package/dist/esm/routes/meta-logs.js +35 -35
- package/dist/esm/routes/meta-ping.js +7 -7
- package/dist/esm/routes/meta-stats.js +14 -14
- package/dist/esm/routes/meta.js +15 -15
- package/dist/esm/routes/oauth2-init.js +41 -41
- package/dist/esm/routes/oauth2-refresh.js +29 -29
- package/dist/esm/routes/oauth2-signin.js +251 -251
- package/dist/esm/routes/webmanager.js +22 -22
- package/dist/esm/rules.js +374 -163
- package/dist/esm/sandbox.js +12 -0
- package/dist/esm/schema/user.js +19 -19
- package/dist/esm/server.js +395 -387
- package/dist/esm/settings/email.js +1 -1
- package/dist/esm/settings/index.js +168 -165
- package/dist/esm/shared/clients.js +22 -22
- package/dist/esm/shared/email.js +1 -1
- package/dist/esm/shared/env.js +1 -1
- package/dist/esm/shared/error.js +25 -25
- package/dist/esm/shared/http.js +22 -22
- package/dist/esm/shared/password.js +38 -38
- package/dist/esm/shared/rootpath.js +13 -13
- package/dist/esm/shared/signin.js +128 -128
- package/dist/esm/shared/simple-fetch.js +59 -59
- package/dist/esm/shared/tokens.js +72 -72
- package/dist/esm/shared/validate.js +41 -41
- package/dist/esm/start.js +50 -50
- package/dist/esm/test.js +8 -8
- package/dist/esm/websocket/index.js +313 -302
- package/dist/esm/websocket/manager.js +11 -11
- package/dist/esm/websocket/socket.io.js +71 -71
- package/dist/types/auth.d.ts +3 -3
- package/dist/types/cluster.d.ts +1 -1
- package/dist/types/index.d.ts +4 -4
- package/dist/types/logger.d.ts +35 -35
- package/dist/types/middleware/404.d.ts +7 -7
- package/dist/types/middleware/admin-only.d.ts +19 -19
- package/dist/types/middleware/cache.d.ts +3 -3
- package/dist/types/middleware/connection.d.ts +7 -7
- package/dist/types/middleware/context.d.ts +3 -3
- package/dist/types/middleware/cors.d.ts +25 -25
- package/dist/types/middleware/swagger.d.ts +3 -3
- package/dist/types/middleware/user.d.ts +2 -2
- package/dist/types/oauth-providers/dropbox.d.ts +52 -52
- package/dist/types/oauth-providers/facebook.d.ts +41 -41
- package/dist/types/oauth-providers/google.d.ts +43 -43
- package/dist/types/oauth-providers/index.d.ts +10 -10
- package/dist/types/oauth-providers/instagram.d.ts +50 -50
- package/dist/types/oauth-providers/oauth-provider.d.ts +74 -74
- package/dist/types/oauth-providers/spotify.d.ts +53 -53
- package/dist/types/routes/auth-change-password.d.ts +20 -20
- package/dist/types/routes/auth-delete.d.ts +16 -16
- package/dist/types/routes/auth-forgot-password.d.ts +16 -16
- package/dist/types/routes/auth-reset-password.d.ts +23 -23
- package/dist/types/routes/auth-signin.d.ts +24 -24
- package/dist/types/routes/auth-signout.d.ts +14 -14
- package/dist/types/routes/auth-signup.d.ts +32 -32
- package/dist/types/routes/auth-state.d.ts +13 -13
- package/dist/types/routes/auth-update.d.ts +33 -33
- package/dist/types/routes/auth-verify-email.d.ts +21 -21
- package/dist/types/routes/auth.d.ts +6 -6
- package/dist/types/routes/data-exists.d.ts +9 -9
- package/dist/types/routes/data-export.d.ts +10 -10
- package/dist/types/routes/data-get.d.ts +14 -14
- package/dist/types/routes/data-import.d.ts +13 -13
- package/dist/types/routes/data-index-create.d.ts +51 -51
- package/dist/types/routes/data-index-delete.d.ts +17 -17
- package/dist/types/routes/data-index-list.d.ts +21 -21
- package/dist/types/routes/data-query.d.ts +49 -49
- package/dist/types/routes/data-reflect.d.ts +29 -29
- package/dist/types/routes/data-schema-get.d.ts +11 -11
- package/dist/types/routes/data-schema-set.d.ts +19 -19
- package/dist/types/routes/data-schema-test.d.ts +19 -19
- package/dist/types/routes/data-schemas-list.d.ts +11 -11
- package/dist/types/routes/data-set.d.ts +27 -27
- package/dist/types/routes/data-sync-changes.d.ts +25 -28
- package/dist/types/routes/data-sync-mutations.d.ts +25 -28
- package/dist/types/routes/data-transaction.d.ts +34 -34
- package/dist/types/routes/data-update.d.ts +27 -27
- package/dist/types/routes/data.d.ts +3 -3
- package/dist/types/routes/docs.d.ts +3 -3
- package/dist/types/routes/meta-info.d.ts +11 -11
- package/dist/types/routes/meta-logs.d.ts +20 -20
- package/dist/types/routes/meta-ping.d.ts +7 -7
- package/dist/types/routes/meta-stats.d.ts +13 -13
- package/dist/types/routes/meta.d.ts +3 -3
- package/dist/types/routes/oauth2-init.d.ts +13 -13
- package/dist/types/routes/oauth2-refresh.d.ts +17 -17
- package/dist/types/routes/oauth2-signin.d.ts +15 -15
- package/dist/types/routes/webmanager.d.ts +3 -3
- package/dist/types/rules.d.ts +73 -34
- package/dist/types/sandbox.d.ts +3 -0
- package/dist/types/schema/user.d.ts +85 -85
- package/dist/types/server.d.ts +117 -111
- package/dist/types/settings/email.d.ts +14 -14
- package/dist/types/settings/index.d.ts +195 -187
- package/dist/types/shared/clients.d.ts +46 -46
- package/dist/types/shared/email.d.ts +34 -34
- package/dist/types/shared/env.d.ts +47 -44
- package/dist/types/shared/error.d.ts +15 -15
- package/dist/types/shared/http.d.ts +22 -21
- package/dist/types/shared/password.d.ts +19 -19
- package/dist/types/shared/rootpath.d.ts +2 -2
- package/dist/types/shared/signin.d.ts +31 -31
- package/dist/types/shared/simple-fetch.d.ts +21 -21
- package/dist/types/shared/tokens.d.ts +24 -24
- package/dist/types/shared/validate.d.ts +22 -22
- package/dist/types/start.d.ts +1 -1
- package/dist/types/test.d.ts +1 -1
- package/dist/types/websocket/index.d.ts +6 -6
- package/dist/types/websocket/manager.d.ts +99 -99
- package/dist/types/websocket/socket.io.d.ts +10 -10
- package/package.json +4 -4
- package/src/routes/data-set.yaml +5 -5
- package/src/routes/data-update.yaml +4 -4
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.addMiddleware = void 0;
|
|
13
|
-
const error_1 = require("../shared/error");
|
|
14
|
-
const signin_1 = require("../shared/signin");
|
|
15
|
-
const tokens_1 = require("../shared/tokens");
|
|
16
|
-
const addMiddleware = (env) => {
|
|
17
|
-
// Add bearer authentication middleware
|
|
18
|
-
env.
|
|
19
|
-
let authorization = req.get('Authorization');
|
|
20
|
-
if (typeof authorization !== 'string' && 'auth_token' in req.query) {
|
|
21
|
-
// Enables browser calls to be authenticated by adding the access token as auth_token query parameter
|
|
22
|
-
if (req.path.startsWith('/export/') || req.path.startsWith('/logs')) {
|
|
23
|
-
// For now, only allow '/export' or '/logs' api calls
|
|
24
|
-
// In the future, use these prerequisites:
|
|
25
|
-
// - user must be currently authenticated (in cache)
|
|
26
|
-
// - ip address must match the token
|
|
27
|
-
authorization = 'Bearer ' + req.query.auth_token;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
if (typeof authorization === 'string' && authorization.startsWith('Bearer ')) {
|
|
31
|
-
const token = authorization.slice(7);
|
|
32
|
-
let tokenDetails;
|
|
33
|
-
try {
|
|
34
|
-
tokenDetails = (0, tokens_1.decodePublicAccessToken)(token, env.tokenSalt);
|
|
35
|
-
}
|
|
36
|
-
catch (err) {
|
|
37
|
-
return (0, error_1.sendNotAuthenticatedError)(res, 'invalid_token', 'The passed token is invalid. Sign in again');
|
|
38
|
-
}
|
|
39
|
-
// Is this token cached?
|
|
40
|
-
req.user = env.authCache.get(tokenDetails.uid);
|
|
41
|
-
if (!req.user) {
|
|
42
|
-
// Query database to get user for this token
|
|
43
|
-
try {
|
|
44
|
-
yield (0, signin_1.signIn)({ method: 'internal', access_token: tokenDetails.access_token }, env, req);
|
|
45
|
-
}
|
|
46
|
-
catch (err) {
|
|
47
|
-
return (0, error_1.sendNotAuthenticatedError)(res, err.code, err.message);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
if (req.user.is_disabled === true) {
|
|
51
|
-
return (0, error_1.sendNotAuthenticatedError)(res, 'account_disabled', 'Your account has been disabled. Contact your database administrator');
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
next();
|
|
55
|
-
}));
|
|
56
|
-
};
|
|
57
|
-
exports.addMiddleware = addMiddleware;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.addMiddleware = void 0;
|
|
13
|
+
const error_1 = require("../shared/error");
|
|
14
|
+
const signin_1 = require("../shared/signin");
|
|
15
|
+
const tokens_1 = require("../shared/tokens");
|
|
16
|
+
const addMiddleware = (env) => {
|
|
17
|
+
// Add bearer authentication middleware
|
|
18
|
+
env.router.use((req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
let authorization = req.get('Authorization');
|
|
20
|
+
if (typeof authorization !== 'string' && 'auth_token' in req.query) {
|
|
21
|
+
// Enables browser calls to be authenticated by adding the access token as auth_token query parameter
|
|
22
|
+
if (req.path.startsWith('/export/') || req.path.startsWith('/logs')) {
|
|
23
|
+
// For now, only allow '/export' or '/logs' api calls
|
|
24
|
+
// In the future, use these prerequisites:
|
|
25
|
+
// - user must be currently authenticated (in cache)
|
|
26
|
+
// - ip address must match the token
|
|
27
|
+
authorization = 'Bearer ' + req.query.auth_token;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (typeof authorization === 'string' && authorization.startsWith('Bearer ')) {
|
|
31
|
+
const token = authorization.slice(7);
|
|
32
|
+
let tokenDetails;
|
|
33
|
+
try {
|
|
34
|
+
tokenDetails = (0, tokens_1.decodePublicAccessToken)(token, env.tokenSalt);
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
return (0, error_1.sendNotAuthenticatedError)(res, 'invalid_token', 'The passed token is invalid. Sign in again');
|
|
38
|
+
}
|
|
39
|
+
// Is this token cached?
|
|
40
|
+
req.user = env.authCache.get(tokenDetails.uid);
|
|
41
|
+
if (!req.user) {
|
|
42
|
+
// Query database to get user for this token
|
|
43
|
+
try {
|
|
44
|
+
req.user = yield (0, signin_1.signIn)({ method: 'internal', access_token: tokenDetails.access_token }, env, req);
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
return (0, error_1.sendNotAuthenticatedError)(res, err.code, err.message);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (req.user.is_disabled === true) {
|
|
51
|
+
return (0, error_1.sendNotAuthenticatedError)(res, 'account_disabled', 'Your account has been disabled. Contact your database administrator');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
next();
|
|
55
|
+
}));
|
|
56
|
+
};
|
|
57
|
+
exports.addMiddleware = addMiddleware;
|
|
58
58
|
//# sourceMappingURL=user.js.map
|
|
@@ -1,110 +1,110 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.AuthProvider = exports.DropboxAuthProvider = void 0;
|
|
13
|
-
const oauth_provider_1 = require("./oauth-provider");
|
|
14
|
-
const simple_fetch_1 = require("../shared/simple-fetch");
|
|
15
|
-
class DropboxAuthProvider extends oauth_provider_1.OAuth2Provider {
|
|
16
|
-
constructor(settings) {
|
|
17
|
-
super(settings);
|
|
18
|
-
if (!settings.scopes) {
|
|
19
|
-
settings.scopes = [];
|
|
20
|
-
}
|
|
21
|
-
if (settings.scopes.length > 0 && !settings.scopes.includes('account_info.read')) {
|
|
22
|
-
settings.scopes.push('account_info.read');
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Starts auth flow by getting the url the user should be redirected to
|
|
27
|
-
* @param info.redirectUrl Url dropbox will redirect to after authorizing
|
|
28
|
-
* @param info.state Optional state that will be passed to redirectUri by dropbox
|
|
29
|
-
* @param info.options Optional Dropbox specific authentication settings
|
|
30
|
-
* @param info.options.require_role If this parameter is specified, the user will be asked to authorize with a particular type of Dropbox account, either work for a team account or personal for a personal account. Your app should still verify the type of Dropbox account after authorization since the user could modify or remove the require_role parameter.
|
|
31
|
-
* @param info.options.force_reapprove Whether or not to force the user to approve the app again if they've already done so. If false (default), a user who has already approved the application may be automatically redirected to the URI specified by redirect_uri. If true, the user will not be automatically redirected and will have to approve the app again.
|
|
32
|
-
* @param info.options.disable_signup When true (default is false) users will not be able to sign up for a Dropbox account via the authorization page. Instead, the authorization page will show a link to the Dropbox iOS app in the App Store. This is only intended for use when necessary for compliance with App Store policies.
|
|
33
|
-
* @param info.options.locale If the locale specified is a supported language, Dropbox will direct users to a translated version of the authorization website. Locale tags should be IETF language tags.
|
|
34
|
-
* @param info.options.force_reauthentication When true (default is false) users will be signed out if they are currently signed in. This will make sure the user is brought to a page where they can create a new account or sign in to another account. This should only be used when there is a definite reason to believe that the user needs to sign in to a new or different account.
|
|
35
|
-
*/
|
|
36
|
-
init(info) {
|
|
37
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
// Return url to get authorization code with
|
|
39
|
-
const options = info.options || {};
|
|
40
|
-
const authUrl = `https://www.dropbox.com/oauth2/authorize?response_type=code&token_access_type=offline&client_id=${this.settings.client_id}&scope=${encodeURIComponent(this.settings.scopes.join(' '))}&redirect_uri=${encodeURIComponent(info.redirect_url)}&locale=${options.locale || ''}&require_role=${options.require_role || ''}&force_reauthentication=${options.force_reauthentication === true}&force_reapprove=${options.force_reapprove === true}&disable_signup=${options.disable_signup === true}&state=${encodeURIComponent(info.state)}`;
|
|
41
|
-
return authUrl;
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
getAccessToken(params) {
|
|
45
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
// Request access & refresh tokens with authorization code
|
|
47
|
-
const response = yield (0, simple_fetch_1.fetch)('https://api.dropbox.com/oauth2/token', {
|
|
48
|
-
method: 'POST',
|
|
49
|
-
headers: {
|
|
50
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
51
|
-
},
|
|
52
|
-
body: `client_id=${this.settings.client_id}&client_secret=${this.settings.client_secret}` +
|
|
53
|
-
(params.type === 'refresh'
|
|
54
|
-
? `&grant_type=refresh_token&refresh_token=${params.refresh_token}`
|
|
55
|
-
: `&grant_type=authorization_code&code=${params.auth_code}&redirect_uri=${encodeURIComponent(params.redirect_url)}`),
|
|
56
|
-
});
|
|
57
|
-
if (response.status !== 200) {
|
|
58
|
-
// Handle error
|
|
59
|
-
const code = response.status;
|
|
60
|
-
const hasJSON = response.headers.get('Content-Type') === 'application/json';
|
|
61
|
-
const details = yield (hasJSON ? response.json() : response.text());
|
|
62
|
-
throw new Error(`${code}: ${hasJSON ? details.error_description ? `${details.error}, ${details.error_description}` : details.error_summary : details}`);
|
|
63
|
-
}
|
|
64
|
-
const result = yield response.json();
|
|
65
|
-
const secondsToExpiry = result.expires_in;
|
|
66
|
-
result.expires = new Date(Date.now() + (secondsToExpiry * 1000));
|
|
67
|
-
return result;
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
getUserInfo(access_token) {
|
|
71
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
-
const response = yield (0, simple_fetch_1.fetch)(`https://api.dropboxapi.com/2/users/get_current_account`, {
|
|
73
|
-
method: 'POST',
|
|
74
|
-
headers: {
|
|
75
|
-
'Authorization': `Bearer ${access_token}`,
|
|
76
|
-
},
|
|
77
|
-
});
|
|
78
|
-
if (response.status !== 200) {
|
|
79
|
-
const code = response.status;
|
|
80
|
-
const hasJSON = response.headers.get('Content-Type') === 'application/json';
|
|
81
|
-
const details = yield (hasJSON ? response.json() : response.text());
|
|
82
|
-
throw new Error(`${code}: ${hasJSON ? details.error_summary : details}`);
|
|
83
|
-
}
|
|
84
|
-
const result = yield response.json();
|
|
85
|
-
const user = result;
|
|
86
|
-
return {
|
|
87
|
-
id: user.account_id,
|
|
88
|
-
name: `${user.name.given_name} ${user.name.surname}`,
|
|
89
|
-
display_name: user.name.display_name,
|
|
90
|
-
picture: user.profile_photo_url ? [{ url: user.profile_photo_url }] : null,
|
|
91
|
-
email: user.email,
|
|
92
|
-
email_verified: user.email_verified,
|
|
93
|
-
other: {
|
|
94
|
-
account_type: user.account_type['.tag'],
|
|
95
|
-
disabled: user.disabled,
|
|
96
|
-
locale: user.locale,
|
|
97
|
-
country: user.country,
|
|
98
|
-
// include the following?
|
|
99
|
-
// referral_link: user.referral_link,
|
|
100
|
-
// team_id: user.team.id,
|
|
101
|
-
// team_name: user.team.name,
|
|
102
|
-
// team_member_id: user.team_member_id
|
|
103
|
-
},
|
|
104
|
-
};
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
exports.DropboxAuthProvider = DropboxAuthProvider;
|
|
109
|
-
exports.AuthProvider = DropboxAuthProvider;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AuthProvider = exports.DropboxAuthProvider = void 0;
|
|
13
|
+
const oauth_provider_1 = require("./oauth-provider");
|
|
14
|
+
const simple_fetch_1 = require("../shared/simple-fetch");
|
|
15
|
+
class DropboxAuthProvider extends oauth_provider_1.OAuth2Provider {
|
|
16
|
+
constructor(settings) {
|
|
17
|
+
super(settings);
|
|
18
|
+
if (!settings.scopes) {
|
|
19
|
+
settings.scopes = [];
|
|
20
|
+
}
|
|
21
|
+
if (settings.scopes.length > 0 && !settings.scopes.includes('account_info.read')) {
|
|
22
|
+
settings.scopes.push('account_info.read');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Starts auth flow by getting the url the user should be redirected to
|
|
27
|
+
* @param info.redirectUrl Url dropbox will redirect to after authorizing
|
|
28
|
+
* @param info.state Optional state that will be passed to redirectUri by dropbox
|
|
29
|
+
* @param info.options Optional Dropbox specific authentication settings
|
|
30
|
+
* @param info.options.require_role If this parameter is specified, the user will be asked to authorize with a particular type of Dropbox account, either work for a team account or personal for a personal account. Your app should still verify the type of Dropbox account after authorization since the user could modify or remove the require_role parameter.
|
|
31
|
+
* @param info.options.force_reapprove Whether or not to force the user to approve the app again if they've already done so. If false (default), a user who has already approved the application may be automatically redirected to the URI specified by redirect_uri. If true, the user will not be automatically redirected and will have to approve the app again.
|
|
32
|
+
* @param info.options.disable_signup When true (default is false) users will not be able to sign up for a Dropbox account via the authorization page. Instead, the authorization page will show a link to the Dropbox iOS app in the App Store. This is only intended for use when necessary for compliance with App Store policies.
|
|
33
|
+
* @param info.options.locale If the locale specified is a supported language, Dropbox will direct users to a translated version of the authorization website. Locale tags should be IETF language tags.
|
|
34
|
+
* @param info.options.force_reauthentication When true (default is false) users will be signed out if they are currently signed in. This will make sure the user is brought to a page where they can create a new account or sign in to another account. This should only be used when there is a definite reason to believe that the user needs to sign in to a new or different account.
|
|
35
|
+
*/
|
|
36
|
+
init(info) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
// Return url to get authorization code with
|
|
39
|
+
const options = info.options || {};
|
|
40
|
+
const authUrl = `https://www.dropbox.com/oauth2/authorize?response_type=code&token_access_type=offline&client_id=${this.settings.client_id}&scope=${encodeURIComponent(this.settings.scopes.join(' '))}&redirect_uri=${encodeURIComponent(info.redirect_url)}&locale=${options.locale || ''}&require_role=${options.require_role || ''}&force_reauthentication=${options.force_reauthentication === true}&force_reapprove=${options.force_reapprove === true}&disable_signup=${options.disable_signup === true}&state=${encodeURIComponent(info.state)}`;
|
|
41
|
+
return authUrl;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
getAccessToken(params) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
// Request access & refresh tokens with authorization code
|
|
47
|
+
const response = yield (0, simple_fetch_1.fetch)('https://api.dropbox.com/oauth2/token', {
|
|
48
|
+
method: 'POST',
|
|
49
|
+
headers: {
|
|
50
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
51
|
+
},
|
|
52
|
+
body: `client_id=${this.settings.client_id}&client_secret=${this.settings.client_secret}` +
|
|
53
|
+
(params.type === 'refresh'
|
|
54
|
+
? `&grant_type=refresh_token&refresh_token=${params.refresh_token}`
|
|
55
|
+
: `&grant_type=authorization_code&code=${params.auth_code}&redirect_uri=${encodeURIComponent(params.redirect_url)}`),
|
|
56
|
+
});
|
|
57
|
+
if (response.status !== 200) {
|
|
58
|
+
// Handle error
|
|
59
|
+
const code = response.status;
|
|
60
|
+
const hasJSON = response.headers.get('Content-Type') === 'application/json';
|
|
61
|
+
const details = yield (hasJSON ? response.json() : response.text());
|
|
62
|
+
throw new Error(`${code}: ${hasJSON ? details.error_description ? `${details.error}, ${details.error_description}` : details.error_summary : details}`);
|
|
63
|
+
}
|
|
64
|
+
const result = yield response.json();
|
|
65
|
+
const secondsToExpiry = result.expires_in;
|
|
66
|
+
result.expires = new Date(Date.now() + (secondsToExpiry * 1000));
|
|
67
|
+
return result;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
getUserInfo(access_token) {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
const response = yield (0, simple_fetch_1.fetch)(`https://api.dropboxapi.com/2/users/get_current_account`, {
|
|
73
|
+
method: 'POST',
|
|
74
|
+
headers: {
|
|
75
|
+
'Authorization': `Bearer ${access_token}`,
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
if (response.status !== 200) {
|
|
79
|
+
const code = response.status;
|
|
80
|
+
const hasJSON = response.headers.get('Content-Type') === 'application/json';
|
|
81
|
+
const details = yield (hasJSON ? response.json() : response.text());
|
|
82
|
+
throw new Error(`${code}: ${hasJSON ? details.error_summary : details}`);
|
|
83
|
+
}
|
|
84
|
+
const result = yield response.json();
|
|
85
|
+
const user = result;
|
|
86
|
+
return {
|
|
87
|
+
id: user.account_id,
|
|
88
|
+
name: `${user.name.given_name} ${user.name.surname}`,
|
|
89
|
+
display_name: user.name.display_name,
|
|
90
|
+
picture: user.profile_photo_url ? [{ url: user.profile_photo_url }] : null,
|
|
91
|
+
email: user.email,
|
|
92
|
+
email_verified: user.email_verified,
|
|
93
|
+
other: {
|
|
94
|
+
account_type: user.account_type['.tag'],
|
|
95
|
+
disabled: user.disabled,
|
|
96
|
+
locale: user.locale,
|
|
97
|
+
country: user.country,
|
|
98
|
+
// include the following?
|
|
99
|
+
// referral_link: user.referral_link,
|
|
100
|
+
// team_id: user.team.id,
|
|
101
|
+
// team_name: user.team.name,
|
|
102
|
+
// team_member_id: user.team_member_id
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.DropboxAuthProvider = DropboxAuthProvider;
|
|
109
|
+
exports.AuthProvider = DropboxAuthProvider;
|
|
110
110
|
//# sourceMappingURL=dropbox.js.map
|
|
@@ -1,86 +1,86 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.AuthProvider = exports.FacebookAuthProvider = void 0;
|
|
13
|
-
const oauth_provider_1 = require("./oauth-provider");
|
|
14
|
-
const simple_fetch_1 = require("../shared/simple-fetch");
|
|
15
|
-
class FacebookAuthProvider extends oauth_provider_1.OAuth2Provider {
|
|
16
|
-
constructor(settings) {
|
|
17
|
-
super(settings);
|
|
18
|
-
if (!settings.scopes) {
|
|
19
|
-
settings.scopes = [];
|
|
20
|
-
}
|
|
21
|
-
if (!settings.scopes.includes('email')) {
|
|
22
|
-
settings.scopes.push('email');
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Starts auth flow by getting the url the user should be redirected to
|
|
27
|
-
* @param info.redirectUrl Url spotify will redirect to after authorizing, should be the url
|
|
28
|
-
* @param info.state Optional state that will be passed to redirectUri by spotify
|
|
29
|
-
*/
|
|
30
|
-
init(info) {
|
|
31
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
// Return url to get authorization code with
|
|
33
|
-
const authUrl = `https://www.facebook.com/v7.0/dialog/oauth?response_type=code&client_id=${this.settings.client_id}&scope=${encodeURIComponent(this.settings.scopes.join(' '))}&redirect_uri=${encodeURIComponent(info.redirect_url)}&state=${encodeURIComponent(info.state)}`;
|
|
34
|
-
return authUrl;
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
getAccessToken(params) {
|
|
38
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
// Request access token with authorization code, or previously granted (short or long-lived) access_token
|
|
40
|
-
const url = `https://graph.facebook.com/v7.0/oauth/access_token?client_id=${this.settings.client_id}&client_secret=${this.settings.client_secret}` +
|
|
41
|
-
(params.type === 'refresh'
|
|
42
|
-
? `&grant_type=fb_exchange_token&fb_exchange_token=${params.refresh_token}`
|
|
43
|
-
: `&code=${params.auth_code}&redirect_uri=${encodeURIComponent(params.redirect_url)}`);
|
|
44
|
-
const response = yield (0, simple_fetch_1.fetch)(url);
|
|
45
|
-
const result = yield response.json();
|
|
46
|
-
if (result.error) {
|
|
47
|
-
const error = result.error;
|
|
48
|
-
throw new Error(`${error.type} ${error.code}: ${error.message}`);
|
|
49
|
-
}
|
|
50
|
-
const secondsToExpiry = result.expires_in;
|
|
51
|
-
result.expires = new Date(Date.now() + (secondsToExpiry * 1000));
|
|
52
|
-
// A short-lived access token can be exchanged for a long-lived (60 day) token.
|
|
53
|
-
// Not sure if a long-lived token can be used to get a new long-lived token,
|
|
54
|
-
// needs testing. See docs at: https://developers.facebook.com/docs/facebook-login/access-tokens/refreshing/
|
|
55
|
-
result.refresh_token = result.access_token;
|
|
56
|
-
return result;
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
getUserInfo(access_token) {
|
|
60
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
-
// TODO: Check if any requested scopes have not been granted access
|
|
62
|
-
// await fetch(`https://graph.facebook.com/v7.0/me/permissions`);
|
|
63
|
-
const response = yield (0, simple_fetch_1.fetch)(`https://graph.facebook.com/v7.0/me?fields=email,name,short_name,picture&access_token=${access_token}`);
|
|
64
|
-
const result = yield response.json();
|
|
65
|
-
if (response.status !== 200) {
|
|
66
|
-
const error = result;
|
|
67
|
-
throw new Error(`${error.code}: ${error.message}`);
|
|
68
|
-
}
|
|
69
|
-
const user = result;
|
|
70
|
-
return {
|
|
71
|
-
id: user.id,
|
|
72
|
-
name: user.name,
|
|
73
|
-
display_name: user.short_name,
|
|
74
|
-
picture: user.picture.data.is_silhouette ? null : [{ width: user.picture.data.width, height: user.picture.data.height, url: user.picture.data.url }],
|
|
75
|
-
email: user.email,
|
|
76
|
-
email_verified: typeof user.email === 'string',
|
|
77
|
-
other: {
|
|
78
|
-
// We haven't requested more, so we didn't get more
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
exports.FacebookAuthProvider = FacebookAuthProvider;
|
|
85
|
-
exports.AuthProvider = FacebookAuthProvider;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AuthProvider = exports.FacebookAuthProvider = void 0;
|
|
13
|
+
const oauth_provider_1 = require("./oauth-provider");
|
|
14
|
+
const simple_fetch_1 = require("../shared/simple-fetch");
|
|
15
|
+
class FacebookAuthProvider extends oauth_provider_1.OAuth2Provider {
|
|
16
|
+
constructor(settings) {
|
|
17
|
+
super(settings);
|
|
18
|
+
if (!settings.scopes) {
|
|
19
|
+
settings.scopes = [];
|
|
20
|
+
}
|
|
21
|
+
if (!settings.scopes.includes('email')) {
|
|
22
|
+
settings.scopes.push('email');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Starts auth flow by getting the url the user should be redirected to
|
|
27
|
+
* @param info.redirectUrl Url spotify will redirect to after authorizing, should be the url
|
|
28
|
+
* @param info.state Optional state that will be passed to redirectUri by spotify
|
|
29
|
+
*/
|
|
30
|
+
init(info) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
// Return url to get authorization code with
|
|
33
|
+
const authUrl = `https://www.facebook.com/v7.0/dialog/oauth?response_type=code&client_id=${this.settings.client_id}&scope=${encodeURIComponent(this.settings.scopes.join(' '))}&redirect_uri=${encodeURIComponent(info.redirect_url)}&state=${encodeURIComponent(info.state)}`;
|
|
34
|
+
return authUrl;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
getAccessToken(params) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
// Request access token with authorization code, or previously granted (short or long-lived) access_token
|
|
40
|
+
const url = `https://graph.facebook.com/v7.0/oauth/access_token?client_id=${this.settings.client_id}&client_secret=${this.settings.client_secret}` +
|
|
41
|
+
(params.type === 'refresh'
|
|
42
|
+
? `&grant_type=fb_exchange_token&fb_exchange_token=${params.refresh_token}`
|
|
43
|
+
: `&code=${params.auth_code}&redirect_uri=${encodeURIComponent(params.redirect_url)}`);
|
|
44
|
+
const response = yield (0, simple_fetch_1.fetch)(url);
|
|
45
|
+
const result = yield response.json();
|
|
46
|
+
if (result.error) {
|
|
47
|
+
const error = result.error;
|
|
48
|
+
throw new Error(`${error.type} ${error.code}: ${error.message}`);
|
|
49
|
+
}
|
|
50
|
+
const secondsToExpiry = result.expires_in;
|
|
51
|
+
result.expires = new Date(Date.now() + (secondsToExpiry * 1000));
|
|
52
|
+
// A short-lived access token can be exchanged for a long-lived (60 day) token.
|
|
53
|
+
// Not sure if a long-lived token can be used to get a new long-lived token,
|
|
54
|
+
// needs testing. See docs at: https://developers.facebook.com/docs/facebook-login/access-tokens/refreshing/
|
|
55
|
+
result.refresh_token = result.access_token;
|
|
56
|
+
return result;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
getUserInfo(access_token) {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
// TODO: Check if any requested scopes have not been granted access
|
|
62
|
+
// await fetch(`https://graph.facebook.com/v7.0/me/permissions`);
|
|
63
|
+
const response = yield (0, simple_fetch_1.fetch)(`https://graph.facebook.com/v7.0/me?fields=email,name,short_name,picture&access_token=${access_token}`);
|
|
64
|
+
const result = yield response.json();
|
|
65
|
+
if (response.status !== 200) {
|
|
66
|
+
const error = result;
|
|
67
|
+
throw new Error(`${error.code}: ${error.message}`);
|
|
68
|
+
}
|
|
69
|
+
const user = result;
|
|
70
|
+
return {
|
|
71
|
+
id: user.id,
|
|
72
|
+
name: user.name,
|
|
73
|
+
display_name: user.short_name,
|
|
74
|
+
picture: user.picture.data.is_silhouette ? null : [{ width: user.picture.data.width, height: user.picture.data.height, url: user.picture.data.url }],
|
|
75
|
+
email: user.email,
|
|
76
|
+
email_verified: typeof user.email === 'string',
|
|
77
|
+
other: {
|
|
78
|
+
// We haven't requested more, so we didn't get more
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.FacebookAuthProvider = FacebookAuthProvider;
|
|
85
|
+
exports.AuthProvider = FacebookAuthProvider;
|
|
86
86
|
//# sourceMappingURL=facebook.js.map
|