ekyc

Electronic KYC process with uploading ID document using OAuth 2.1 (experimental)
Log | Files | Refs | README | LICENSE

callback.tsx (840B)


      1 import { AppState } from "#http/routes/_middleware.ts";
      2 import { Handlers } from "$fresh/server.ts";
      3 import { unreachable } from "$std/assert/unreachable.ts";
      4 
      5 export const handler: Handlers<void, AppState<"/oauth2/callback">> = {
      6   async GET(_req, ctx) {
      7     const { app, forms, formContext } = ctx.state;
      8     const { oauth2Authorize } = app;
      9 
     10     if (formContext === null) {
     11       return forms.redirect({ form: "/connect", context: { back: "/" } });
     12     }
     13 
     14     const { flowId, clientId } = formContext;
     15     if (forms.session === null) {
     16       return unreachable();
     17     }
     18 
     19     const result = await oauth2Authorize.execute({
     20       clientId,
     21       flowId,
     22       resourceOwner: forms.session.uuid,
     23     });
     24 
     25     if (result.authorized) {
     26       return Response.redirect(result.redirectUri!, 303);
     27     }
     28 
     29     return ctx.renderNotFound();
     30   },
     31 };