簡體   English   中英

Identity Server 4 多租戶注銷

[英]Identity Server 4 Multi-tenancy logout

我目前正在開發身份服務器。 它是具有多個用戶存儲庫的多租戶。

我能夠(使用 Services.OpenIDConnect.Options)將我的租戶詳細信息從我的 MVC 傳遞到 IDS,以便在登錄時將相應的用戶存儲庫 select

options.Events.OnRedirectToIdentityProvider = context =>
{                        
    context.ProtocolMessage.SetParameter("Tenant", "TenantDetail");
    return Task.CompletedTask;
};

我正在嘗試獲取相同的注銷信息,但是對注銷的初始調用有一些調用 CustomProfileService.IsActiveAsync(IsActiveContext context) 的后端進程。

我無法從 IsActiveContext 獲取租戶信息,也無法讀取任何類型的查詢字符串(就像我用於登錄一樣)。

任何建議,甚至可能比我嘗試的更正確的替代方法,將不勝感激。

注銷時不會點擊OnRedirectToIdentityProvider 您需要在客戶端的OnRedirectToIdentityProviderForSignOut事件中傳遞租戶信息。

這是一個片段,遠未完成:

services
    .AddOpenIdConnect("oidc", options =>
    {
        options.Events = new OpenIdConnectEvents
        {
            OnRedirectToIdentityProviderForSignOut = context =>
            {
                context.ProtocolMessage.AcrValues = "tenant:TenantDetail";
                return Task.CompletedTask;
            },
        }
    }

在 IdentityServer 中,您需要在請求的查詢參數中查找 acr_values。 注入 IHttpContextAccessor 以訪問上下文:

public class ProfileService : IProfileService
{
    private readonly IHttpContextAccessor _httpContextAccessor;

    public ProfileService(IHttpContextAccessor httpContextAccessor)
    {
        _httpContextAccessor = httpContextAccessor;
    }

    public async Task GetProfileDataAsync(ProfileDataRequestContext context)
    {
        // ...
    }

    public async Task IsActiveAsync(IsActiveContext context)
    {
        // Please note that this method is called on many occasions. Check context.Caller
        // This means that you'll have to make sure that the acr_valus are present on all
        // ocassions, hence the question in my comment.

        var request = _httpContextAccessor.HttpContext.Request;
        if (request.Method == HttpMethods.Get)
        {
            // acr_values should be present on all ocassions.
            var values = (string)request.Query["acr_values"];

            // This is just a sample, you'll need to parse the values.
            var tenant = values.Split(':')[1];
        }

        // Your code where you link the repository ...

        var sub = context.Subject.GetSubjectId();
        var user = await userManager.FindByIdAsync(sub);
        context.IsActive = user != null;
    }
}

請讓我知道這是否可以為您解決問題。

暫無
暫無

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

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