Giter VIP home page Giter VIP logo

oauth2-errors's Introduction

Oauth2-Errors Build Status

Introduction

Error classes and handler for Oauth 2.0 spec errors. Was patterned after the well-known http-errors lib.

Getting Started

Install the module with: npm install oauth2-errors

const OauthErrors = require('oauth2-errors');

Errors

Follows the Oauth 2.0 Spec for errors, see here

  • InvalidClient - invalid_client
  • InvalidGrant - invalid_grant
  • InvalidRequest - invalid_request
  • InvalidScope - invalid_scope
  • UnauthorizedClient - unauthorized_client
  • UnauthorizedGrantType - unauthorized_grant_type

And Authorization Errors:

  • AccessDenied - access_denied
  • UnsupportedResponseType - unsupported_response_type
  • ServerError - server_error
  • TemporarilyUnavailable - temporarily_unavailable

Usage

Each error is a class, so can be instantiated by calling new.

const invalidGrantError = new OauthErrors.InvalidGrant()

Each class can optionally take a params argument with 2 optional properties:

  • description - error_description
  • uri - error_uri
const invalidRequestError = new OauthErrors.InvalidRequest({
  description: 'more description this bad request', 
  uri: 'https://mydomain.com/invalid_request'
})

Methods

  • toString

    • Creates a JSON string with the following properties:
      • error
      • error_description - [optional]
      • error_uri - [optional]
  • respond

    • ExpressJS convenience response handler
    • Takes the ExpressJS response as the sole argument

Examples

const OauthErrors = require('oauth2-errors');
...

// Using the respond convenience fn
function authorize(req, res, next) {

  if (invalidClient()) {
    const invalidClientErr = new OauthErrors.InvalidClient()
    return invalidClientErr.respond(res)
  }
}

Release History

  • v1.0.0 - Initial Release - April 13, 2018
  • v1.0.1 - Update compilation - April 13, 2018
  • v1.0.2 - Improve tests - April 13, 2018
  • v1.0.3 - Add authorization errors - April 14, 2018

License

Copyright (c) 2018 Richard Lucas. Licensed under the MIT license.

oauth2-errors's People

Contributors

ralucas avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

oauth2-errors's Issues

401 and 403 status errors?

Hi Richard,
Fabulous library! The only thing that gives me pause is - why hardcode the http status code at 400 for all the errors? Some of them are traditionally 401 (invalid_token, invalid_client_secret etc) and 403.
Would you be open to a PR that adjusts that?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.