4

SSO openid を dotnetopenauth で動作させようとしています。

2 つの別々のプロジェクトがあり、別々にデバッグされています (両方とも localhost で 2 つの異なるポートで)。1 つはプロバイダーとして機能し、もう 1 つは依存側として機能します。

証明書利用者は で実行されていlocalhost:1903ます。プロバイダーは で実行されていlocalhost:3314ます。

証明書利用者コード:

    public ActionResult Authenticate()
    {
        UriBuilder returnToBuilder = new UriBuilder(Request.Url);
        returnToBuilder.Path = "/OpenId/";
        returnToBuilder.Query = null;
        returnToBuilder.Fragment = null;

        Uri returnTo = returnToBuilder.Uri;
        returnToBuilder.Path = "/";
        Realm realm = returnToBuilder.Uri;
        realm = "http://localhost:3314/OpenId/";
        returnTo = new Uri("http://localhost:3314/OpenId/");
        var response = openid.GetResponse();

        if (response == null) {
            if (Request.QueryString["ReturnUrl"] != null && User.Identity.IsAuthenticated) {
            } else {
                string strIdentifier = "testidentifier";
                var request = openid.CreateRequest(
                    strIdentifier,
                    realm,
                    returnTo);

                var fetchRequest = new FetchRequest();
                request.AddExtension(fetchRequest);
                request.RedirectToProvider();
            }
        } else {
            switch (response.Status) {
                case AuthenticationStatus.Canceled:
                    //stuff got cancelled for some reason
                    break;
                case AuthenticationStatus.Failed:
                    //response.Exception.Message;
                    break;
                case AuthenticationStatus.Authenticated:
                    //a bunch of applying roles that i don't think we care about
                    break;
            }
        }

        return new EmptyResult();
    }

プロバイダ コード:

    public ActionResult Index()
    {
        IAuthenticationRequest iR = (IAuthenticationRequest)Request;

        if (iR.IsReturnUrlDiscoverable(ProviderEndpoint.Provider.Channel.WebRequestHandler) != RelyingPartyDiscoveryResult.Success) {
            iR.IsAuthenticated = false;
            return new EmptyResult();
        }

        if (iR.IsDirectedIdentity) {
            if (User.Identity.IsAuthenticated) {
                iR.LocalIdentifier = BuildIdentityUrl();
                iR.IsAuthenticated = true;
            } else {
                if (iR.Immediate || ImplicitAuth) {
                    iR.IsAuthenticated = false;
                } else {
                    if (!Request.Path.EndsWith("Login", StringComparison.OrdinalIgnoreCase)) {
                        return RedirectToAction("Login", "User");
                    }
                }
            }
        } else {
            string userOwningOpenIdUrl = ExtractUserName(iR.LocalIdentifier);

            iR.IsAuthenticated = userOwningOpenIdUrl == User.Identity.Name;

            if (!iR.IsAuthenticated.Value && !ImplicitAuth && !iR.Immediate) {
                if (!Request.Path.EndsWith("Login", StringComparison.OrdinalIgnoreCase)) {
                    return RedirectToAction("Login", "User");
                }
            }
        }

        if (iR.IsAuthenticated.Value) {
            var fetchRequest = iR.GetExtension<FetchRequest>();

            if (fetchRequest != null) {
                var fetchResponse = new FetchResponse();
                //roles and stuff

                iR.AddResponseExtension(fetchResponse);
            }
        }

        return new EmptyResult();
    }

メソッドで証明書利用者コードを実行すると、エラーが発生しますopenid.CreateRequest。プロバイダー コードでデバッグを有効にしましたが、ヒットしません。

エラーを調査したところ、プロキシの問題に関する多くの提案が見つかりましたが、ローカルホストにしかアクセスしないので、それは問題にはなりません。

おそらくそれはかなり明白なことですが、私は何が間違っているのか途方に暮れています。

助けてくれてありがとう!

編集: 参考までに、DotNetOpenAuth サンプルからこのコードを取得しました。

4

3 に答える 3

2

さて、私はソースを手動でステップ実行して、問題をある程度理解しました.

dumdum はやや正しかったことがわかりました - 私の最初の問題は、URI を識別子として必要としていたことでしたhttp://localhost:3314/OpenId/

2 番目の問題は、web.config に情報を追加するのを忘れていたため、localhostホワイトリストに登録されず、CreateRequestそこで失敗したことでした。

これらの 2 つの問題を修正した後、プロバイダー コードは問題なく動作しました。別のエラーが発生していますが、それは別の質問です。

Web.Config:

<configSections>
  <sectionGroup name="dotNetOpenAuth" type="DotNetOpenAuth.Configuration.DotNetOpenAuthSection, DotNetOpenAuth">
    <section name="openid" type="DotNetOpenAuth.Configuration.OpenIdElement, DotNetOpenAuth" requirePermission="false" allowLocation="true"/>
    <section name="oauth" type="DotNetOpenAuth.Configuration.OAuthElement, DotNetOpenAuth" requirePermission="false" allowLocation="true"/>
    <section name="messaging" type="DotNetOpenAuth.Configuration.MessagingElement, DotNetOpenAuth" requirePermission="false" allowLocation="true"/>
    <section name="reporting" type="DotNetOpenAuth.Configuration.ReportingElement, DotNetOpenAuth" requirePermission="false" allowLocation="true"/>
    </sectionGroup>
</configSections>

<dotNetOpenAuth>
<openid>
  <relyingParty>
    <security requireSsl="false">
      <!-- Uncomment the trustedProviders tag if your relying party should only accept positive assertions from a closed set of OpenID Providers. -->
      <!--<trustedProviders rejectAssertionsFromUntrustedProviders="true">
        <add endpoint="https://www.google.com/accounts/o8/ud" />
      </trustedProviders>-->
    </security>
    <behaviors>
      <!-- The following OPTIONAL behavior allows RPs to use SREG only, but be compatible
           with OPs that use Attribute Exchange (in various formats). -->
      <add type="DotNetOpenAuth.OpenId.RelyingParty.Behaviors.AXFetchAsSregTransform, DotNetOpenAuth"/>
      <!--<add type="DotNetOpenAuth.OpenId.RelyingParty.Behaviors.GsaIcamProfile, DotNetOpenAuth" />-->
    </behaviors>
    <!-- Uncomment the following to activate the sample custom store.  -->
    <!--<store type="OpenIdRelyingPartyWebForms.CustomStore, OpenIdRelyingPartyWebForms" />-->
  </relyingParty>
</openid>
<messaging>
  <untrustedWebRequest>
    <whitelistHosts>
      <!-- since this is a sample, and will often be used with localhost -->
      <add name="localhost"/>
    </whitelistHosts>
  </untrustedWebRequest>
</messaging>
<!-- Allow DotNetOpenAuth to publish usage statistics to library authors to improve the library. -->
<reporting enabled="true"/>
</dotNetOpenAuth>
于 2012-09-20T13:27:32.847 に答える
1

あなたが私と同じ問題を抱えているかどうかはわかりませんが... 私にとっては、ユーザー名として「bob」のようなものを入力すると、openid を求められた後、このエラーが発生しました。dumdum@yahoo.com などの有効なオープン ID を入力すると、この問題は解決しました。完全にありそうもないオープン ID の例外処理をボタンで留める必要があるようです。

于 2012-09-17T18:49:19.147 に答える
0

私は最近同じ問題を抱えていましたが、問題は私のアプリケーションではなく、openID サーバー側にあることが判明しました。openID サーバーを呼び出すと、500 - internal server error が返され、アプリケーションがプロトコル例外 - No OpenID endpoint found on line をスローしましたopenId.CreateRequest(Identifier.Parse(openIdServer))

内部サーバー エラーを修正した OpenID サーバーの管理者に連絡したところ、すべて問題なく動作しました (エラー前と同様)。

なぜ DotNetOpenAuth は質問であるような愚かな例外を投げているのですか...

于 2015-04-15T05:42:41.747 に答える