React-native-auth0: a0.response.invalid: unknown error using expired token

Created on 8 Oct 2019  路  4Comments  路  Source: auth0/react-native-auth0

Description

When accessing the authentication endpoint /userinfo with an expired access token the error is reported up to the client incorrectly as a0.response.invalid: unknown error
The error is not unknown, the WWW-Authenticate response header actually contains more details of the error

WWW-Authenticate: Bearer realm="Users", error="invalid_token", error_description="The token has expired"

It would be helpful if the client raised the correct AuthError

Reproduction

const auth0 = new Auth0({
  domain: Config.AUTH_CLIENT_DOMAIN,
  clientId: Config.AUTH_CLIENT_ID
});

const user = await auth0
  .auth
  .userInfo({expired_token});


Environment

Please provide the following:

react-native-auth0: master (e8da8e0b053649af020cdd7018dfc91ef6e8eef1)
react-native 60.5
iOS 13

bug

All 4 comments

I thought we covered that with https://github.com/auth0/react-native-auth0/pull/228 already. The code is correctly parsing it as an AuthError here. Seems the problem is that this particular endpoint does not fail with a JSON object but with that header you shared. I'll try to reproduce it and see how we can improve the catch. Thanks for opening this 馃挴

Can confirm this behavior. Expired or otherwise invalid token throws that unknown error. Handling is here:

https://github.com/auth0/react-native-auth0/blob/master/src/auth/index.js#L262-L264

AuthError is here:

https://github.com/auth0/react-native-auth0/blob/master/src/auth/authError.js

It tries to get the error information from returned body JSON which, in the case of userinfo, is not there. Response is Unauthorized with the error in the header (as @raldred mentioned). This call probably needs a custom handler.

Edit: Just realized that's exactly what you typed @lbalmaceda 馃槅 glad we came to the same conclusion here 馃憤

hehe. Thanks for reproducing @joshcanhelp ! Will take care of it as soon as I have some spare time

@raldred thanks for reporting this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yuyaohshimo picture yuyaohshimo  路  3Comments

Bardiamist picture Bardiamist  路  8Comments

dronsfield picture dronsfield  路  7Comments

anderslemke picture anderslemke  路  9Comments

robwalkerco picture robwalkerco  路  10Comments