servicestack - JSON Web 令牌服务堆栈 API
问题描述
我已通过以下方式(以及其他方式)配置了 JSON Web 令牌。
Plugins.Add(new AuthFeature(() => new AuthUserSession(),
new IAuthProvider[] {
new JwtAuthProvider(appSettings) { AuthKeyBase64 = appSettings.GetString("JWT:AuthKeyBase64")},
new FacebookAuthProvider(appSettings),
new TwitterAuthProvider(appSettings),
new CredentialsAuthProvider(appSettings),
}));
当我尝试使用 reslet 向用户授权时,/auth 我得到 401 Unauthorized,即使我知道用户名和密码是正确的。
还有什么我必须添加到请求中的吗?还是我必须做的其他一些改变?如果我启用了 BasicAuth,则登录没有问题。
解决方案
空/auth
路由仅检查您是否已通过身份验证,如果您未通过身份验证,它将返回 401 指示,否则将返回 200 响应,其中包含有关您的会话的基本信息。
要进行身份验证,您需要使用Auth Providers之一进行身份验证,例如对于用户名/密码,您需要使用以下方式进行身份验证:
/auth/credentials
通过发送GET /auth/credentials?username=myuser&password=mypass
或通过 HTTP POST:
POST /auth/credentials
{
"UserName": "admin",
"Password": "test",
"RememberMe": true
}
请注意,在 ServiceStack 的下一个版本中,GET Authenticate 请求(如 /auth/credentials)将默认禁用,因此建议在您的应用程序中通过 HTTP POST 进行身份验证。
推荐阅读
- jquery - 显示“等待”模式_before_我的冗长表格排序开始(然后消失)
- php - 如何在 WordPress 内容之外替换 HTML?
- python - pandas 自定义聚合函数
- c# - 面对方向的随机敌人移动
- ios - 一旦已经在 WebView 中,如何使用 WKWebView 打开外部链接?
- r - 仅对数字列求和并将值除以总数
- phabricator - 在 Phabricator 中更改用户的密码
- reactjs - 如何动态生成 Joi 模式并将其保存为 React JS 中的对象
- android - 应用内更新(如何确定应用更新类型?)
- opencart - Opencart 自定义类别类型