如何使用空手道实施基本身份验证? [英] How to implement Basic Auth using Karate?

查看:36
本文介绍了如何使用空手道实施基本身份验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Karate Demo中看到了有关Oauth 2的详细信息,您还能提供如何实现基本身份验证的方法吗? ?

推荐答案

是的,此JS函数就是您所需要的:

Yes, this JS function is all you need:

function(creds) {
  var temp = creds.username + ':' + creds.password;
  var Base64 = Java.type('java.util.Base64');
  var encoded = Base64.getEncoder().encodeToString(temp.bytes);
  return 'Basic ' + encoded;
}

然后使用此函数构建Authorization标头的值:

And then use this function to build the value of the Authorization header:

* header Authorization = call read('basic-auth.js') { username: 'john', password: 'secret' }

在此处参考文档: https://github.com/intuit/空手道#http-basic-authentication-example

这篇关于如何使用空手道实施基本身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆