小编Rau*_*han的帖子

当访问令牌过期时 GraphServiceClient 会发生什么?

这是代码。我获得一个访问令牌,并使用该访问令牌创建一个客户端。如果访问令牌过期会发生什么?我需要创建另一个客户端吗?只创建一个客户端?或者每次我需要用户时,我应该调用 GetGraphServiceClient()?这将解决令牌因需要新令牌而过期的问题。如果不是,我如何验证令牌是否过期?

public async Task<GraphServiceClient> GetGraphServiceClient()
{
    var token = await GetAccessToken();

    var client = new GraphServiceClient(new DelegateAuthenticationProvider(
        (requestMessage) =>
        {
            requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
            return Task.FromResult(0);
        }));

    return client;
}

    private async Task<string> GetAccessToken()
    {
        var app = ConfidentialClientApplicationBuilder.Create(_connectionData.ClientId)
       .WithAuthority(AzureCloudInstance.AzurePublic, _connectionData.TenantId)
       .WithClientSecret(_connectionData.ClientSecret)
       .Build();

        AuthenticationResult result = null;
        try
        {
            result = await app.AcquireTokenForClient(scopes)
            .ExecuteAsync();               
        }
        catch (MsalServiceException ex)
        {
            // Case when ex.Message contains: invalid scope
        }

        return result?.AccessToken;
    }
Run Code Online (Sandbox Code Playgroud)

.net microsoft-graph-api

6
推荐指数
1
解决办法
946
查看次数

Docker postgres 映像:主机没有 pg_hba.conf 条目

我有一个用于 DB 的 Docker 映像(已安装 postgres),我尝试运行它,但得到以下信息:

数据库| 2018-11-27 08:29:28.849 UTC [2808] 致命:主机“172.xxx”、用户“postgres”、数据库“postgres”没有 pg_hba.conf 条目,SSL 关闭

我尝试了以下方法:

  • 更改IP并输入我当前机器的IP
  • 设置 Postgres 时:echo -e "host all all 0.0.0.0/0 trust"我把

这些都不起作用。

postgresql docker

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

.net ×1

docker ×1

microsoft-graph-api ×1

postgresql ×1