ServiceStack 和 Auth0
问题说明
我希望使用 Auth0 作为 ServiceStack 的身份验证提供程序.Auth0 上记录了一个很棒的示例应用程序,它适用于 &在使用 ServiceStack 和使用 ServiceStack.Host.MVC 时效果很好:https://auth0.com/docs/quickstart/webapp/servicestack/01-login.
I am looking to use Auth0 as the authentication provider for ServiceStack. There is a great sample application documented at Auth0 which applies & works well when working with ServiceStack and using ServiceStack.Host.MVC: https://auth0.com/docs/quickstart/webapp/servicestack/01-login.
但是,在我不使用 MVC & 的情况下,我不知道如何构造授权 URL 并将用户重定向到该 URL.AccountController 重定向用户.如果我想按照下面的 MVC 示例代码复制逻辑,如何使用 ServiceStack Auth 插件构建重定向 URL:
However, I am at a loss how to construct the authorization URL and redirect the user to that URL in a scenario where I am NOT using MVC & the AccountController to redirect the user. How can I construct the redirect URLs using ServiceStack Auth Plugin, if I want to replicate the logic as per MVC sample code below:
public class AccountController : Controller
{
public ActionResult Login()
{
string clientId = WebConfigurationManager.AppSettings["oauth.auth0.AppId"];
string domain = WebConfigurationManager.AppSettings["oauth.auth0.OAuthServerUrl"].Substring(8);
var redirectUri = new UriBuilder(this.Request.Url.Scheme, this.Request.Url.Host, this.Request.Url.IsDefaultPort ? -1 : this.Request.Url.Port, "api/auth/auth0");
var client = new AuthenticationApiClient(new Uri($"https://{domain}"));
var authorizeUrlBuilder = client.BuildAuthorizationUrl()
.WithClient(clientId)
.WithRedirectUrl(redirectUri.ToString())
.WithResponseType(AuthorizationResponseType.Code)
.WithScope("openid profile")
.WithAudience($"https://{domain}/userinfo");
return Redirect(authorizeUrlBuilder.Build().ToString());
}
}
正确答案
对于所有感兴趣的人,这里是我最终采用的解决方案.
For all who are interested,here is the solution I ended up adopting.
步骤:
1) 创建一个 Auth0 插件(参见要点 此处)
1) Create an Auth0 plugin (see gist here)
2) 在您的 AppHost 中注册插件.
2) Register the Plugin in your AppHost.
Plugins.Add(new AuthFeature(() => new Auth0UserSession(), new IAuthProvider[] {
new Auth0Provider(appSettings,appSettings.GetString("oauth.auth0.OAuthServerUrl"))
}));
3) 在您的 Web.Config 中添加相关键.
3) Add the relevant keys in your Web.Config.
<appSettings>
<add key="oauth.auth0.OAuthServerUrl" value="https://xxxxxxx.auth0.com" />
<add key="oauth.auth0.AppId" value="xxxxxx" />
<add key="oauth.auth0.AppSecret" value="xxxxxxx" />
</appSettings>
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcgjgik
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20