我的场景是我必须使用基本编码对令牌和秘密进行编码,然后通过 API 生成一个 JWT 令牌,这将给出如下响应:
eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJmOWJlYmFjYjVhMjE0M2FiYTE1ZWFlMDUyNGFlMjFhYiIsImV4cCI6MTUwOTYwNDQ5OSwianRpIjoiN256WlhqQW9yd2FEVmxnSUZSZHJLQSIsImlhdCI6MTUwOTYwNDQ4NCwibmJmIjoxNTA5NjA0MzY0LCJzdWIiOiJmOWJlYmFjYjVhMjE0M2FiYTE1ZWFlMDUyNGFlMjFhYiJ9.0QCtE5XF-_FxxhjpP2sIEFU8rSnNK5jwD3BBd5oCUGc
然后我们必须在头文件中使用它来进行其余的 API 调用,例如:
function() {
var out = {
'Authorization': 'Bearer eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJlNjhjODJhNjY1MTQ0ZmRkOTk5YzU1MjExYjYyODQ3YyIsImV4cCI6MTUwMjk3NjEzNSwianRpIjoiUm1VeFdDNWhQQXdvNVZ0TXFYeEFlQSIsImlhdCI6MTUwMjk3NjEyMCwibmJmIjoxNTAyOTc2MDAwLCJzdWIiOiJlNjhjODJhNjY1MTQ0ZmRkOTk5YzU1MjExYjYyODQ3YyJ9.h3buTcq-KATXuDF6SEdA5rblvTI84_SuDZPOqdm4j7Q',
'Content-Type': 'application/json'
};
return out;
}
那么如何集成它以使该标头对其余的 API 调用通用?