如何将tenantid分配给登录过程API中



应用程序(aspnetboilerplate(是独立的API服务。对于登录使用 tokenauthController/authenticate 作为发布请求,它正在记录,但不能在那里获取租户详细信息。由于未设置 abpsession.tenantid 。以下是代码。实际上,在尝试获取租户登录的用户的记录时,我会获得无效的abpsession值。但是没有租户,它可以正常工作。

   [AbpAllowAnonymous]
    [HttpPost]
    public async Task<AuthenticateResultModel> Authenticate([FromBody] AuthenticateModel model)
    {
        var loginResult = await GetLoginResultAsync(
            model.UserNameOrEmailAddress,
            model.Password,
            GetTenancyNameOrNull()
        );
        var accessToken = CreateAccessToken(CreateJwtClaims(loginResult.Identity));
        await _sessionAppService.GetCurrentLoginInformations();

        return new AuthenticateResultModel
        {
            AccessToken = accessToken,
            EncryptedAccessToken = GetEncrpyedAccessToken(accessToken),
            ExpireInSeconds = (int)_configuration.Expiration.TotalSeconds,
            UserId = loginResult.User.Id
        };
    }

我只是遇到了相同的问题,而您解决此问题的方法是在调用Authenticate

之前将租户ID添加到标题中

这是我的工作版本

var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("Abp.TenantId", "3234");

调用您的身份验证方法,以确保使用上述HTTPCLEINT。

例如新tokenauthserviceproxyclient(httpclient(.authenticateasync(身体:身体(;

最新更新