The error is as follows:
Register return error:
failed to register user: failed to register user: Response from server: Error Code: 20 - Authentication failure
The relevant part of the code is as follows:
import (
[...]
mspclient "github.com/hyperledger/fabric-sdk-go/pkg/client/msp"
[...]
)
[...]
func RegisterUser(sdk *fabsdk.FabricSDK, info *InitInfo, r *RegistrationRequest) (string, error) {
clientContext := sdk.Context(fabsdk.WithUser(info.OrgAdmin), fabsdk.WithOrg(info.OrgName))
if clientContext == nil {
return "", fmt.Errorf("根据指定的组织名称与管理员创建资源管理客户端Context失败")
}
// 创建一个新的msp客户端实例,并返回
c, err := mspclient.New(sdk.Context(), mspclient.WithOrg(info.OrgName))
if err != nil {
return "", fmt.Errorf("根据指定的 OrgName 创建 Org MSP 客户端实例失败: %v", err)
}
request := mspclient.RegistrationRequest{
Name: r.Name,
Type: r.Type,
MaxEnrollments: r.MaxEnrollments,
Affiliation: r.Affiliation,
//Attributes: ,
CAName: r.CAName,
Secret: r.Secret,
}
_, err = c.Register(&request)
if err != nil {
return "", fmt.Errorf("Register return error:\n %s\n", err)
}
return "enroll user is completed", nil
}
In this forum, I also found that someone reported the same error, and some people answered that the user name and password do not match, but my code is a registered user, this reason should not appear.
This is the sdk config file of one of the organizations.