ekyc

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

userinfo.tsx (709B)


      1 import { AppState } from "#http/routes/_middleware.ts";
      2 import { Handlers } from "$fresh/server.ts";
      3 
      4 const BEARER = /^bearer (.+)$/i;
      5 
      6 export const handler: Handlers<void, AppState> = {
      7   async GET(req, ctx) {
      8     const { oauth2UserInfo } = ctx.state.app;
      9     const authorization = req.headers.get("authorization");
     10     if (!authorization) {
     11       return new Response(null, { status: 400 });
     12     }
     13     const match = authorization.match(BEARER);
     14     if (match === null) {
     15       return new Response(null, { status: 400 });
     16     }
     17     const accessToken = match[1];
     18     const result = await oauth2UserInfo.execute({ accessToken });
     19     return Response.json(result, { status: result.exists ? 200 : 404 });
     20   },
     21 };