首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ServiceStack和Auth0

ServiceStack和Auth0
EN

Stack Overflow用户
提问于 2018-03-26 22:54:04
回答 1查看 291关注 0票数 1

我希望使用Auth0作为ServiceStack的身份验证提供者。在Auth0上有一个很好的示例应用程序,它在使用ServiceStack和使用ServiceStack.Host.MVC时可以很好地应用:https://auth0.com/docs/quickstart/webapp/servicestack/01-login

但是,在不使用MVC & AccountController来重定向用户的情况下,我不知道如何构造授权URL并将用户重定向到该URL。如果我想按照下面的ServiceStack示例代码复制逻辑,如何使用MVC身份验证插件构建重定向URL:

代码语言:javascript
复制
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());
 }
}
EN

回答 1

Stack Overflow用户

发布于 2018-04-19 12:35:24

对于所有感兴趣的人,这里是我最终采用的解决方案。

步骤:

1)创建Auth0插件(参见要点here)

2)在您的AppHost中注册插件。

代码语言:javascript
复制
Plugins.Add(new AuthFeature(() => new Auth0UserSession(), new IAuthProvider[] {
    new Auth0Provider(appSettings,appSettings.GetString("oauth.auth0.OAuthServerUrl"))
}));

3)在您的Web.Config中添加相关密钥。

代码语言:javascript
复制
<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>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49494449

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档