Skip to content

Consider refactoring registration authorization as a middleware #43

@dlongley

Description

@dlongley
          Moving this out for later refactoring and providing some context around what the "token" is and what it's for:
      if(cfg.registration.authorizationRequired.length > 0) {
        await _authorizeRegistration({req});
      }

Down below where helpers are defined:

async function _authorizeRegistration({req}) {
  const cfg = config['account-http'];
  const {authorizationRequired} = cfg.registration;
  const {authorization} = req.body;
  if(!(authorization?.type === authorizationRequired &&
    authorization.token)) {
    throw new BedrockError(
      `Authorization using "${authorizationRequired}" is required.`, {
        name: 'NotAllowedError',
        details: {
          httpStatusCode: 403,
          public: true
        }
    });
  }
  
  const remoteIp = req.socket.remoteAddress;
  await _verifyTurnstileToken({token: authorization.token, remoteIp});
}

Since the above fits the middleware pattern, I'll file an issue about potentially making this a middleware in the future.

I'm also not sure if using req.socket.remoteAddress is will work in deployment scenarios -- we'll need to figure that out before merging the PR to make sure we're pulling the IP from the right place.

Originally posted by @dlongley in #42 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions