0

我有一個租戶雲服務,我希望只能訪問我公司的員工。該解決方案具有Web角色和輔助角色。配置雲服務以使用Azure Active Directory進行身份驗證

的Web.Config

<add key="ida:Tenant" value="MyCompany.onmicrosoft.com" /> 
<add key="ida:Audience" value="https://MyCompany.onmicrosoft.com/MySolutionWebRole" /> 
<add key="ida:ClientID" value="44421xxx-xxxx-xxxx-xxxx-xxxxxxx7024" /> 
<add key="ida:Password" value="i6fMxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx4Yk=" /> 
<add key="ida:AADInstance" value="https://login.microsoftonline.com/{0}" /> 
<add key="ida:PostLogoutRedirectUri" value="https://localhost:44322/" /> 

而且,我在Cloud.config相同的設置:

<Setting name="ida.Tenant" value="MyCompany.onmicrosoft.com" /> 
<Setting name="ida.Audience" value="https://MyCompany.onmicrosoft.com/MySolutionWebRole" /> 
<Setting name="ida.ClientID" vvalue="44421xxx-xxxx-xxxx-xxxx-xxxxxxx7024" /> 
<Setting name="ida.Password" value="i6fMxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx4Yk=" /> 
<Setting name="ida.AADInstance" value="https://login.microsoftonline.com/{0}" /> 
<Setting name="ida.PostLogoutRedirectUri" value="https://localhost:44322/" /> 

移動到Startup.Auth.cs

public void ConfigureAuth(IAppBuilder app) 
    { 
     string authority = String.Format(CultureInfo.InvariantCulture, aadInstance, tenant); 
     app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType); 
     app.UseCookieAuthentication(new CookieAuthenticationOptions());  
     app.UseOpenIdConnectAuthentication(
       new OpenIdConnectAuthenticationOptions 
       { 
        ClientId = clientId, 
        Authority = authority, 
        PostLogoutRedirectUri = postLogoutRedirectUri, 
        RedirectUri = postLogoutRedirectUri, 

        Notifications = new OpenIdConnectAuthenticationNotifications 
        { 
         AuthenticationFailed = context => 
         { 
          context.HandleResponse(); 
          context.Response.Redirect("/Error?message=" + context.Exception.Message); 
          return Task.FromResult(0); 
         } 
        } 

       }); 
     } 

最後,我在我的控制器中設置了[授權]標籤。

在Azure Active Directory設置中,我已經註冊了我的cloudservice。 應用程序類型是Web應用程序/ API,多租戶是「否」。註銷網址設置爲https://localhost:44322/Account/EndSession。我沒有改變或編輯Manifest。 enter image description here enter image description here

當我試圖進入雲服務,我重定向到我的組織的登錄頁面(都好到目前爲止),但進入密碼後,我招呼我的錯誤消息。

我們在登錄時遇到問題。我們收到了非法請求。 (自由翻譯)

相關ID:21f4089f-1952-4f57-aead-173a66c1408d時間戳: 2016年9月26日10:24:14Z AADSTS90093:此應用程序需要 應用程序的權限到另一個應用程序。同意 應用程序權限只能由管理員執行。 退出並以管理員身份登錄或聯繫您的組織管理員之一。

登錄請求的URL如下(我輸入密碼的場景);

https://login.microsoftonline.com/ fd2xxxxx-XXXX-XXXX-xxxxxxxf3f2/ 的oauth2 /授權?CLIENT_ID = 444xxxxx-XXXX-XXXX-xxxxxxxx024 & REDIRECT_URI = HTTPS%3A%2F%2flocalhost%3a44322%2F & response_mode = form_post & response_type = code + id_token & scope = openid + profile & state = OpenIdConnect。AuthenticationProperties %3dYkxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

基於在 https://github.com/Azure-Samples/active-directory-dotnet-webapp-openidconnecthttps://github.com/Azure-Samples/active-directory-dotnet-webapp-multitenant-openidconnect

我是在這個問題上的任何幫助非常感激發現web應用程序我一直在尋找兩個示例解決方案

回答

0

地調我必須在Azure Active Directory應用程序註冊中編輯我的清單:

"requiredResourceAccess": [ 
    { 
     "resourceAppId": "00000002-0000-0000-c000-000000000000", 
     "resourceAccess": [ 
     { 
      "id": "311a71xxxx-xxxx-xxxx-xxxx7156d8e6", 
      "type": "Scope" 
     }, 
     { 
      "id": "5778995axxxx-xxxx-xxx-xxxx63a9f3f4d04", 
      "type": "Role" 
     } 

當我刪除最後一個條目(角色,可能是工作者角色)時,如果我想授予我的Azure AD配置文件的應用程序讀取權限,我會得到一個屏幕提示我。回答OK後,我被轉發爲localhost:44322有404到解決方案是從配置文件中刪除postLogoutRedirectUri鍵,以及去除Startup.Auth.cs

//PostLogoutRedirectUri = postLogoutRedirectUri, 
//RedirectUri = postLogoutRedirectUri, 

兩條線現在它按預期工作:)

相關問題