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
const auth0 = new Auth0({
domain: Config.AUTH_CLIENT_DOMAIN,
clientId: Config.AUTH_CLIENT_ID
});
const user = await auth0
.auth
.userInfo({expired_token});
Please provide the following:
react-native-auth0: master (e8da8e0b053649af020cdd7018dfc91ef6e8eef1)
react-native 60.5
iOS 13
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.