使用 Microsoft Azure Active Directory (Azure AD) 身份验证访问 Application Insights API | 您所在的位置:网站首页 › 验证oauth的token › 使用 Microsoft Azure Active Directory (Azure AD) 身份验证访问 Application Insights API |
你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。 使用 Microsoft Azure Active Directory (Azure AD) 身份验证访问 Application Insights API 项目 06/05/2023可以使用 Azure Monitor Application Insights 终结点 https://api.applicationinsights.io 提交查询请求。 若要访问终结点,必须通过 Azure Active Directory (Azure AD) 进行身份验证。 设置身份验证若要访问 API,请向 Azure AD 注册客户端应用并请求令牌。 在 Azure AD 中注册应用。 在应用的概述页面中,选择“API 权限”。 选择“添加权限”。 在“我的组织使用的 API”选项卡上,搜索“Application Insights”,然后从列表中选择“Application Insights API”。 选择“委托的权限”。 选中“Data.Read”复选框。 选择“添加权限”。 现在,应用已注册完成并有权使用 API,请授予你的应用对 Application Insights 资源的访问权限。 在 Application Insights 资源概述页中,选择“访问控制 (IAM)”。 选择“添加角色分配”。 选择“读取者”角色,然后选择“成员”。 在“成员”选项卡上,选择“选择成员”。 在“选择”框中,输入应用的名称。 选择应用,然后选择“选择”。 选择“查看 + 分配”。 在完成 Active Directory 设置和权限事项后,请请求授权令牌。 注意 在此示例中,我们应用了“读取者”角色。 此角色是许多内置角色之一,可能包含超过所需的权限。 可以创建更精细的角色和权限。 请求获取授权令牌在开始之前,请确保你拥有成功进行请求所需的所有值。 所有请求都需要: 你的 Azure AD 租户 ID。 App Insights 应用 ID - 如果当前使用的是 API 密钥,则这是相同的应用 ID。 该应用的 Azure AD 客户端 ID。 该应用的 Azure AD 客户端密码。Application Insights API 通过三种不同的 Azure AD OAuth2 流支持 Azure AD 身份验证: 客户端凭据 授权代码 隐式 客户端凭据流在客户端凭据流中,令牌用于 Application Insights 终结点。 使用上述在 Azure AD 中注册应用的步骤中为应用提供的凭据,发出单个请求来接收令牌。 使用 https://api.applicationinsights.io 终结点。 客户端凭据令牌 URL(POST 请求) POST //oauth2/token Host: https://login.microsoftonline.com Content-Type: application/x-www-form-urlencoded grant_type=client_credentials &client_id= &resource=https://api.applicationinsights.io &client_secret=成功的请求在响应中接收访问令牌: { token_type": "Bearer", "expires_in": "86399", "ext_expires_in": "86399", "access_token": ""eyJ0eXAiOiJKV1QiLCJ.....Ax" }在对 Application Insights 终结点的请求中使用令牌: POST /v1/apps/yous_app_id/query?timespan=P1D Host: https://api.applicationinsights.io Content-Type: application/json Authorization: bearer Body: { "query": "requests | take 10" }示例响应: "tables": [ { "name": "PrimaryResult", "columns": [ { "name": "timestamp", "type": "datetime" }, { "name": "id", "type": "string" }, { "name": "source", "type": "string" }, { "name": "name", "type": "string" }, { "name": "url", "type": "string" }, { "name": "success", "type": "string" }, { "name": "resultCode", "type": "string" }, { "name": "duration", "type": "real" }, { "name": "performanceBucket", "type": "string" }, { "name": "customDimensions", "type": "dynamic" }, { "name": "customMeasurements", "type": "dynamic" }, { "name": "operation_Name", "type": "string" }, { "name": "operation_Id", "type": "string" }, { "name": "operation_ParentId", "type": "string" }, { "name": "operation_SyntheticSource", "type": "string" }, { "name": "session_Id", "type": "string" }, { "name": "user_Id", "type": "string" }, { "name": "user_AuthenticatedId", "type": "string" }, { "name": "user_AccountId", "type": "string" }, { "name": "application_Version", "type": "string" }, { "name": "client_Type", "type": "string" }, { "name": "client_Model", "type": "string" }, { "name": "client_OS", "type": "string" }, { "name": "client_IP", "type": "string" }, { "name": "client_City", "type": "string" }, { "name": "client_StateOrProvince", "type": "string" }, { "name": "client_CountryOrRegion", "type": "string" }, { "name": "client_Browser", "type": "string" }, { "name": "cloud_RoleName", "type": "string" }, { "name": "cloud_RoleInstance", "type": "string" }, { "name": "appId", "type": "string" }, { "name": "appName", "type": "string" }, { "name": "iKey", "type": "string" }, { "name": "sdkVersion", "type": "string" }, { "name": "itemId", "type": "string" }, { "name": "itemType", "type": "string" }, { "name": "itemCount", "type": "int" } ], "rows": [ [ "2018-02-01T17:33:09.788Z", "|0qRud6jz3k0=.c32c2659_", null, "GET Reports/Index", "http://fabrikamfiberapp.azurewebsites.net/Reports", "True", "200", "3.3833", " |
CopyRight 2018-2019 实验室设备网 版权所有 |