【问题标题】:servicestack oauth2 google authentication not working for selfhosted sitesservicestack oauth2 google 身份验证不适用于自托管站点
【发布时间】:2013-11-21 22:36:06
【问题描述】:

我一直在尝试将 Google 的 OAuth2 提供程序添加到基于 ServiceStack 构建的概念验证应用程序中,但是当我尝试启动登录时,我不断收到以下错误...

This method requires a current HttpContext. Alternatively, use an overload of this method that allows you to pass in information without an HttpContext`enter code here`

[Auth: 11/21/2013 10:29:25 PM]: [REQUEST: {provider:googleoauth}] System.InvalidOperationException: This method requires a current HttpContext. Alternatively, use an overload of this method that allows you to pass in information without an HttpContext. at DotNetOpenAuth.Requires.ValidState(Boolean condition, String message) at DotNetOpenAuth.Messaging.Channel.GetRequestFromContext() at DotNetOpenAuth.OAuth2.WebServerClient.ProcessUserAuthorization(HttpRequestBase request) at ServiceStack.Authentication.OAuth2.OAuth2Provider.Authenticate(IServiceBase authService, IAuthSession session, Auth request) at ServiceStack.ServiceInterface.Auth.AuthService.Authenticate(Auth request, String provider, IAuthSession session, IAuthProvider oAuthConfig) at ServiceStack.ServiceInterface.Auth.AuthService.Post(Auth request) at ServiceStack.ServiceInterface.Auth.AuthService.Get(Auth request) at lambda_method(Closure , Object , Object ) at ServiceStack.ServiceHost.ServiceRunner`1.Execute(IRequestContext requestContext, Object instance, TRequest request)

我还下载了演示应用 SocialBootstrapApi 并向其中添加了 Google Oauth2 提供程序,并且能够使其正常工作。我已将 web.config 中的配置复制到自托管项目的 app.config 文件中,但仍然无法正常工作。

任何帮助都会很棒!

感谢您的帮助。

【问题讨论】:

    标签: oauth servicestack self-hosting


    【解决方案1】:

    ServiceStack.AuthWeb.Tests 是一个 ASP.NET WebHost,显示 all the ServiceStack AuthProviders 在单个应用程序中工作。

    请注意,OAuth2 提供程序使用Web.config 中指定的附加配置,这要求您注册自己的应用程序以获取您的应用程序的使用者密钥和秘密。出于测试目的,您可以使用 Web.config 中已嵌入的 ServiceStack 测试密钥。

    OAuth2 section in the Authentication wiki 提供了 URL,您可以在其中为每个提供商注册您的应用程序。

    【讨论】:

    • 我将其标记为正确...因为从技术上讲它是正确的。但是,我仍然无法让 oauth2 在使用 servicestack 的自托管应用程序中工作。当您将它与网络托管应用程序一起使用时,它可以完美运行。如果您知道那里有任何项目已经这样做了,您可以将它们传递出去。能够将 servicestack 作为独立应用托管是我整体架构的关键。
    • @Dan 是的,我发现 DotNetOpenAuth 在托管在自托管的 HttpListener 中时无法正常工作,因此任何需要 DNOA 才能工作的东西,例如目前支持的 OAuth2 仅限于 ASP.NET 主机。如果您希望对此进行进一步研究,请添加feature request
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-04
    • 2016-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-13
    • 2016-11-21
    相关资源
    最近更新 更多