簡體   English   中英

嘗試初始化 Azure AD 時出現 404 not found 錯誤

[英]404 not found error when trying to initialize Azure AD

我正在嘗試在 ASP.NET WebForms 應用程序上實現 Azure AD。 在 Web.Config 中,我添加了以下信息:

<add key="ida:RedirectUri" value="https://localhost:44320/" />
<!--Directory_Name.onmicrosoft.com-->
<add key="ida:Tenant" value="https://login.microsoftonline.com/000..." />
<!--App ID URI of service APP-->
<add key="ida:Audience" value="https://login.microsoftonline.com/000../federationmetadata/2007-06/federationmetadata.xml?appid=00000.." />
<!--Client Application Client ID-->
<add key="ida:TrustedCallerClientId" value="000..." />

Startup.cs 文件調用包含以下方法的 Startup.Auth.cs。

   public void ConfigureAuth_Azure(IAppBuilder app)
    {
        app.UseWindowsAzureActiveDirectoryBearerAuthentication(
            new WindowsAzureActiveDirectoryBearerAuthenticationOptions
            {
                TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters()
                {
                    ValidAudience = ConfigurationManager.AppSettings["ida:Audience"]
                },
                Tenant = ConfigurationManager.AppSettings["ida:Tenant"]
            }); 
    }

一旦遇到此代碼,它就會拋出錯誤:

System.Net.Http.HttpRequestException HResult=0x80131500
消息=響應狀態代碼不表示成功:404(未找到)。 源 = 堆棧跟蹤:

嘗試使用此代碼。

    public void Configuration(IAppBuilder app)
        {
        app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
        app.UseCookieAuthentication(new CookieAuthenticationOptions());
        app.UseOpenIdConnectAuthentication(
        new OpenIdConnectAuthenticationOptions
        {
        // Sets the ClientId, authority, RedirectUri as obtained from web.config
        ClientId = clientId,
        Authority = authority,
        RedirectUri = redirectUrl,
        
        // PostLogoutRedirectUri is the page that users will be redirected to after sign-out. In this case, it is using the home page
        PostLogoutRedirectUri = redirectUrl,
        Scope = OpenIdConnectScope.OpenIdProfile,
        ResponseType = OpenIdConnectResponseType.IdToken,
        TokenValidationParameters = new TokenValidationParameters()
        {
        ValidateIssuer = false
        },
        // OpenIdConnectAuthenticationNotifications configures OWIN to send notification of failed authentications to OnAuthenticationFailed method
        Notifications = new OpenIdConnectAuthenticationNotifications
        {
        AuthenticationFailed = OnAuthenticationFailed
      }});
    }



private Task OnAuthenticationFailed(AuthenticationFailedNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions> context)
    {
    context.HandleResponse();
    context.Response.Redirect("/?errormessage=" + context.Exception.Message);
    return Task.FromResult(0);
     }

您可以在 Github 中遵循以下代碼示例
https://github.com/azure-cxp-community/Azure-CXP-Community-Engineering/tree/master/src/DeveloperTools/WebApp.OpenIdConnect.Guide

並檢查此鏈接

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM