openid / openid/AppAuth-JS

Improved error handling for NodeRequestor

Open
#120 5 comments 6 reactions 1 assignee View on GitHub

@tikurahul is already working on this.

Since Sep 4, 2019.

bug
Dominant language
TypeScript
Stars
1k
Forks
165
PR merge metrics
No merged PRs in 30d

Description

Expected Behavior

Describe expected behavior

Failing requests to /token endpoint (status code 400) should reject with the full error returned by the client in the body of the request. The body contains information for the reason of a failing request (eg. refresh_token expired, client authentication not successful)

Describe the problem

Currently the requestors rejects with new AppAuthError(statusMessage) (FetchRequestor rejects with new AppAuthError(statusCode, statusMessage)).
As the app does not receive the error response (see RFC 6749 section 5.2) it can't handle accordingly.

Actual Behavior

NodeRequestor rejects with Bad Request only.

Steps to reproduce the behavior

Issue a Token Request with an invalid authorization code:

const requestor = new NodeRequestor();
const tokenHandler = new BaseTokenRequestHandler(requestor);
const request = new TokenRequest({
  client_id: idpConfig.clientId,
  redirect_uri: idpConfig.redirectUri,
  grant_type: GRANT_TYPE_AUTHORIZATION_CODE,
  code: 'INVALID CODE',
  refresh_token: undefined,
  extras: extras
});

tokenHandler.performTokenRequest(serviceConfiguration, request)
  .then(response => {})
  .catch(err => {
    //err is {message:'Bad Request'},
    //err should be {message: 'Bad Request', code: 400, body: { error: 'invalid_grant', error_description: 'Malformed auth code.' }}
  });
Environment
  • AppAuth-JS version: 1.2.4
  • AppAuth-JS Environment: Node (also applicable for Browser in JQueryRequestor and FetchRequestor )

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.