'Hyperledger Composer Multiple user mode for REST server throws 401 error
I have been following the tutorials which are provided in Hyperledger Composer docs, but I am not getting the results that they are supposed to I should be getting. Specifically, when I try to enable the multiple user mode for the REST server and I try to call one of the business network REST API operations using the REST API explorer I always get a HTTP 401 Authorization Required. According to the Tutorial, I if get this error is due to I have not authenticated correctly to the REST API, but it does not mention why this error occurs or how I may fix it.
It is very important for application development to be able to authenticate each user who wants to make requests to the API.
Solution 1:[1]
What version of Hyperledger Composer are you using? The tutorial/document you refer to is correct for v0.15.0 and works a little differently for prior versions.
Are you seeing an Access token at the top of the Browser Window - this indicates that you have successfully authenticated and can continue with the steps for the Wallet.
If you are not seeing an Access token displayed, then make sure you hit your REST server with a URL similar to http://localhost:3000/auth/github again and login.
If you are still experiencing problems I would suggest going back to just using authentication without multiuser mode and verify that the authentication works properly from there.
Solution 2:[2]
After some research, I found a solution and worked for me. If you already enable Github authentication then ignore. Otherwise first enable authentication following this tutorial Enaling Authentication.
Before start rest server you will export your admin card from the network by using this command:
composer card export -n admin@sample-network -f admincard.card
Now start rest server with authentication using this command:
composer-rest-server -c admin@sample-network -p 3000 -a true -m true
After some time rest server will start. Now First, go this link for authentication: http://localhost:3000/auth/github
After successful authentication, you will get an access token and also you will see a Wallet options below. Now you need to import a card that you already export from your network. That's it, you can able to add anything to your network.
Solution 3:[3]
In my case, I have two missed steps:
- enabling authentication for the REST server https://hyperledger.github.io/composer/v0.19/integrating/enabling-rest-authentication.html
- composer-rest-server -c admin@you_project -a true, I just execute composer-rest-server but did not specify the identity "admin@you_project" before.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | R Thatcher |
| Solution 2 | Faysal Ahmed |
| Solution 3 | Sara |
