diff --git a/packages/core/src/errors/RequestError.ts b/packages/core/src/errors/RequestError.ts index d07d04fb6..c904ccd4e 100644 --- a/packages/core/src/errors/RequestError.ts +++ b/packages/core/src/errors/RequestError.ts @@ -4,15 +4,20 @@ export enum GuardErrorCode { InvalidInput = 'guard.invalid_input', } +export enum OidcErrorCode { + Aborted = 'oidc.aborted', +} + export enum RegisterErrorCode { UsernameExists = 'register.username_exists', } -export type RequestErrorCode = GuardErrorCode | RegisterErrorCode; +export type RequestErrorCode = GuardErrorCode | OidcErrorCode | RegisterErrorCode; const requestErrorMessage: Record = { - [RegisterErrorCode.UsernameExists]: 'The username already exists.', [GuardErrorCode.InvalidInput]: 'The request input is invalid.', + [OidcErrorCode.Aborted]: 'The end-user aborted interaction.', + [RegisterErrorCode.UsernameExists]: 'The username already exists.', }; export type RequestErrorMetadata = { diff --git a/packages/core/src/routes/sign-in.ts b/packages/core/src/routes/sign-in.ts index a88e25526..a81acf206 100644 --- a/packages/core/src/routes/sign-in.ts +++ b/packages/core/src/routes/sign-in.ts @@ -6,6 +6,7 @@ import { findUserById } from '@/queries/user'; import { Provider } from 'oidc-provider'; import { conditional } from '@logto/essentials'; import koaGuard from '@/middleware/koa-guard'; +import { OidcErrorCode } from '@/errors/RequestError'; export default function createSignInRoutes(provider: Provider) { const router = new Router(); @@ -82,5 +83,13 @@ export default function createSignInRoutes(provider: Provider) { ctx.body = { redirectTo }; }); + router.post('/sign-in/abort', async (ctx) => { + await provider.interactionDetails(ctx.req, ctx.res); + const redirectTo = await provider.interactionResult(ctx.req, ctx.res, { + error: OidcErrorCode.Aborted, + }); + ctx.body = { redirectTo }; + }); + return router.routes(); }