@baxcloud/parse-server-baxverify 1.0.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/LICENSE +21 -0
- package/README.md +98 -0
- package/dist/create.d.ts +34 -0
- package/dist/create.js +67 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/package.json +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 BaxCloud
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# @baxcloud/parse-server-baxverify
|
|
2
|
+
|
|
3
|
+
Parse Server custom auth adapter for **BaxVerify** phone login. Mobile clients verify SMS OTP with BaxVerify, then call `ParseUser.logInWith('baxverify', { id, token })`; Parse Server validates the proof JWT server-side.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @baxcloud/parse-server-baxverify parse-server
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Requires Node.js 18+. Your BaxCloud API key must stay on the Parse Server — never in mobile apps.
|
|
12
|
+
|
|
13
|
+
## Quick start
|
|
14
|
+
|
|
15
|
+
### 1. Environment
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
BAXCLOUD_PROJECT_ID=your-project-id
|
|
19
|
+
BAXCLOUD_API_KEY=your-api-key
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### 2. Parse Server config
|
|
23
|
+
|
|
24
|
+
```javascript
|
|
25
|
+
const { ParseServer } = require('parse-server');
|
|
26
|
+
|
|
27
|
+
new ParseServer({
|
|
28
|
+
databaseURI: process.env.DATABASE_URI,
|
|
29
|
+
appId: process.env.PARSE_APP_ID,
|
|
30
|
+
masterKey: process.env.PARSE_MASTER_KEY,
|
|
31
|
+
serverURL: process.env.PARSE_SERVER_URL,
|
|
32
|
+
auth: {
|
|
33
|
+
baxverify: {
|
|
34
|
+
module: '@baxcloud/parse-server-baxverify',
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### 3. Flutter client
|
|
41
|
+
|
|
42
|
+
After BaxVerify `verifyOtp`, pass `result.externalAuth` to Parse:
|
|
43
|
+
|
|
44
|
+
```dart
|
|
45
|
+
await ParseUser.logInWith('baxverify', result.externalAuth!);
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
See [Flutter BaxVerify SDK](../flutter-verify/README.md#parse-server) and [BaxCloud docs](https://baxcloud.tech/docs/baxverify/sdk/flutter#parse-server).
|
|
49
|
+
|
|
50
|
+
## Configuration options
|
|
51
|
+
|
|
52
|
+
You can pass credentials in Parse auth config instead of env vars:
|
|
53
|
+
|
|
54
|
+
```javascript
|
|
55
|
+
auth: {
|
|
56
|
+
baxverify: {
|
|
57
|
+
module: '@baxcloud/parse-server-baxverify',
|
|
58
|
+
projectId: process.env.BAXCLOUD_PROJECT_ID,
|
|
59
|
+
apiKey: process.env.BAXCLOUD_API_KEY,
|
|
60
|
+
consume: true, // default — single-use token on login
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
| Option | Description |
|
|
66
|
+
|--------|-------------|
|
|
67
|
+
| `projectId` | BaxCloud project ID (or `BAXCLOUD_PROJECT_ID`) |
|
|
68
|
+
| `apiKey` | BaxCloud API key (or `BAXCLOUD_API_KEY`) |
|
|
69
|
+
| `consume` | Consume JWT on login (default `true`) |
|
|
70
|
+
|
|
71
|
+
## Custom factory
|
|
72
|
+
|
|
73
|
+
For a local auth file or shared defaults:
|
|
74
|
+
|
|
75
|
+
```javascript
|
|
76
|
+
const { createBaxVerifyParseAuth } = require('@baxcloud/parse-server-baxverify/create');
|
|
77
|
+
|
|
78
|
+
module.exports = createBaxVerifyParseAuth({
|
|
79
|
+
projectId: process.env.BAXCLOUD_PROJECT_ID,
|
|
80
|
+
apiKey: process.env.BAXCLOUD_API_KEY,
|
|
81
|
+
});
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## How it works
|
|
85
|
+
|
|
86
|
+
1. Client sends OTP via BaxVerify (`@baxcloud/baxverify` on your API, or `baxcloud_verify_sdk` on Flutter).
|
|
87
|
+
2. Client verifies OTP and receives a short-lived `accessToken` (JWT proof).
|
|
88
|
+
3. Client calls `ParseUser.logInWith('baxverify', { id: phone, token: accessToken })`.
|
|
89
|
+
4. This adapter calls BaxVerify `validateVerificationToken`, checks phone matches `authData.id`, and stores `{ phone }` on the Parse User.
|
|
90
|
+
|
|
91
|
+
## Related
|
|
92
|
+
|
|
93
|
+
- [@baxcloud/baxverify](../node-verify/README.md) — BaxVerify Node.js SDK
|
|
94
|
+
- [BaxVerify docs](https://baxcloud.tech/docs/baxverify)
|
|
95
|
+
|
|
96
|
+
## License
|
|
97
|
+
|
|
98
|
+
MIT
|
package/dist/create.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** authData from ParseUser.logInWith('baxverify', { id, token }) */
|
|
2
|
+
interface BaxVerifyParseAuthData {
|
|
3
|
+
id?: string;
|
|
4
|
+
token?: string;
|
|
5
|
+
}
|
|
6
|
+
/** Fields from Parse Server auth.baxverify config (plus env fallbacks). */
|
|
7
|
+
interface BaxVerifyParseAuthOptions {
|
|
8
|
+
projectId?: string;
|
|
9
|
+
apiKey?: string;
|
|
10
|
+
/** Consume token on login (default true — single use). */
|
|
11
|
+
consume?: boolean;
|
|
12
|
+
module?: string;
|
|
13
|
+
}
|
|
14
|
+
interface BaxVerifyParseAuthProvider {
|
|
15
|
+
validateAuthData: (authData: BaxVerifyParseAuthData, options?: BaxVerifyParseAuthOptions) => Promise<Record<string, string>>;
|
|
16
|
+
validateAppId: (appIds?: string[], authData?: BaxVerifyParseAuthData) => Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Create a Parse Server auth adapter for BaxVerify phone login.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```js
|
|
24
|
+
* const { createBaxVerifyParseAuth } = require('@baxcloud/parse-server-baxverify/create');
|
|
25
|
+
*
|
|
26
|
+
* module.exports = createBaxVerifyParseAuth({
|
|
27
|
+
* projectId: process.env.BAXCLOUD_PROJECT_ID,
|
|
28
|
+
* apiKey: process.env.BAXCLOUD_API_KEY,
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
declare function createBaxVerifyParseAuth(defaults?: BaxVerifyParseAuthOptions): BaxVerifyParseAuthProvider;
|
|
33
|
+
|
|
34
|
+
export { type BaxVerifyParseAuthData, type BaxVerifyParseAuthOptions, type BaxVerifyParseAuthProvider, createBaxVerifyParseAuth };
|
package/dist/create.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/create.ts
|
|
21
|
+
var create_exports = {};
|
|
22
|
+
__export(create_exports, {
|
|
23
|
+
createBaxVerifyParseAuth: () => createBaxVerifyParseAuth
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(create_exports);
|
|
26
|
+
var import_baxverify = require("@baxcloud/baxverify");
|
|
27
|
+
function resolveConfig(defaults, parseOptions) {
|
|
28
|
+
return {
|
|
29
|
+
projectId: parseOptions?.projectId ?? defaults?.projectId ?? process.env.BAXCLOUD_PROJECT_ID,
|
|
30
|
+
apiKey: parseOptions?.apiKey ?? defaults?.apiKey ?? process.env.BAXCLOUD_API_KEY,
|
|
31
|
+
consume: parseOptions?.consume ?? defaults?.consume ?? true
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function createBaxVerifyParseAuth(defaults) {
|
|
35
|
+
return {
|
|
36
|
+
validateAppId: () => Promise.resolve(),
|
|
37
|
+
validateAuthData: async (authData, options) => {
|
|
38
|
+
const phone = authData?.id;
|
|
39
|
+
const token = authData?.token;
|
|
40
|
+
if (!phone || !token) {
|
|
41
|
+
throw new Error("BaxVerify authData requires id (phone) and token");
|
|
42
|
+
}
|
|
43
|
+
const config = resolveConfig(defaults, options);
|
|
44
|
+
if (!config.projectId?.trim() || !config.apiKey?.trim()) {
|
|
45
|
+
throw new Error(
|
|
46
|
+
"BaxVerify Parse auth requires projectId and apiKey (Parse auth options or BAXCLOUD_PROJECT_ID / BAXCLOUD_API_KEY env vars)"
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
const verify = new import_baxverify.BaxCloudVerifyClient({
|
|
50
|
+
projectId: config.projectId,
|
|
51
|
+
apiKey: config.apiKey
|
|
52
|
+
});
|
|
53
|
+
const proof = await verify.validateVerificationToken({
|
|
54
|
+
token,
|
|
55
|
+
consume: config.consume ?? true
|
|
56
|
+
});
|
|
57
|
+
if (proof.phone !== phone) {
|
|
58
|
+
throw new Error("BaxVerify phone does not match authData.id");
|
|
59
|
+
}
|
|
60
|
+
return { phone: proof.phone };
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
65
|
+
0 && (module.exports = {
|
|
66
|
+
createBaxVerifyParseAuth
|
|
67
|
+
});
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@baxcloud/parse-server-baxverify",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Parse Server custom auth adapter for BaxVerify phone login (SMS OTP)",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"require": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts"
|
|
11
|
+
},
|
|
12
|
+
"./create": {
|
|
13
|
+
"require": "./dist/create.js",
|
|
14
|
+
"types": "./dist/create.d.ts"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"README.md",
|
|
20
|
+
"LICENSE"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsup src/create.ts --format cjs --dts --clean && cp src/index.js src/index.d.ts dist/",
|
|
24
|
+
"dev": "tsup src/create.ts --format cjs --dts --watch",
|
|
25
|
+
"typecheck": "tsc --noEmit",
|
|
26
|
+
"prepublishOnly": "npm run build"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"baxcloud",
|
|
30
|
+
"baxverify",
|
|
31
|
+
"parse-server",
|
|
32
|
+
"parse",
|
|
33
|
+
"auth",
|
|
34
|
+
"sms",
|
|
35
|
+
"otp",
|
|
36
|
+
"phone",
|
|
37
|
+
"authentication"
|
|
38
|
+
],
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=18.0.0"
|
|
41
|
+
},
|
|
42
|
+
"license": "MIT",
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": "https://github.com/baxcloud/parse-server-baxverify",
|
|
46
|
+
"directory": "SDK/parse-server-baxverify"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"parse-server": ">=6.0.0"
|
|
50
|
+
},
|
|
51
|
+
"peerDependenciesMeta": {
|
|
52
|
+
"parse-server": {
|
|
53
|
+
"optional": true
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"@baxcloud/baxverify": "^1.0.0"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@types/node": "^20.0.0",
|
|
61
|
+
"tsup": "^8.0.0",
|
|
62
|
+
"typescript": "^5.3.0"
|
|
63
|
+
}
|
|
64
|
+
}
|