使用客户端 ID 和密钥访问 Azure 应用服务

问题描述 投票:0回答:1

我已在 Azure 中使用 Microsoft 身份验证 (Entra ID) 创建了一个应用服务。因此,在尝试浏览应用程序时,我直接收到此信息您无权查看此目录或页面。现在,如果我在 Postman 中生成 OAuth2.0 令牌并访问该应用程序,它就可以工作。 现在的问题是 -

  1. 是否可以设置应用程序服务,使其在浏览时自动提示登录,而不是您无权查看此目录或页面
  2. 我可以使用应用程序注册客户端 ID 和密钥从 https://login.microsoftonline.com/tenant ID/oauth2/v2.0/token 创建不记名令牌。是否可以像OAuth一样无需用户登录,通过此Token访问App Service?
azure azure-web-app-service
1个回答
0
投票
  1. 是否可以设置应用程序服务,使其在浏览时自动提示登录,而不是您无权查看此目录或页面

是的,可以为 Azure 应用服务设置自动登录提示。

  • 默认情况下,Azure App服务提供授权和身份验证,无需使用任何代码。
  • 它提供了一种简单、无代码的方式来验证用户身份。它可以通过 Azure 门户启用,我们可以在其中配置 Microsoft Entra ID (Azure AD)、Facebook、Google 等身份提供商。
  • 它处理登录的各个方面,例如用户提示、重定向到身份提供商、令牌验证。

在 Azure 中创建 Azure Web 应用程序后,导航到设置 -> 身份验证 -> 添加身份提供商。

enter image description here

我选择 Microsoft 作为身份提供商。

enter image description here

我为当前租户使用了劳动力配置。

enter image description here

在应用程序注册类型中,我选择了

create new app registration
并且支持的帐户类型是当前
tenant-single tenant

enter image description here

enter image description here

选择必填字段后,我单击了添加按钮。

enter image description here

已成功将身份提供程序添加到 Azure Web 应用程序,如下所示。

enter image description here

浏览 Azure Web App URL 后,系统提示我出现一个请求应用程序注册权限的页面。

成功登录后,我将重定向到我的网页。

enter image description here

是否可以像OAuth一样无需用户登录,通过此Token访问App Service?

是的,无需用户登录即可通过访问令牌访问应用程序服务。

谢谢@Intelli Tech的清晰解释。

我将应用程序角色添加到我的应用程序注册中,如下所示。

enter image description here

我创建了新应用程序注册,我将上述应用程序角色添加到了 Api 权限。 转到 API 权限 -> 添加权限 -> 我的 API -> Azure Web 应用程序应用程序注册 -> 应用程序权限 -> 角色 -> 添加权限。 确保授予应用程序角色管理员同意。 enter image description here

在 Postman 或 VS code Thunder 客户端扩展中,我传递以下值来获取访问令牌。 在范围内客户端 ID 应是 Azure Web 应用程序客户端 ID。

Post:https://login.microsoftonline.com/{tenant-id}/oauth2/v2.0/token

grant_type=client_credentials
client_id={client-app-id}
client_secret={client-secret}
scope=api://{AzureWebApp-api-client-id}/.default

enter image description here

我使用了上面的访问令牌并且能够进行身份验证。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.