@kne/fastify-oidc 0.1.18 → 0.1.19
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/libs/idp/create-provider.js +24 -2
- package/package.json +1 -1
|
@@ -272,9 +272,31 @@ module.exports = async ({ fastify, options, identity, translator, jwks, getLocal
|
|
|
272
272
|
}
|
|
273
273
|
return globalThis.fetch(url, init);
|
|
274
274
|
},
|
|
275
|
+
// 浏览器授权失败(如 interaction 过期)时不要吐 JSON;跳 SPA 回调页由前端引导重新登录。
|
|
276
|
+
// 纯 API 客户端(Accept 只要 JSON、不要 HTML)仍返回 JSON。
|
|
275
277
|
renderError: async (ctx, out) => {
|
|
276
|
-
ctx.
|
|
277
|
-
|
|
278
|
+
const accept = String(ctx.get('accept') || '');
|
|
279
|
+
const wantsJson = accept.includes('application/json') && !accept.includes('text/html');
|
|
280
|
+
if (wantsJson) {
|
|
281
|
+
ctx.type = 'json';
|
|
282
|
+
ctx.body = out;
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
const params = new URLSearchParams();
|
|
286
|
+
if (out.error) {
|
|
287
|
+
params.set('error', out.error);
|
|
288
|
+
}
|
|
289
|
+
if (out.error_description) {
|
|
290
|
+
params.set('error_description', out.error_description);
|
|
291
|
+
}
|
|
292
|
+
if (out.state) {
|
|
293
|
+
params.set('state', out.state);
|
|
294
|
+
}
|
|
295
|
+
const path = options.errorRedirectPath || '/oidc-callback';
|
|
296
|
+
const target = new URL(path, `${runtime.issuerOrigin}/`);
|
|
297
|
+
target.search = params.toString();
|
|
298
|
+
ctx.status = 303;
|
|
299
|
+
ctx.redirect(target.toString());
|
|
278
300
|
}
|
|
279
301
|
};
|
|
280
302
|
|