【发布时间】:2019-12-25 22:10:41
【问题描述】:
我正在尝试在 RestAssured 测试中移植以下 curl shell:
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() 进行翻译。从服务器日志中我可以看到它是唯一为空的参数:
type=LOGIN_ERROR, realmId=demo, clientId=backend-service, userId=null, ipAddress=127.0.0.1, error=invalid_client_credentials, grant_type=password
知道如何配置它吗? 谢谢
【问题讨论】:
-
你试过
.auth().preemptive()吗? -
谢谢,auth().preemptive() 成功了!
标签: rest-assured