【发布时间】:2021-02-17 19:17:51
【问题描述】:
我有这个代码
<cfscript>
public struct function CreateToken() {
var result = '';
var apiKeys = {
'appKey' : variables.username,
'appSecret': variables.password
};
httpService = new http(method = "POST", url = "https://wesa.com/v1/tokens/create");
httpService.addParam(type = "header", name="Content-Type", value = "application/json");
httpService.addParam(type = "body", value = "#parseBody(apiKeys)#");
result = httpService.send().getprefix();
if(result.statuscode == '200') {
resultDeserialized = deserializeJSON(result.fileContent);
}
return resultDeserialized;
}
public struct function RefreshToken(required string token) {
var apiStruct = [:];
apiStruct['refreshToken'] = arguments.token;
httpService = new http(method = "POST", url = "https://wesa.com/v1/tokens/refresh");
httpService.addParam(type = "header", name="Content-Type", value = "application/json");
httpService.addParam(type = "body", value = "#parseBody(apiStruct)#");
result = httpService.send().getprefix();
if(result.statuscode == '200') {
resultDeserialized = deserializeJSON(result.fileContent);
}
return resultDeserialized;
}
</cfscript>
但我想了解如何自动调用刷新令牌,因为如果令牌处于活动状态且已过期,它会给我一个 401 状态。
我没有得到底层行为,如何自动使用它来刷新它,然后调用 API 进行调用。
同理,过期时间是8900秒,所以甚至不确定刷新令牌在时间过期后是否可用或检查是否过期,只需调用刷新令牌
我只是需要一些关于如何使用它的指导
【问题讨论】:
标签: coldfusion lucee