【问题标题】:(Google)OpenId Authenication has InvalidOperationException(Google)OpenId 身份验证有 InvalidOperationException
【发布时间】:2012-12-22 20:24:24
【问题描述】:

我正在尝试使用 ServiceStack.Authentication.OpenId 包通过 Google 启动和运行身份验证。我遵循了 SocialBootStrap 示例,但无法弄清楚我错过了什么。

我已将身份验证提供程序添加到我的 apphost:

Plugins.Add(new AuthFeature(() => new CustomUserSession(), new IAuthProvider[] { 
                    new CredentialsAuthProvider(), //HTML Form post of UserName/Password credentials
                    new TwitterAuthProvider(appSettings),       //Sign-in with Twitter
                    new FacebookAuthProvider(appSettings),      //Sign-in with Facebook
                    new GoogleOpenIdOAuthProvider(appSettings), //Sign-in with Goolge OpenId
                    new WsFedSamlAuthProvider(appSettings)
                    })

我已将配置设置添加到我的 app.config(我正在运行自托管应用):

<add key="oauth.googleopenid.AppId" value="XXX" />
<add key="oauth.googleopenid.AppSecret" value="XXX" />
<add key="oauth.googleopenid.RedirectUrl" value="http://XXX" />
<add key="oauth.googleopenid.CallbackUrl" value="http://XXX/api/auth/googleopenid" />

顺便说一下,AppId 和 AppSecret 不在示例中,但没有它们我得到了不同的错误。

最后我在我的登录页面上放置了一个网络表单:

<form action="/api/auth/googleopenid" method="POST">
    <button class='btn' type='submit'>Sign-in with Google</button>
</form>

当我点击按钮时,我收到以下错误:

errorCode: InvalidOperation
Exceptionmessage:  No current HttpContext was detected, so an IOpenIdApplicationStore instance must be explicitly provided or specified in the .config file. Call the constructor overload that takes an IOpenIdApplicationStore.stack 
Trace[Auth: 08/01/13 20:49:30]: [REQUEST: {provider:googleopenid}]System.InvalidOperationException: No current HttpContext was detected, so an IOpenIdApplicationStore instance must be explicitly provided or specified in the .config file. Call the constructor overload that takes an IOpenIdApplicationStore. at DotNetOpenAuth.Messaging.ErrorUtilities.VerifyOperation(Boolean condition, String errorMessage, Object[] args) at DotNetOpenAuth.OpenId.RelyingParty.OpenIdRelyingParty.get_HttpApplicationStore() at DotNetOpenAuth.OpenId.RelyingParty.OpenIdRelyingParty..ctor() at ServiceStack.Authentication.OpenId.OpenIdOAuthProvider.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 lambda_method(Closure , Object , Object ) at ServiceStack.ServiceHost.ServiceRunner`1.Execute(IRequestContext requestContext, Object instance, TRequest request)

我已经尽可能地遵循了这些示例,我想我错过了什么?

谢谢你的期待。

【问题讨论】:

    标签: oauth openid servicestack dotnetopenauth


    【解决方案1】:

    如错误所示,该问题与没有 HTTP 上下文有关。这是因为我在自托管应用程序中运行,即不在 IIS 中。

    要在此环境中工作,必须为 dotnetopenauth 提供自定义应用程序商店。存储是存储密钥和随机数的地方,在 IIS 环境中,dotnetopenauth 将使用通过 HTTP 上下文访问的应用程序缓存。

    为了解决这个问题,我编写了一个由本机 REDIS 客户端和自定义 OpenIdAuthentication Provider 支持的自定义应用程序商店。

    我已经在https://gist.github.com/miketrebilcock/6652969 中提出了我的代码要点。这适用于我基于 OpenId 编写的 STS 服务器,但似乎不适用于 Servicestack 中的 OpenId 提供程序 - 需要进行更多调查。

    【讨论】:

      猜你喜欢
      • 2014-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-25
      • 1970-01-01
      • 2018-07-01
      • 2021-09-07
      • 2010-09-06
      相关资源
      最近更新 更多