有没有一种方法可以使用Azure B2C来编程消耗在Azure APIM中部署的REST API?

发布于 2025-02-02 18:04:04 字数 196 浏览 4 评论 0 原文

有没有一种方法可以通过编程方式进行身份验证并获取令牌而无需登录界面。我们计划从一个过程中消耗我们的API,而不是通过用户首先通过登录屏幕对其进行认证的用例。我们如何完成这项任务?

OUT API在Azure中被部署为AppService。 我们正在使用AZ B2C来集成身份验证。 我们还在APIM中添加了一项政策,以需要JWT令牌。

谢谢您的帮助

Is there a way to programmatically authenticate and get the tokens without having to login into an interface. We plan to consume our API from a process, and not from the use case in which a user authenticates first via a login screen. How do we accomplish this task?

Out API is deployed as a AppService in Azure.
We are using AZ B2C to integrate authentication.
We also added a policy in APIM to require a JWT token.

Thank you for any help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

窗影残 2025-02-09 18:04:04

有应用程序令牌和用户令牌。
您正在寻找的是应用程序令牌。

将邮递员与B2C客户端ID,客户端秘密,赠款类型..一起使用,并根据您的B2C /令牌端点发布它们以获得有效的ID_Token。

There are App tokens and user tokens.
What you are looking for is for an app token.

Use postman with B2C client ID, client secret, grant type.. and Post them against your B2C /token endpoint to get a valid id_token.

暖伴 2025-02-09 18:04:04

是的,您可以使用MSAL.NET库进行编程验证。

在此处查看“控制台/守护程序应用程序”部分:

https://learn.microsoft.com/en-us/azure/active-directory-b2c/integrate-with-with-with-app-code-code-samples#consoledaemon-apps

href =“ https://github.com/azure-samples/ms-indistity-dotnetcore-b2c-account-manage dotnetcore-b2c-account-Managements

您还可以使用OAuth 2.0资源所有者密码凭据(ROPC)B2C用户流进行编程对Azure AD B2C进行编程身份验证。这是最近的补充。

您将通过Web请求将凭据传递给适当的OAuth 2.0端点。但是,这是不可取的,因为您必须编写Web请求,并且您必须创建一个应用程序流程可以使用的“用户”帐户。

请参阅此处:
https://learn.microsoft.com/en-us/azure/active-directory-b2c/add-ropc-policy?tabs=pabs=pabs=pabs=pabs=pab-ga&pivots = b2c-user-flow < /a>

Yes, you can programmatically authenticate using the MSAL.NET library.

Check the "Console/Daemon App" section here:

https://learn.microsoft.com/en-us/azure/active-directory-b2c/integrate-with-app-code-samples#consoledaemon-apps

https://github.com/Azure-Samples/ms-identity-dotnetcore-b2c-account-management

You can also programmatically authenticate against Azure AD B2C using the OAuth 2.0 Resource Owner Password Credential (ROPC) B2C user flow. This is a recent addition.

You would pass your credentials in through a web request to the appropriate OAuth 2.0 endpoints. However, this is less desirable because you would have to write the web requests and also you would have to create a 'user' account that your app process would use to authenticate with.

See here:
https://learn.microsoft.com/en-us/azure/active-directory-b2c/add-ropc-policy?tabs=app-reg-ga&pivots=b2c-user-flow

哎呦我呸! 2025-02-09 18:04:04

感谢Juanma和Ali的建议。经过几次尝试找到解决方案的尝试,我终于找到了一种对我们有用的方法。 Juanma的评论指出了我朝正确的方向指出。我们的API托管在Azure中,我们正在使用AD B2C来利用身份验证。为了获得JWT令牌,我们使用 client_credentials grant_type 使用令牌端点,因此不需要用户身份。

https://.b2clogin.com/.onmicrosoft.com//oauth2/v2.0/token,

我们然后在Azure API Management(APIM)中创建了一个JWT策略,以验证令牌并授予对我们API的访问。

阿里,
我尝试了守护程序控制台应用程序,并努力使它起作用。另外,我们的客户不是Microsoft商店,因此我不确定他们是否可以从非Microsoft开发环境中使用MSAL.NET库。这可能吗?

谢谢你的

帮助

Thank you Juanma and Ali for your suggestions. After several attempts to try to find a solution, I finally found an approach that will work for us. Juanma's comment pointed me in the right direction. Our API is hosted in Azure and we are using AD B2C to leverage authentication. To get the JWT token we are using the token endpoint with the client_credentials grant_type so no need for a user identity.

https://.b2clogin.com/.onmicrosoft.com//oauth2/v2.0/token

We then created a JWT policy in Azure API Management (APIM) to validate the token and grant access to our APIs.

Ali,
I tried the daemon console app and struggled to make it work. Also, our clients are not Microsoft shops so I am not sure if they can use the MSAL.NET library from their non-Microsoft development environments. Is this possible?

Thank you for your help

Pedro

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文