这是代码。我获得一个访问令牌,并使用该访问令牌创建一个客户端。如果访问令牌过期会发生什么?我需要创建另一个客户端吗?只创建一个客户端?或者每次我需要用户时,我应该调用 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) 我有一个用于 DB 的 Docker 映像(已安装 postgres),我尝试运行它,但得到以下信息:
数据库| 2018-11-27 08:29:28.849 UTC [2808] 致命:主机“172.xxx”、用户“postgres”、数据库“postgres”没有 pg_hba.conf 条目,SSL 关闭
我尝试了以下方法:
echo -e "host all all 0.0.0.0/0 trust"
我把这些都不起作用。