@oneaccount/express 0.1.1 → 0.1.2
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/dist/middleware/auth.js +21 -0
- package/dist/types/index.d.ts +8 -0
- package/package.json +1 -1
package/dist/middleware/auth.js
CHANGED
|
@@ -85,8 +85,29 @@ function createAuthMiddleware(config) {
|
|
|
85
85
|
const jwksUrl = config.jwksUrl ||
|
|
86
86
|
`${config.accountProUrl || "https://myaccount.one"}/.well-known/jwks.json`;
|
|
87
87
|
const cookieName = config.cookieName || "auth_token";
|
|
88
|
+
const autoSetCookie = config.autoSetCookie !== false; // Default to true
|
|
88
89
|
return async function authMiddleware(req, res, next) {
|
|
89
90
|
req.oneAccount = { user: null };
|
|
91
|
+
// Auto-set cookie from ?token= query parameter (SSO redirect handling)
|
|
92
|
+
if (autoSetCookie && req.query?.token && typeof req.query.token === 'string') {
|
|
93
|
+
const tokenFromUrl = req.query.token;
|
|
94
|
+
// Set the cookie
|
|
95
|
+
res.cookie(cookieName, tokenFromUrl, {
|
|
96
|
+
httpOnly: true,
|
|
97
|
+
secure: process.env.NODE_ENV === 'production',
|
|
98
|
+
maxAge: 30 * 24 * 60 * 60 * 1000, // 30 days
|
|
99
|
+
sameSite: 'lax',
|
|
100
|
+
path: '/',
|
|
101
|
+
});
|
|
102
|
+
// Build redirect URL without the token parameter
|
|
103
|
+
const url = new URL(req.originalUrl || req.url, `${req.protocol}://${req.get('host')}`);
|
|
104
|
+
url.searchParams.delete('token');
|
|
105
|
+
const redirectPath = url.pathname + url.search;
|
|
106
|
+
if (config.debug) {
|
|
107
|
+
console.log(`[OneAccount] Auto-set cookie from URL token, redirecting to ${redirectPath}`);
|
|
108
|
+
}
|
|
109
|
+
return res.redirect(redirectPath);
|
|
110
|
+
}
|
|
90
111
|
let token = null;
|
|
91
112
|
const authHeader = req.headers.authorization;
|
|
92
113
|
if (authHeader?.startsWith("Bearer ")) {
|
package/dist/types/index.d.ts
CHANGED
|
@@ -25,6 +25,14 @@ export interface OneAccountConfig {
|
|
|
25
25
|
cacheMaxAge?: number;
|
|
26
26
|
debug?: boolean;
|
|
27
27
|
cookieName?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Automatically set auth cookie from ?token= URL parameter (SSO redirect handling).
|
|
30
|
+
* When enabled (default: true), the middleware will:
|
|
31
|
+
* 1. Detect ?token= in the URL
|
|
32
|
+
* 2. Set it as an HttpOnly cookie
|
|
33
|
+
* 3. Redirect to the same URL without the token parameter
|
|
34
|
+
*/
|
|
35
|
+
autoSetCookie?: boolean;
|
|
28
36
|
}
|
|
29
37
|
export interface StripeConnectStatus {
|
|
30
38
|
hasAccount: boolean;
|