2013-11-21 46 views
1

我一直在嘗試將Google的OAuth2提供程序添加到在ServiceStack上構建的概念應用程序證明上,但是當我嘗試啓動登錄時,我不斷收到以下錯誤...servicestack oauth2谷歌身份驗證不適用於自我託管網站

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,並添加了谷歌的oauth2提供給它,並能夠得到它的工作。我已經將web.config中的配置複製到自己託管的項目的app.config文件中,但它仍然不起作用。

任何幫助將是偉大的!

感謝您的幫助。

回答

0

ServiceStack.AuthWeb.Tests是一個ASP.NET WebHost,顯示all the ServiceStack AuthProviders在單個應用程序內工作。

注意的OAuth2提供商使用它需要您註冊自己的應用程序,讓您的使用者密鑰和機密您的應用程式Web.config指定的其他配置。出於測試目的,您可以使用已嵌入Web.config中的ServiceStack測試密鑰。

OAuth2 section in the Authentication wiki提供了您可以在其中爲每個提供商註冊您的應用程序的網址。

+0

我正在標記這個正確的...因爲技術上它是。但是,我仍然無法讓oauth2使用服務堆在自己託管的應用程序中工作。當您使用它與Web託管的應用程序時,它完美地工作。如果你知道任何已經完成了這個項目的項目,你可以把它們一起傳給他們。能夠將ServiceStack作爲獨立應用程序託管是我整體架構的關鍵。 – Dan

+1

@Dan Yeah我發現當DotNetOpenAuth託管在自託管的HttpListener中時,它不能正常工作,因此任何需要DNOA才能正常工作的例如目前,受支持的OAuth2僅限於ASP.NET主機。如果您希望看到進一步研究,請添加[功能請求](http://servicestack.uservoice.com/forums/176786-feature-requests)。 – mythz