1. 为权限管理创建用户
1.1 首先为权限管理创建用户
1.2 将新创建的用户设置为confirmed&!blocked
2. 配置你需要设置权限的API
2.1 找到api的authenticated选项
Settings->Roles(USERS & PERMISSIONS)->Authenticated
2.2 将api设置为authenticated
将选中的API的Allow to perform this action for:设置为isauthenticated
3. 调用apilocal/auth获取jwt
调用http://localhost:1337/auth/local的POST方法
post-body如下:
{
"identifier": "strapi@strapi.com",
"password": "<your password>"
}
response:
{
"jwt": "<your jwt token>",
"user": {
# the properties of this user
}
}
4. 使用jwt调用你所配置的auth-api
本文中将使用post-man来测试api的调用。
4.1 2.2中已经为Entity1的create方法设置为authenticated
4.2 使用上一篇帖子中添加Entity1的api就会返回403错误(unauthroized)
4.3 在调用api时,在authorization header中添加Bearer token
在Authorization header中加入Bearer Token就可以通过strapi的权限验证了