我已在 Azure 中使用 Microsoft 身份验证 (Entra ID) 创建了一个应用服务。因此,在尝试浏览应用程序时,我直接收到此信息您无权查看此目录或页面。现在,如果我在 Postman 中生成 OAuth2.0 令牌并访问该应用程序,它就可以工作。 现在的问题是 -
- 是否可以设置应用程序服务,使其在浏览时自动提示登录,而不是您无权查看此目录或页面?
是的,可以为 Azure 应用服务设置自动登录提示。
在 Azure 中创建 Azure Web 应用程序后,导航到设置 -> 身份验证 -> 添加身份提供商。
我选择 Microsoft 作为身份提供商。
我为当前租户使用了劳动力配置。
在应用程序注册类型中,我选择了
create new app registration
并且支持的帐户类型是当前 tenant-single tenant
。
选择必填字段后,我单击了添加按钮。
已成功将身份提供程序添加到 Azure Web 应用程序,如下所示。
浏览 Azure Web App URL 后,系统提示我出现一个请求应用程序注册权限的页面。
成功登录后,我将重定向到我的网页。
是否可以像OAuth一样无需用户登录,通过此Token访问App Service?
是的,无需用户登录即可通过访问令牌访问应用程序服务。
谢谢@Intelli Tech的清晰解释。
我将应用程序角色添加到我的应用程序注册中,如下所示。
我创建了新应用程序注册,我将上述应用程序角色添加到了 Api 权限。 转到 API 权限 -> 添加权限 -> 我的 API -> Azure Web 应用程序应用程序注册 -> 应用程序权限 -> 角色 -> 添加权限。 确保授予应用程序角色管理员同意。
在 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
我使用了上面的访问令牌并且能够进行身份验证。