我正在尝试在RestAssured测试中移植以下curl外壳:
curl -X POST http://localhost:8180/auth/realms/demo/protocol/openid-connect/token \
--user backend-service:secret \
-H 'content-type: application/x-www-form-urlencoded' \
-d 'username=alice&password=alice&grant_type=password'
这是我的RestAssured版本:
response = given().urlEncodingEnabled(true)
.auth().basic("backend-service", "secret")
.param("grant_type", "password")
.param("client_id", "backend-service")
.param("username", "alice")
.param("password", "alice")
.header("Accept", ContentType.JSON.getAcceptHeader())
.post("http://localhost:8180/auth/realms/demo/protocol/openid-connect/token")
.then().statusCode(200).extract()
.response();
不幸的是,问题出在“ --user”参数,该参数未通过auth()。basic()转换。从服务器日志中,我可以看到它是唯一为null的参数:
type=LOGIN_ERROR, realmId=demo, clientId=backend-service, userId=null, ipAddress=127.0.0.1, error=invalid_client_credentials, grant_type=password
任何想法如何配置它? 谢谢