用Auth0删除用户apiv2
问题描述:
我想删除一个基于id的用户,在auth0 API v2上他们只给出curl命令。对于post方法,我设法将其修改为angular2 http post,出于某种原因,我无法弄清楚如何使用删除请求。用Auth0删除用户apiv2
的ID看起来像这样
id = auth0|582b40627882b2970253725c
这是我使用的方法:
deleteAuth0User(id){
let headers = new Headers();
headers.append('Authorization', 'Bearer mytoken');
return this.http.delete('https://myusername.eu.auth0.com/api/v2/users/' + id, {headers:headers})
.map(response => response.json());
}
我已删除了我的auth0的用户名和API令牌。
我得到这个错误的结果:
"{"statusCode":403,"error":"Forbidden","message":"Insufficient scope, expected any of: delete:users,delete:current_user","errorCode":"insufficient_scope"}"
任何建议非常赞赏。 谢谢
P.S.如果你有兴趣在POST方法添加新用户:每次添加的范围产生一个新的令牌选项时
createAuth0User(body){
let headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('Authorization', 'Bearer myapitoken');
return this.http.post('https://myusername.eu.auth0.com/api/v2/users', JSON.stringify(body),{headers:headers})
.map(response => response.json());
}
答
我设法弄明白,与Auth0 API第2版,您可以向范围添加多个选项,以便您可以对所有这些选项使用相同的标记。
与HTTP的Auth0 API第2版第2件事删除你不能使用.MAP因为你会得到一个:
json parsing error syntax error unexpected end of input
的工作方法是:
deleteAuth0User(id){
let headers = new Headers();
headers.append('Authorization', 'Bearer mytoken');
return this.http.delete('https://myusername.eu.auth0.com/api/v2/users/' + id, {headers:headers})
}
这将工作,做不要忘记在你使用该方法的组件中订阅,因为你仍然会得到回应。
答
获取所需代码的一种简单方法是使用Postman。然后,您可以简单地将Curl命令导入Postman(使用import
选项)和/或生成所需的JavaScript(客户端)/ NodeJs代码(使用Postman的code
选项)。
见下截图:
和
最后,你可以得到所有Auth0的Authentication API和Management APIv2端点预建的模板邮差命令。
查看下载选项here
Avram,很高兴你整理出来!已经下降了一个快速的“答案”,建议一个简单的方法来获取模板代码。 – arcseldon
或者您可以创建一个单例令牌生成方法,以在应用程序中使用相同的令牌。 –