How to use the @hapi/boom.unauthorized function in @hapi/boom

To help you get started, we’ve selected a few @hapi/boom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hapijs / hapi / test / auth.js View on Github external
}

            const parts = authorization.split(/\s+/);
            if (parts.length !== 2) {
                return h.continue;          // Error without error or credentials
            }

            const username = parts[1];
            const credentials = settings.users[username];

            if (!credentials) {
                throw Boom.unauthorized('Missing credentials', 'Custom');
            }

            if (credentials === 'skip') {
                return h.unauthenticated(Boom.unauthorized(null, 'Custom'));
            }

            if (typeof credentials === 'string') {
                return h.response(credentials).takeover();
            }

            credentials.user = credentials.user || null;
            return h.authenticated({ credentials, artifacts: settings.artifacts });
        },
        response: (request, h) => {
github elitan / hasura-backend-plus / src / auth / auth.js View on Github external
}
    ) {
      affected_rows
    }
  }
  `;

  let hasura_data;
  try {
    hasura_data = await graphql_client.request(mutation, {
      user_id: user.id,
    });
  } catch (e) {
    console.error(e);
    // console.error('Error connection to GraphQL');
    return next(Boom.unauthorized('Unable to delete refresh token'));
  }

  res.send('OK');
});
github hapijs / bell / examples / okta.js View on Github external
handler: function (request, h) {

                if (!request.auth.isAuthenticated) {
                    throw Boom.unauthorized('Authentication failed: ' + request.auth.error.message);
                }

                // Just store the third party credentials in the session as an example. You could do something
                // more useful here - like loading or setting up an account (social signup).

                request.auth.session.set(request.auth.credentials);
                return h.redirect('/');
            }
        }
github mattboutet / user-pal / lib / services / user.js View on Github external
async changePassword(id, { password, newPassword }, trx) {

        const { Users } = this.server.models();

        const foundUser = await Users.query(trx).throwIfNotFound().findById(id);

        const result = await this.pwd.verify(Buffer.from(password), foundUser.password);

        //Unrecognized hash is a pain/contrived to generate, don't bother
        // $lab:coverage:off$
        if (result === SecurePassword.INVALID ||
            result === SecurePassword.INVALID_UNRECOGNIZED_HASH) {
            // $lab:coverage:on$

            throw Boom.unauthorized('Invalid Password');
        }

        return await this.setPassword(id, newPassword, trx);
    }
github dherault / serverless-offline / src / events / http / createAuthScheme.js View on Github external
// Set the credentials for the rest of the pipeline
        // return resolve(
        return h.authenticated({
          credentials: {
            authorizer,
            context: policy.context,
            principalId: policy.principalId,
            usageIdentifierKey: policy.usageIdentifierKey,
          },
        })
      } catch (err) {
        serverlessLog(
          `Authorization function returned an error response: (λ: ${authFunName})`,
        )

        return Boom.unauthorized('Unauthorized')
      }
    },
  })
github hapijs / hapi / test / auth.js View on Github external
imp.verify = async (auth) => {

                    await Hoek.wait(1);
                    if (auth.credentials.user !== 'steve') {
                        throw Boom.unauthorized('Invalid');
                    }
                };
github hapipal / toys / test / index.js View on Github external
handler: () => {

                        throw Boom.unauthorized('Original message');
                    },
                    ext: {
github lelylan / simple-oauth2 / test / _authorization-server-mock.js View on Github external
function tokenAuthorizationError(scopeOptions, params) {
    return nock(authorizationServerUrl, scopeOptions)
      .post('/oauth/token', params)
      .reply(401, Boom.unauthorized(), {
        'Content-Type': 'application/json',
      });
  }
github hapijs / hapi / test / auth.js View on Github external
                return { authenticate: (request, h) => h.unauthenticated(Boom.unauthorized(), { credentials: { user: 'steve' } }) };
            };
github superchargejs / framework / auth / schemes / session.js View on Github external
async authenticate (request, h) {
    const { credentials, artifacts } = await this.strategy.validate(request, h)

    if (credentials) {
      return h.authenticated({ credentials, artifacts })
    }

    return h.unauthenticated(Boom.unauthorized(null, SessionScheme.name))
  }
}