npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

oauth2boom

v1.0.3

Published

OAuth2.0 Errors using Boom

Downloads

16

Readme

OAuth2Boom

OAuth2.0 Errors using Boom

Build Status Current Version

Lead Maintainer: Andy Nguyen

Description

oauth2boom provides a set of utilities for returning OAuth 2.0 errors through Boom. Each utility returns a Boom error response. In addition to the Boom properties, the following property is added to the error response:

  • toURIFrag - function to transform the error into a URI fragment string.

The OAuth 2.0 errors are based off of the Yahoo OAuth 2.0 guide.

Helper Methods

create(errorCode, [message], [data])

Generates an Error object with the boom decorations where:

  • errorCode - an OAuth 2.0 error code.
  • message - optional message string that will override the preset message.
  • data - additional error data set to error.data property.
var error = OAuth2Boom.create('invalid_client', 'Bad request', { timestamp: Date.now() });

createNew(errorCode, [statusCode], [message], [data])

Generates an Error object with the boom decorations and a custom error code where:

  • errorCode - an error code.
  • statusCode - an HTTP error code number. Must be greater or equal 400.
  • message - optional message string that will override the preset message.
  • data - additional error data set to error.data property.
var error = OAuth2Boom.createNew('oauth_error', 400, 'Bad request', { timestamp: Date.now() });

wrap(error, [errorCode], [statusCode], [message])

Decorates an error with the boom properties and a toURIFrag method where:

  • error - the error object to wrap. If error is already a boom object, returns back the same object.
  • errorCode - optional error code that will override the error name set by Boom.
  • statusCode - optional HTTP status code. Defaults to 500.
  • message - optional message string. If the error already has a message, it adds the message as a prefix. Defaults to no message.
var error = new Error('Unexpected input');
OAuth2Boom.wrap(error, 'invalid_input');

HTTP 400 Errors

OAuth2Boom.invalidClient([message], [data])

Returns an invalid_client error where:

  • message - optional message string that will override the preset message.
  • data - optional additional error data.
OAuth2Boom.invalidClient();

Generates the following response payload:

{
    "statusCode": 400,
    "error": "invalid_client",
    "message": "An invalid client_id was provided."
}

OAuth2Boom.invalidRequest([message], [data])

Returns an invalid_request error where:

  • message - optional message string that will override the preset message.
  • data - optional additional error data.
OAuth2Boom.invalidRequest();

Generates the following response payload:

{
    "statusCode": 400,
    "error": "invalid_request",
    "message": "An invalid request parameter was provided."
}

OAuth2Boom.invalidParam([message], [data])

Returns an invalid_param error where:

  • message - optional message string that will override the preset message.
  • data - optional additional error data.
OAuth2Boom.invalidParam();

Generates the following response payload:

{
    "statusCode": 400,
    "error": "invalid_param",
    "message": "A provided request parameter is invalid."
}

OAuth2Boom.invalidRedirectURI([message], [data])

Returns an invalid_redirect_uri error where:

  • message - optional message string that will override the preset message.
  • data - optional additional error data.
OAuth2Boom.invalidRedirectURI();

Generates the following response payload:

{
    "statusCode": 400,
    "error": "invalid_redirect_uri",
    "message": "The provided redirect_uri does not match the one provided with the original authorization request."
}

OAuth2Boom.unsupportedOverHTTP([message], [data])

Returns an unsupported_over_http error where:

  • message - optional message string that will override the preset message.
  • data - optional additional error data.
OAuth2Boom.unsupportedOverHTTP();

Generates the following response payload:

{
    "statusCode": 400,
    "error": "unsupported_over_http",
    "message": "OAuth 2.0 only supports calls over HTTPS."
}

OAuth2Boom.unsupportedResponseType([message], [data])

Returns an unsupported_response_type error where:

  • message - optional message string that will override the preset message.
  • data - optional additional error data.
OAuth2Boom.unsupportedResponseType();

Generates the following response payload:

{
    "statusCode": 400,
    "error": "unsupported_response_type",
    "message": "The provided response_type is not supported for this request."
}

OAuth2Boom.unsupportedGrantType([message], [data])

Returns an unsupported_grant_type error where:

  • message - optional message string that will override the preset message.
  • data - optional additional error data.
OAuth2Boom.unsupportedGrantType();

Generates the following response payload:

{
    "statusCode": 400,
    "error": "unsupported_grant_type",
    "message": "The provided grant_type is not supported."
}

OAuth2Boom.unsupportedRedirectURI([message], [data])

Returns an unsupported_redirect_uri error where:

  • message - optional message string that will override the preset message.
  • data - optional additional error data.
OAuth2Boom.unsupportedRedirectURI();

Generates the following response payload:

{
    "statusCode": 400,
    "error": "unsupported_redirect_urie",
    "message": "The provided redirect_uri is not supported for this request type."
}

OAuth2Boom.versionRejected([message], [data])

Returns an version_rejected error where:

  • message - optional message string that will override the preset message.
  • data - optional additional error data.
OAuth2Boom.versionRejected();

Generates the following response payload:

{
    "statusCode": 400,
    "error": "version_rejected",
    "message": "An unsupported version of OAuth was supplied."
}

HTTP 401 Errors

OAuth2Boom.invalidToken([message], [data])

Returns an invalid_token error where:

  • message - optional message string that will override the preset message.
  • data - optional additional error data.
OAuth2Boom.invalidToken();

Generates the following response payload:

{
    "statusCode": 401,
    "error": "invalid_token",
    "message": "The provided token is invalid."
}

OAuth2Boom.invalidCallback([message], [data])

Returns an invalid_callback error where:

  • message - optional message string that will override the preset message.
  • data - optional additional error data.
OAuth2Boom.invalidCallback();

Generates the following response payload:

{
    "statusCode": 401,
    "error": "invalid_callback",
    "message": "The redirect_uri provided with this request uses an unsupported port or does not match the Client ID (Consumer Key)."
}

OAuth2Boom.invalidClientSecret([message], [data])

Returns an invalid_client_secret error where:

  • message - optional message string that will override the preset message.
  • data - optional additional error data.
OAuth2Boom.invalidClientSecret();

Generates the following response payload:

{
    "statusCode": 401,
    "error": "invalid_client_secret",
    "message": "An invalid client_secret was provided."
}

OAuth2Boom.invalidGrant([message], [data])

Returns an invalid_grant error where:

  • message - optional message string that will override the preset message.
  • data - optional additional error data.
OAuth2Boom.invalidGrant();

Generates the following response payload:

{
    "statusCode": 401,
    "error": "invalid_grant",
    "message": "An invalid or expired token was provided."
}

OAuth2Boom.tokenExpired([message], [data])

Returns a token_expired error where:

  • message - optional message string that will override the preset message.
  • data - optional additional error data.
OAuth2Boom.tokenExpired();

Generates the following response payload:

{
    "statusCode": 401,
    "error": "token_expired",
    "message": "The provided token has expired."
}

OAuth2Boom.unauthorizedClient([message], [data])

Returns an unauthorized_client error where:

  • message - optional message string that will override the preset message.
  • data - optional additional error data.
OAuth2Boom.unauthorizedClient();

Generates the following response payload:

{
    "statusCode": 401,
    "error": "unauthorized_client",
    "message": "The client application is not allowed to use this grant_type."
}