在 Postman 中为受 Azure AD B2C 保护的 Azure Function App 请求访问令牌 [英] Request Access Token in Postman for Azure Function App protected by Azure AD B2C

查看:16
本文介绍了在 Postman 中为受 Azure AD B2C 保护的 Azure Function App 请求访问令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由 Azure Active Directory B2C 租户保护的 AspNetCore 2.0 MVC Web API.通过遵循此 SO 发布,我已经能够使用 Postman 测试 API 端点:

这就是我在 Azure B2C 租户中设置应用程序的方式:

如果我通过浏览器访问函数端点,我会成功路由到 Azure AD B2C 登录页面并可以登录,然后从 API 端点查看结果.所以我很有信心一切都很好.Azure AD B2C <-> Function App 配置.

但是,我不能使用上面链接的请求访问令牌技术来获取令牌并检查 Postman 中的端点

如果我获取身份验证后获得的令牌(例如,通过使用 fiddler 并观察返回的 id_token),并在 Postman 中选择承载身份验证并提供该 id_token,则 Postman 成功命中我的端点.但是,如果我按照上面链接文档中的步骤操作,我会得到登录"弹出窗口,然后会得到一个有效的 [正在查看] 令牌,但是当我单击使用令牌并运行请求时,我会得到 <块引用>

您无权查看此目录或页面.

我真的很希望能够像使用我的 aspnetcore 2.0 应用程序一样向邮递员请求访问令牌(真的只是为了保持一致性,所以我不必记住很多不同的技术).Azure Function Apps 是否有可能,如果可以,是否有任何线索表明我在上面做错了什么?

解决方案

啊,我偶然发现了它.我通过添加 Postman API 客户端 ID 来修复它(注意:邮递员 API 客户端 ID,而不是邮递员 App 客户端 ID)[这些引用在上面链接的 Microsoft 操作方法],在允许的令牌受众"下(在上面有问题的屏幕截图中可见).

I have an AspNetCore 2.0 MVC web API secured by an Azure Active Directory B2C tenant. I have been able to use Postman to test the API end points by following this SO posting: Request Access Token in Postman for Azure AD B2C (in particular, the Microsoft documented steps referenced in SpottedMahn's comments: https://docs.microsoft.com/en-us/aspnet/core/security/authentication/azure-ad-b2c-webapi#use-postman-to-get-a-token-and-test-the-api )

Now, I am working on a serverless version of the above - the app is pretty much identical expect that the endpoints have been implemented by Azure functions in an Azure Functions App

The Functions App has Authentication on, Log in with Azure Active Directory and the following settings:

This is how i have set up the Application in the Azure B2C tenant:

If I access the functions endpoint via a browser, I get successfully routed to the Azure AD B2C login page and can log in, then see the results from the API endpoint. So I'm pretty confident all is good w.r.t. the Azure AD B2C <-> Function App configuration.

However, I can't use the Request Access Token technique linked above to get a token and inspect the endpoint in Postman

If I take the token obtained after authentication (for example by using fiddler and observing the id_token being returned), and in Postman I choose Bearer authentication and supply that id_token, then Postman successfully hits my endpoint. However, if I follow the steps in the linked document above, I do get the "login" popup and then do get a valid [looking] token, but when I click Use Token and run the request, I get

You do not have permission to view this directory or page.

I'd really like to be able to request an access token from postman just like I can with my aspnetcore 2.0 app (really just for the consistency so I don't have to remember lots of different techniques). Is that possible for Azure Function Apps and if so, any clues what I'm doing wrong in the above?

解决方案

Ah I stumbled upon it. I fixed it by adding the Postman API client id (note: the postman API client id, not the postman App client id) [those references will make sense in the context of the Microsoft how-to linked above], under "ALLOWED TOKEN AUDIENCES" (visible in screenshot in question above).

这篇关于在 Postman 中为受 Azure AD B2C 保护的 Azure Function App 请求访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆