Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

How to implement Basic Auth using Karate?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.getBytes());
  return 'Basic ' + encoded;
}

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

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

Refer to the docs here: https://github.com/intuit/karate#http-basic-authentication-example

For OAuth or "login form" kinds of flows, see: https://stackoverflow.com/a/58643689/143475 and https://stackoverflow.com/a/46333729/143475


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...