使用Azure Active Directory的安全APIM API,无需登录页面



我们有一个托管在Azure中的项目,通过APIM向桌面web浏览器公开API。API是安全的,只有公司员工才能通过Azure AD访问。

当用户请求资源页面时,是否可以阻止登录页面显示?请看下面的问题。

更新请参阅我基于@SureshBabu MT的回答的分步操作:

步骤1:将下面的URL输入到web浏览器中

https://login.microsoftonline.com/xx/oauth2/authorize?    
client_id=xx
redirect_uri=https://xxx.developer.azure-api.net/signin-oauth/code/callback/user-authorisation-via-oauth2
response_type=code
state=xxx
scope=
sso_reload=true
prompt=none

响应:

You have successfully authenticated.
Close <- a button, but the browser tab is not closed after clicking it.

步骤2:在下面输入目标url:

https://xx-dev.azure-api.net/echo/resource

结果:

{
statusCode: 401,
message: "Unauthorized. Access token is missing or invalid."
} 

步骤2中的请求中似乎缺少访问令牌。

只需重新迭代

当用户像上面的第2步一样输入目标URL,并且用户通过身份验证,并且请求的URL成功返回时,有可能吗?

使用提示参数函数:

OAuth 2.0授权码授予可以在安装在设备上的应用程序中使用,以访问受保护的资源,如web API

该流程使应用程序能够安全地获取可用于访问由Microsoft身份平台保护的资源的access_token

prompt=无(这将确保用户不会收到任何交互式提示)

获取/授权&prompt={none}&

none-不显示登录或同意

https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize?
client_id=6731de76-14a6-49ae-XXXX-XXXXXXXXXXX
&response_type=token
&redirect_uri=http%3A%2F%2Flocalhost%2Fmyapp%2F
&scope=https%3A%2F%2Fgraph.microsoft.com%2Fuser.read
&response_mode=fragment
&state=12345
&nonce=678910
&prompt=none
&login_hint=myuser@mycompany.com

客户端可以使用prompt参数来确保最终用户仍然存在于当前会话中或引起对请求的注意。

Prompt值设置为none,任何其他值都会出错。prompt=none参数会使Auth0立即使用指定的response_mode向指定的redirect_uri(回调URL)发送一个结果,其中包含两个可能的响应之一:成功或错误。

示例:

curl -v -k -X GET "https://localhost:9444/oauth2/authorize?
prompt=none+login&scope=openid..."

参考:https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow

最新更新