1

My scenario is I have to encode the token and secret using base encoding then generate a JWT token through API, which will give response like:

eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJmOWJlYmFjYjVhMjE0M2FiYTE1ZWFlMDUyNGFlMjFhYiIsImV4cCI6MTUwOTYwNDQ5OSwianRpIjoiN256WlhqQW9yd2FEVmxnSUZSZHJLQSIsImlhdCI6MTUwOTYwNDQ4NCwibmJmIjoxNTA5NjA0MzY0LCJzdWIiOiJmOWJlYmFjYjVhMjE0M2FiYTE1ZWFlMDUyNGFlMjFhYiJ9.0QCtE5XF-_FxxhjpP2sIEFU8rSnNK5jwD3BBd5oCUGc

Then we have to use this in headers for rest of the API call like:

function() {
    var out = {
        'Authorization': 'Bearer eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJlNjhjODJhNjY1MTQ0ZmRkOTk5YzU‌​1MjExYjYyODQ3YyIsImV‌​4cCI6MTUwMjk3NjEzNSw‌​ianRpIjoiUm1VeFdDNWh‌​QQXdvNVZ0TXFYeEFlQSI‌​sImlhdCI6MTUwMjk3NjE‌​yMCwibmJmIjoxNTAyOTc‌​2MDAwLCJzdWIiOiJlNjh‌​jODJhNjY1MTQ0ZmRkOTk‌​5YzU1MjExYjYyODQ3YyJ‌​9.h3buTcq-KATXuDF6SE‌​dA5rblvTI84_SuDZPOqd‌​m4j7Q',
        'Content-Type': 'application/json'
    };
    return out;
}

So how to integrate this to make this header generic for rest of the API calls?

Antti29
  • 2,953
  • 12
  • 34
  • 36

1 Answers1

0

Here is how to perform basic-auth: HTTP Basic Auth Example.

Also look at the OAuth2 sample: oauth2.feature.

There are plenty of ways to make headers generic for all calls in Karate. Just look at the samples, for example: headers.feature.

EDIT: also see this answer: https://stackoverflow.com/a/52205655/143475

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248