【发布时间】:2015-10-19 04:27:08
【问题描述】:
实现自定义身份验证提供程序 (CredentialsAuthProvider) 时如何使用 Swagger UI 对 ServiceStack 进行身份验证。
对于基本身份验证提供程序,我只会发送带有 base64 编码的用户:密码的授权标头,但是这个怎么样?
【问题讨论】:
标签: authentication servicestack restful-authentication swagger-ui
实现自定义身份验证提供程序 (CredentialsAuthProvider) 时如何使用 Swagger UI 对 ServiceStack 进行身份验证。
对于基本身份验证提供程序,我只会发送带有 base64 编码的用户:密码的授权标头,但是这个怎么样?
【问题讨论】:
标签: authentication servicestack restful-authentication swagger-ui
从 v4.0.43+ 开始,现在是 available on MyGet,ServiceStack 的 Swagger API Feature 支持添加 UserName 和 Password,它们会在 HTTP Basic Auth Headers 中为每个允许访问的 Swagger 请求发送经过身份验证的服务:
这使用BasicAuthProvider 是通过HTTP Basic Authentication 启用身份验证,可以在注册AuthFeature 时启用:
Plugins.Add(new AuthFeature(...,
new IAuthProvider[] {
new BasicAuthProvider(appSettings),
...
});
如果您只启用了CredentialsAuthProvider,则需要首先在 Swagger 之外进行身份验证,例如手动调用 URL:
/auth/credentials=Username=xxx&Password=xxx
如果成功,您可以使用 Swagger UI 访问经过身份验证的服务。
【讨论】:
window.authorizations.add("key", new ApiKeyAuthorization("Authorization", "Basic "+key, "header")); 并将密钥作为 base64 编码的用户名:密码发送吗?