2

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 は例に含まれていませんが、それらがないと別のエラーが発生していました。

最後に、ログイン ページに Web フォームを配置しました。

<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)

私は可能な限り例をたどりましたが、何か不足していると思いますか?

期待していただきありがとうございます。

4

1 に答える 1

1

エラーが示すように、問題は HTTP コンテキストがないことに関連していました。これは、IIS ではなく、自己ホスト型アプリで実行しているためです。

この環境で動作するには、dotnetopenauth にカスタム アプリケーション ストアを提供する必要があります。ストアは、暗号鍵とノンスが格納される場所です。IIS 環境では、dotnetopenauth は HTTP コンテキストを介してアクセスされるアプリケーション キャッシュを使用します。

この問題を解決するために、ネイティブ REDIS クライアントとカスタム OpenIdAuthentication プロバイダーに支えられたカスタム アプリケーション ストアを作成しました。

ここにコードの要旨を掲載しましたhttps://gist.github.com/miketrebilcock/6652969。これは、OpenId に基づいて作成した STS サーバーでは機能しますが、Servicestack の OpenId プロバイダーでは機能しないようです - もう少し調査が必要です。

于 2013-02-07T14:01:49.560 に答える