Getting 401 Unauthorized

35 views
Skip to first unread message

Anurag Mishra

unread,
Oct 11, 2016, 5:46:40 AM10/11/16
to LoopbackJS
Hello All,

I am executing a script to create and update user with the auth credentials. Firstly I am checking the user is exist, if user exist then I update the user and if didn't then it gives 404(User not exists) so I create a new user. I am creating access_token with every request but after 5-8 request and it starting to give an error 401 Unauthorized.

Thanks,
Anurag Mishra

Anurag Mishra

unread,
Oct 12, 2016, 11:03:19 AM10/12/16
to loopb...@googlegroups.com
Hello All,

Can anyone please help me on this?

Thanks,
Anurag Mishra

Akram Shehadi

unread,
Oct 12, 2016, 12:17:34 PM10/12/16
to LoopbackJS
You should try to add more details (stack trace, etc) to your problem to make it easier for people to help you. Right now it's very hard to tell what's going on.

Anurag Mishra

unread,
Oct 15, 2016, 1:49:36 AM10/15/16
to LoopbackJS
Hello Akram,

Actually, I have list of more than 5k users in my another DB so I want to migrate all the users in loopback DB and may be there will be a duplicate user so that I am checking if user exists then I am updating a user or I am creating new one. I have written a script for that. Its working fine but after updates a user loopback starts to throw an error 401 Unauthorized. Even I have allowed Unauthenticated user to access update, create property in ACL.

Can you please throw some light?

Thanks,
Anurag Mishra

Akram Shehadi

unread,
Oct 15, 2016, 2:59:22 PM10/15/16
to LoopbackJS
The only two things I can think of is that for some reason the DB has incorrect info, for example if you are pointing to a DB without that user (it has happened to me that I point to a staging DB and I try to access it with production credentials). 

The other option is that the token you are using for the requests has expired. Try to refresh the token by logging in again.

If that doesn't help, you need to get more info on what's going on. Try adding debug strings (http://loopback.io/doc/en/lb2/Setting-debug-strings.html). You could try with the security ones like loopback:security:role or maybe loopback:security:acl, or if that doesn't help try the whole category with loopback:security:* . This will show you a stack of what loopback is doing for authorization steps.

You could also try with loopback:connector:* (or use the specific connector you are using, e.g. mongodb) to see what's going on with the database. Like I said, I once was pointing to the wrong database and this is where I saw the user didn't even exist.

That should help you out get more info on the inner workings of your system.

Hoe that helps,
Akram
Reply all
Reply to author
Forward
0 new messages