@oneaccount/express 0.2.0 → 0.2.4
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 +2 -2
- package/dist/client/accountPro.js +1 -1
- package/dist/index.js +1 -1
- package/dist/middleware/auth.js +15 -3
- package/dist/middleware/buyerAuth.js +7 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ app.use(express.json());
|
|
|
20
20
|
// Initialize SDK
|
|
21
21
|
const oa = oneAccount({
|
|
22
22
|
apiKey: process.env.ONEACCOUNT_API_KEY,
|
|
23
|
-
accountProUrl: 'https://
|
|
23
|
+
accountProUrl: 'https://accountpro.replit.app', // optional
|
|
24
24
|
debug: true, // optional - logs auth errors
|
|
25
25
|
});
|
|
26
26
|
|
|
@@ -53,7 +53,7 @@ app.listen(3000);
|
|
|
53
53
|
| Option | Type | Default | Description |
|
|
54
54
|
|--------|------|---------|-------------|
|
|
55
55
|
| `apiKey` | string | required | Your OneAccount API key |
|
|
56
|
-
| `accountProUrl` | string | `https://
|
|
56
|
+
| `accountProUrl` | string | `https://accountpro.replit.app` | OneAccount server URL |
|
|
57
57
|
| `jwksUrl` | string | auto | JWKS endpoint URL (auto-derived from accountProUrl) |
|
|
58
58
|
| `debug` | boolean | `false` | Log authentication errors |
|
|
59
59
|
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AccountProClient = void 0;
|
|
4
4
|
class AccountProClient {
|
|
5
5
|
constructor(config) {
|
|
6
|
-
this.baseUrl = config.accountProUrl || "https://
|
|
6
|
+
this.baseUrl = config.accountProUrl || "https://accountpro.replit.app";
|
|
7
7
|
this.apiKey = config.apiKey;
|
|
8
8
|
this.debug = config.debug || false;
|
|
9
9
|
}
|
package/dist/index.js
CHANGED
|
@@ -12,7 +12,7 @@ function oneAccount(config) {
|
|
|
12
12
|
throw new Error("OneAccount SDK requires an API key");
|
|
13
13
|
}
|
|
14
14
|
const resolvedConfig = {
|
|
15
|
-
accountProUrl: config.accountProUrl || "https://
|
|
15
|
+
accountProUrl: config.accountProUrl || "https://accountpro.replit.app",
|
|
16
16
|
...config,
|
|
17
17
|
};
|
|
18
18
|
const authMiddleware = (0, auth_1.createAuthMiddleware)(resolvedConfig);
|
package/dist/middleware/auth.js
CHANGED
|
@@ -24,8 +24,12 @@ async function fetchJWKS(jwksUrl) {
|
|
|
24
24
|
return cachedJWKS;
|
|
25
25
|
}
|
|
26
26
|
function rsaPublicKeyFromJWK(jwk) {
|
|
27
|
-
|
|
28
|
-
const
|
|
27
|
+
// Convert base64url to base64 (some Node versions don't support base64url directly)
|
|
28
|
+
const base64urlToBase64 = (str) => {
|
|
29
|
+
return str.replace(/-/g, '+').replace(/_/g, '/');
|
|
30
|
+
};
|
|
31
|
+
const n = Buffer.from(base64urlToBase64(jwk.n), "base64");
|
|
32
|
+
const e = Buffer.from(base64urlToBase64(jwk.e), "base64");
|
|
29
33
|
const nLen = n.length;
|
|
30
34
|
const eLen = e.length;
|
|
31
35
|
const nLenBytes = nLen < 128
|
|
@@ -83,7 +87,7 @@ function extractTokenFromCookies(cookieHeader, cookieName) {
|
|
|
83
87
|
}
|
|
84
88
|
function createAuthMiddleware(config) {
|
|
85
89
|
const jwksUrl = config.jwksUrl ||
|
|
86
|
-
`${config.accountProUrl || "https://
|
|
90
|
+
`${config.accountProUrl || "https://accountpro.replit.app"}/.well-known/jwks.json`;
|
|
87
91
|
const cookieName = config.cookieName || "auth_token";
|
|
88
92
|
const autoSetCookie = config.autoSetCookie !== false; // Default to true
|
|
89
93
|
return async function authMiddleware(req, res, next) {
|
|
@@ -135,6 +139,14 @@ function createAuthMiddleware(config) {
|
|
|
135
139
|
return next();
|
|
136
140
|
}
|
|
137
141
|
const publicKey = rsaPublicKeyFromJWK(key);
|
|
142
|
+
if (config.debug) {
|
|
143
|
+
console.log("[OneAccount] Public key generated:", {
|
|
144
|
+
keyType: typeof publicKey,
|
|
145
|
+
keyLength: publicKey?.length,
|
|
146
|
+
startsWithPem: publicKey?.startsWith('-----BEGIN'),
|
|
147
|
+
kid: key.kid
|
|
148
|
+
});
|
|
149
|
+
}
|
|
138
150
|
const payload = jsonwebtoken_1.default.verify(token, publicKey, {
|
|
139
151
|
algorithms: ["RS256"],
|
|
140
152
|
});
|
|
@@ -23,8 +23,12 @@ async function fetchJWKS(jwksUrl) {
|
|
|
23
23
|
return cachedJWKS;
|
|
24
24
|
}
|
|
25
25
|
function rsaPublicKeyFromJWK(jwk) {
|
|
26
|
-
|
|
27
|
-
const
|
|
26
|
+
// Convert base64url to base64 (some Node versions don't support base64url directly)
|
|
27
|
+
const base64urlToBase64 = (str) => {
|
|
28
|
+
return str.replace(/-/g, '+').replace(/_/g, '/');
|
|
29
|
+
};
|
|
30
|
+
const n = Buffer.from(base64urlToBase64(jwk.n), "base64");
|
|
31
|
+
const e = Buffer.from(base64urlToBase64(jwk.e), "base64");
|
|
28
32
|
const nLen = n.length;
|
|
29
33
|
const eLen = e.length;
|
|
30
34
|
const nLenBytes = nLen < 128
|
|
@@ -70,7 +74,7 @@ function rsaPublicKeyFromJWK(jwk) {
|
|
|
70
74
|
}
|
|
71
75
|
function createBuyerAuthMiddleware(config) {
|
|
72
76
|
const jwksUrl = config.jwksUrl ||
|
|
73
|
-
`${config.accountProUrl || "https://
|
|
77
|
+
`${config.accountProUrl || "https://accountpro.replit.app"}/.well-known/jwks.json`;
|
|
74
78
|
return async function buyerAuthMiddleware(req, _res, next) {
|
|
75
79
|
req.buyer = null;
|
|
76
80
|
const authHeader = req.headers.authorization;
|