我希望管道每六个月触发一次。这是代码扫描的合规性要求。所以我制定了一个时间表:
schedules:
- cron: "0 0 1 */6 *"
branches:
include:
- master
always: true
Run Code Online (Sandbox Code Playgroud)
但是这个管道在每次提交到 master 时都会触发。据我了解,不应该。难道我没理解预定的触发器吗?
我可以使用服务主体从https://graph.microsoft.com获取访问令牌,但是当我尝试获取https://graph.microsoft.com/.default的令牌时,出现以下错误。
如果我的代币在没有此范围的情况下发行,可能会产生什么影响?
获取令牌请求返回http错误:400和服务器响应:
{
“error”:“invalid_resource”, “error_description”:“AADSTS500011:在租户中找不到名为https://graph.microsoft.com/.default
的资源主体名为 4c000000-0000-0000-0000-0000000000。如果应用程序尚未由租户管理员安装或租户中的任何用户未同意,则可能会发生这种情况。您可能已将身份验证请求发送给了错误的租户。跟踪 ID:00-00-00-00000
相关 ID:00-00-00-000
时间戳:2020-08-06 00:17:31Z“error_codes”:[500011],
“timestamp”:“2020-08-06 00:17:31Z”,
“trace_id”:“d301a1cb-8feb-44e0-8b04-e463dd8d5b00”,
“correlation_id”:“92947479-d924- 49fd-8e29-1d7cbe70d289",
"error_uri": "https://login.microsoftonline.com/error?code=500011"
}
我正在尝试最简单的IHttpClientFactory用例
public interface IWeatherForecast
{
Task<string> Get();
}
class WeatherForecast : IWeatherForecast
{
private readonly HttpClient httpClient;
public WeatherForecast (IHttpClientFactory httpClientFactory)
{
httpClient = httpClientFactory.CreateClient();
}
public async Task<string> Get()
{
var resp = await httpClient.GetAsync("https://testwebapiforuseinsamples.azurewebsites.net/weatherforecast");
return JsonConvert.SerializeObject(resp.Content.ReadAsStringAsync());
}
}
Run Code Online (Sandbox Code Playgroud)
然后实例化它
static async Task Main(string[] args)
{
var container = new ServiceCollection();
container.AddHttpClient<IWeatherForecast, WeatherForecast>();
var serviceProvider = container.BuildServiceProvider();
var resp = await serviceProvider.GetRequiredService<WeatherForecast>().Get();
}
Run Code Online (Sandbox Code Playgroud)
但是当我运行它时,它会抛出
System.InvalidOperationException:“无法找到类型“HttpClientFactoryExample.WeatherForecast”的合适构造函数。确保类型是具体的...
有人能指出这段代码有什么问题吗?我期望在将WeatherForecast服务添加到 DI 后,我将能够从容器中获取它的初始化实例。
为了在 API 之间建立 Azure AD 系统托管标识,我在应用程序清单中为目标 API 定义了一个自定义角色。
"appRoles": [
{
"allowedMemberTypes": [
"Application"
],
"description": "Allow the application to read all things as itself.",
"displayName": "Read all things",
"id": "86a914fa-a862-4962-9975-be5c9a05dca3",
"isEnabled": true,
"lang": null,
"origin": "Application",
"value": "Things.Read.All"
}
Run Code Online (Sandbox Code Playgroud)
现在,我想将此角色分配给要调用它的 api,以便我可以在从 AzureServiceTokenProvider 收到的访问令牌中验证它。问题是我在应用程序注册中没有看到系统分配的身份。
身份(声明系统分配身份的位置)“Azure 角色分配”下有一个按钮,可用于添加角色分配。此处有可用的角色列表。我正在寻找我定义的自定义角色,它不在下拉列表中。
如何将定义的角色分配给系统身份,以便它可以访问允许的 api 或其他 api?我希望在访问令牌中获得此角色。这是正确的期望吗?