簡體   English   中英

單租戶到多租戶

[英]Single tenant to multi-tenant

我有一個只有一個租戶的網站 MVC 5。 我使用單租戶,但有些用戶使用不同的租戶登錄我的網站。

我有這個錯誤: AADSTS50020: User account 。

你能幫我嗎?

謝謝。

我有這個錯誤: AADSTS50020: User account 。

如果您不將您的網站更新為多租戶,當其他租戶用戶想要登錄您的網站時,也會提示同樣的錯誤。

我創建了一個有多個租戶的網站,但出現 400 錯誤。

對於多租戶,您需要將您的租戶的終結點(如https://login.microsoftonline.com/contoso.onmicrosoft.com )更改為common (如https://login.microsoftonline.com/common ) . 通過這種方式,登錄請求可以發送到跨所有 Azure AD 租戶多路復用的終結點。

有關詳細信息,您可以參考此處

感謝您的回答。

我必須如何修改我的代碼:

  public partial class Startup
{
    private static string clientId = ConfigurationManager.AppSettings["ida:ClientId"];
    private static string appKey = ConfigurationManager.AppSettings["ida:ClientSecret"];
    private static string aadInstance = ConfigurationManager.AppSettings["ida:AADInstance"];
    private static string tenantId = ConfigurationManager.AppSettings["ida:TenantId"];
    private static string postLogoutRedirectUri = ConfigurationManager.AppSettings["ida:PostLogoutRedirectUri"];

    public static readonly string Authority = aadInstance + tenantId;

    // This is the resource ID of the AAD Graph API.  We'll need this to request a token to call the Graph API.
    string graphResourceId = "https://graph.windows.net";

    public void ConfigureAuth(IAppBuilder app)
    {
        ApplicationDbContext db = new ApplicationDbContext();

        app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

        app.UseCookieAuthentication(new CookieAuthenticationOptions());

        app.UseOpenIdConnectAuthentication(
            new OpenIdConnectAuthenticationOptions
            {
                ClientId = clientId,
                Authority = Authority,
                PostLogoutRedirectUri = postLogoutRedirectUri,

                Notifications = new OpenIdConnectAuthenticationNotifications()
                {

                   AuthorizationCodeReceived = (context) => 
                   {
                       var code = context.Code;
                       ClientCredential credential = new ClientCredential(clientId, appKey);
                       string signedInUserID = context.AuthenticationTicket.Identity.FindFirst(ClaimTypes.NameIdentifier).Value;
                       AuthenticationContext authContext = new AuthenticationContext(Authority, new ADALTokenCache(signedInUserID));
                       AuthenticationResult result = authContext.AcquireTokenByAuthorizationCode(
                       code, new Uri(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path)), credential, graphResourceId);

                       return Task.FromResult(0);
                   }
                }
            });
    }
}

謝謝

暫無
暫無

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

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