我尝试通过apigee JS API创建用户帐户。当我上次在12月中旬假期前这样做时,这工作得很好。但是,现在我收到401 Unauthorized错误,读取token_expired
。
有没有办法刷新令牌?我不知道它为什么会过期。
这就是我正在尝试的。首先,我实例化数据客户端。这里没问题:
var dataClient;
var client_creds = {
orgName: '*******',
appName: '*******'
}
dataClient = new Apigee.Client(client_creds);
稍后,在尝试创建新用户时,出现token_expired
错误:
dataClient.request(options, function (error, response) {
if (error) {
console.log(response);
alert("Something went wrong when trying to create the user. " + response.error)
// Error
} else {
// Success - the user has been created, now login.
dataClient.login(user.email, user.password,
function (err) {
if (err) {
//error - could not log user in
console.log("There was an error logging in " + user.name);
} else {
//success - user has been logged in
}
}
);
}
});
我也试过了dataClient.signup
,但同样的错误。
答案 0 :(得分:1)
App Services中没有刷新令牌;您需要关注login flow才能检索新令牌。请注意,您可以指定ttl
参数,因此您不需要经常这样做:
https://api.usergrid.com/{org}/{app}/token?ttl=604800
默认情况下,此设置为7天,但您可以将默认 app max ttl更改为0
(非过期)或其他内容,例如31104000000
( 365天)。
为此,您提出了PUT
请求:
https://api.usergrid.com/{org}/{app}/?client_id={app_client_id}&client_secret={app_client_secret}
使用JSON有效负载:
{
"accesstokenttl":0
}
或者1年:
{
"accesstokenttl":31104000000
}
答案 1 :(得分:1)
如果这对您不起作用,JavaScript SDK的授权令牌将保留在浏览器的本地存储中。在Chrome中,使用开发人员工具。在左侧的“资源”选项卡中,展开“本地存储”条目。您应该看到类似“http://usergrid.dev”之类的东西。选择它,在右侧您应该看到accessToken的条目。删除它,它应该解决你的问题。