如何使用 OAuth 为人和机器保护 Azure 功能? [英] How to secure Azure functions with OAuth for both humans and machines?

查看:14
本文介绍了如何使用 OAuth 为人和机器保护 Azure 功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 azure 函数应用程序,机器(客户端凭据流)和人类(授权代码流)都需要能够对其进行授权/验证.

最初,我使用易于身份验证的 Azures 开箱即用解决方案来保护功能应用程序.但是根据这个

使用此访问令牌调用 Azure 函数:

如果您使用的是 Azure AD b2c,请向我提供更详细的信息,我会为您做一些研究.

I have a functions app in azure that both a machine (client credential flow) and humans (authorization code flow) need to be able to authorize/authenticate against.

Initially I was using easy-auth, Azures out-of-the-box solution for securing functions apps. However according to this https://stackoverflow.com/a/57357226/7411328 it's not possible to use the client credentials flow with easy auth. Although I don't understand why this is. Why is it not possbile to use the same authority for two different flows with a single app registration?

Making the assumption (perhaps incorrectly) that the above is true and I have to implement JWT validation on my own.

Is there any reliable way to tell whether an API is being called by a machine or by a human?

Should I still do it with two seperate app registrations?

My understanding of these technologies might inadequate to properly ask the question, please let me know if I can do anything to clarify the question.

解决方案

As far as I know, you can use client credentials flow to call an Azure function that protected by easy-auth(AAD as auth provider).Generally ,you can try the steps below :

  1. Register an Azure AD App
  2. Getting an access token from Azure AD by request below :

URL:

POST https://login.microsoftonline.com/<your tenant ID/name>/oauth2/token

Header:

Content-Type: application/x-www-form-urlencoded

Body:

client_id=<your new resistered app ID>&
client_secret=<your new resistered app secret>&
resource=<your Azure function app ID which configed at easy-auth>&
grant_type=client_credentials

Result:

Use this access token to call Azure function :

If you are using Azure AD b2c , pls provide me with more detailed infos , and I'll do some research for you .

这篇关于如何使用 OAuth 为人和机器保护 Azure 功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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