Skip to content

WIP: Major Refactor#56

Open
coolaj86 wants to merge 94 commits intotherootcompany:mainfrom
paperos-labs:libauth
Open

WIP: Major Refactor#56
coolaj86 wants to merge 94 commits intotherootcompany:mainfrom
paperos-labs:libauth

Conversation

@coolaj86
Copy link
Contributor

I broke everything down into pluggable, debuggable component pieces:

Before:

auth3000.google(opts);
app.use('/api/authn/', auth3000);

After

  app.use("/api/authn/", libauth.initialize());

  app.post(
    "/api/authn/session/credentials",
    libauth.credentials(),
    MyDB.getUserClaimsByPassword,
    libauth.newSession(),
    libauth.setClaims(),
    libauth.setTokens(),
    libauth.setCookie(),
    MyDB.updateSessionId,
    libauth.setCookieHeader(),
    libauth.sendTokens(),
  );

  // Magic Link
  app.post(
    "/api/authn/challenge/order",
    magic.setOrderParams,
    magic.newLink,
    magic.storeOrder,
    MyDB.notify,
    magic.sendOrder,
  );

  app.get(
    "/api/authn/challenge/status",
    magic.setOrderParams,
    magic.getOrderById, // TODO status
    magic.checkStatus,
    magic.sendReceipt,
  );

  app.post(
    // "/api/authn/session/magic/link",
    "/api/authn/challenge/finalize",
    magic.setOrderParams,
    magic.getOrderById, // TODO status
    magic.verifyOrder,
    magic.storeOrder,
    magic.catchFailure,
    MyDB.getUserClaimsByIdentifier,
    libauth.newSession(),
    libauth.setClaims(),
    libauth.setTokens(),
    libauth.setCookie(),
    MyDB.updateSessionId,
    libauth.setCookieHeader(),
    libauth.sendTokens(),
  );

  // Google Sign In
  let googleOidc = libauth.oidc(
    require("../plugins/oidc-google/")({
      clientId: process.env.GOOGLE_CLIENT_ID,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET,
      // TODO handle url relative to issuer
      //redirectUri: "/api/authn/session/oidc/accounts.google.com/redirect",
    }),
  );
  app.get(
    //"/api/authn/oidc/accounts.google.com/authorization_redirect",
    "/api/authn/session/oidc/accounts.google.com/redirect",
    googleOidc.authorizationRedirect,
    googleOidc.exchangeCode,
    googleOidc.exchangeToken,
    MyDB.getUserClaimsByOidcEmail,
    libauth.newSession(),
    libauth.setClaims(),
    libauth.setTokens(),
    libauth.setCookie(),
    MyDB.updateSessionId,
    libauth.setCookieHeader(),
    libauth.redirectWithTokens("/my-account"),
  );
  app.post(
    "/api/authn/session/oidc/accounts.google.com/token",
    googleOidc.exchangeToken,
    MyDB.getUserClaimsByOidcEmail,
    libauth.newSession(),
    libauth.setClaims(),
    libauth.setTokens(),
    libauth.setCookie(),
    MyDB.updateSessionId,
    libauth.setCookieHeader(),
    libauth.sendTokens(),
  );

I believe all the routes are ready, but it needs just a little finalization of route names and tests need to be rerun.

@socket-security
Copy link

socket-security bot commented Sep 24, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant