Unauthorized request handling in Angular.js
AnsweredHello I developing a web app with angular.js v1.5.7, which integrates Box using oauth2 authentication in the client-side for retrive the tokens, and with them have access to the API.
I have a problem when the access token expires and i make a request with that expired token, I recieve a 401 (unathorized) response that I can't catch in angular because this response has a status code of -1, and this happens before i able to catch this response.
I made a repository in github to demostrates this behaviour https://github.com/danyfu/box-api-test, its a express server that serves on the http:localhost:3000 port the angular app.
It's only a button when you click do a request to the api for get the root folder of the user:
When i make the request with the invalid token the response with two error logs.
https://app.box.com/s/5p551vubkeicvi4c6ohk5j24duaogbi9
When i make the request with a valid access token retrieve the folder info and a status of 200.
https://app.box.com/s/2mzpcgo93bumm8xhu0gv3dju9uqc3u0y
-
You can use passport-box which will do the oauth flow in your app.
https://github.com/bluedge/passport-box
Here's an example where I use it as well:
https://github.com/kendomen/boxadmin
Please sign in to leave a comment.
Comments
1 comment