c# - 从 Startup.cs 中的 API 拉取配置设置
问题描述
在我的Startup.cs
课堂上,我有以下内容
services.AddAuthentication(options =>
{
options.DefaultScheme = "cookie";
options.DefaultChallengeScheme = "oidc";
options.DefaultSignOutScheme = "oidc";
})
.AddCookie("cookie", options =>
{
options.Cookie.Name = "cookie name";
options.Cookie.SameSite = SameSiteMode.Strict;
})
.AddOpenIdConnect("oidc", options =>
{
options.Authority = "the authority URL";
options.ClientId = "the client identifier";
options.ClientSecret = "super secret";
options.Scope.Clear();
options.Scope.Add("openid");
options.Scope.Add("profile");
options.Scope.Add("api");
});
与硬编码值相反,我想调用一个 API 来获取它们。API 将返回一个名为FooAuthenticationConfiguration
.
解决方案
我不知道我是否正确地理解了您想要做什么,但请告诉我这是否适合您:
在 Startup.cs 中,创建如下方法:
private async Task GetConfiguration()
{
HttpClient client = new HttpClient();
var Response = await client.GetAsync("https://reqres.in/api/users/2");
}
将 ConfigureServices 转换为 Async 方法并在 GetConfiguration() 开始时调用,如下所示:
public async void ConfigureServices(IServiceCollection services)
{
await GetConfiguration();
//....
}
推荐阅读
- r - 如何在 sjPlot 中提高线条质量和编辑轴
- css - 如何在悬停css上应用多个元素
- office-js - 从 Excel 加载项访问 Word API,反之亦然
- react-native - 如何在本机反应中隐藏顶部导航栏
- python - 使用 LSTM 时结果中的行数错误
- python - pytest中的导入路径
- tensorflow - 如何在 tf.distribute.experimental.MultiWorkerMirroredStrategy 中合并分布式工作人员的结果
- websphere - 在“ websphere 中的 dropins 文件夹下有多个战争文件如何为每个战争生成单独的日志文件”
- c++ - 使共享指针指向一个变量
- rabbitmq - 如何使用python解决Rabbitmq中的消费者错误