如何使用空手道实现基本身份验证?
How to implement Basic Auth using Karate?
I saw details about Oauth 2 in Karate Demo , Can you also provide how to implement Basic Auth ?
是的,这个 JS 函数就是您所需要的:
function(creds) {
var temp = creds.username + ':' + creds.password;
var Base64 = Java.type('java.util.Base64');
var encoded = Base64.getEncoder().encodeToString(temp.getBytes());
return 'Basic ' + encoded;
}
然后用这个函数建立值 Authorization
header:
* header Authorization = call read('basic-auth.js') { username: 'john', password: 'secret' }
请参阅此处的文档:https://github.com/intuit/karate#http-basic-authentication-example
有关 OAuth 或“登录表单”类型的流程,请参阅:https://whosebug.com/a/58643689/143475 and https://whosebug.com/a/46333729/143475
I saw details about Oauth 2 in Karate Demo , Can you also provide how to implement Basic Auth ?
是的,这个 JS 函数就是您所需要的:
function(creds) {
var temp = creds.username + ':' + creds.password;
var Base64 = Java.type('java.util.Base64');
var encoded = Base64.getEncoder().encodeToString(temp.getBytes());
return 'Basic ' + encoded;
}
然后用这个函数建立值 Authorization
header:
* header Authorization = call read('basic-auth.js') { username: 'john', password: 'secret' }
请参阅此处的文档:https://github.com/intuit/karate#http-basic-authentication-example
有关 OAuth 或“登录表单”类型的流程,请参阅:https://whosebug.com/a/58643689/143475 and https://whosebug.com/a/46333729/143475