Composer-rest-server使用passport-local策略认证失败求助
Hey there, let's work through getting local authentication working for your Composer REST Server! It's totally normal to hit snags with this when you're new to Node.js and Hyperledger Composer, so let's break down the fixes step by step.
First, Let's Fix Your COMPOSER_PROVIDERS Configuration
Your current config has a couple of extra parameters that might be causing the 404 error and unexpected behavior. The callbackURL and callbackHTTPMethod aren't needed for the local passport strategy—here's a cleaned-up, working version:
export COMPOSER_PROVIDERS='{ "local": { "provider": "local", "module": "passport-local", "usernameField": "username", "passwordField": "password", "authPath": "/auth/local", "successRedirect": "/", "failureRedirect": "/login", "setAccessToken": true } }'
- We removed
callbackURLandcallbackHTTPMethodbecause passport-local handles authentication directly via POST requests to yourauthPath(/auth/local). - The
failureRedirectpoints to a/loginpath, which we'll use for our custom login form (more on that next).
Critical Note: Composer REST Server Doesn't Auto-Generate a Local Login Form
This is probably why you didn't see a login page! Unlike GitHub OAuth (which uses GitHub's own login screen), local authentication requires you to create a simple HTML form to submit credentials to the /auth/local endpoint.
Here's a basic login form you can use:
Create a file named login.html in a folder called public (you'll need to make this folder):
<!DOCTYPE html> <html> <head> <title>Local Login</title> </head> <body> <h2>Login to Composer REST Server</h2> <form action="/auth/local" method="POST"> <div> <label>Username:</label> <input type="text" name="username" required> </div> <div> <label>Password:</label> <input type="password" name="password" required> </div> <button type="submit">Log In</button> </form> </body> </html>
Then start your Composer REST Server with the --static flag to serve this static file:
composer-rest-server -c admin@your-network-name -n never -w true --static ./public
Now you can access the login form at http://localhost:3000/login.html, submit your credentials, and it should authenticate against your Fabric network.
Double-Check Your Fabric Identity Exists
Make sure the username and password you're using correspond to an identity that's already registered and enrolled in your Hyperledger Fabric network. You can list existing identities with this command:
composer identity list -c admin@your-network-name
If the user doesn't exist, you'll need to register and enroll them first using composer identity issue.
Debug with Logs
If you still run into issues, start the server with debug mode enabled to see detailed error messages:
composer-rest-server -c admin@your-network-name -n never -w true -d --static ./public
The debug logs will tell you exactly where the authentication flow is failing (e.g., missing identity, incorrect password, or configuration issues).
内容的提问来源于stack exchange,提问作者Jay KM

