@oneaccount/express 0.1.0 → 0.1.1

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.
@@ -69,16 +69,35 @@ function rsaPublicKeyFromJWK(jwk) {
69
69
  const pem = `-----BEGIN PUBLIC KEY-----\n${der.toString("base64").match(/.{1,64}/g)?.join("\n")}\n-----END PUBLIC KEY-----`;
70
70
  return pem;
71
71
  }
72
+ function extractTokenFromCookies(cookieHeader, cookieName) {
73
+ if (!cookieHeader)
74
+ return null;
75
+ const cookies = cookieHeader.split(';').map(c => c.trim());
76
+ for (const cookie of cookies) {
77
+ const [name, ...valueParts] = cookie.split('=');
78
+ if (name === cookieName) {
79
+ return valueParts.join('=');
80
+ }
81
+ }
82
+ return null;
83
+ }
72
84
  function createAuthMiddleware(config) {
73
85
  const jwksUrl = config.jwksUrl ||
74
86
  `${config.accountProUrl || "https://myaccount.one"}/.well-known/jwks.json`;
87
+ const cookieName = config.cookieName || "auth_token";
75
88
  return async function authMiddleware(req, res, next) {
76
89
  req.oneAccount = { user: null };
90
+ let token = null;
77
91
  const authHeader = req.headers.authorization;
78
- if (!authHeader?.startsWith("Bearer ")) {
92
+ if (authHeader?.startsWith("Bearer ")) {
93
+ token = authHeader.substring(7);
94
+ }
95
+ else {
96
+ token = extractTokenFromCookies(req.headers.cookie, cookieName);
97
+ }
98
+ if (!token) {
79
99
  return next();
80
100
  }
81
- const token = authHeader.substring(7);
82
101
  try {
83
102
  const decoded = jsonwebtoken_1.default.decode(token, { complete: true });
84
103
  if (!decoded) {
@@ -24,6 +24,7 @@ export interface OneAccountConfig {
24
24
  jwksUrl?: string;
25
25
  cacheMaxAge?: number;
26
26
  debug?: boolean;
27
+ cookieName?: string;
27
28
  }
28
29
  export interface StripeConnectStatus {
29
30
  hasAccount: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oneaccount/express",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "OneAccount SDK for Express.js - Authentication, entitlements, and Stripe Connect",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",