Azure active directory 设置什么范围和/或资源以获取可与office 365 api一起使用的令牌?
我们已在委托和应用程序中获得管理员同意Azure active directory 设置什么范围和/或资源以获取可与office 365 api一起使用的令牌?,azure-active-directory,office365,microsoft-graph-api,azure-ad-graph-api,office365api,Azure Active Directory,Office365,Microsoft Graph Api,Azure Ad Graph Api,Office365api,我们已在委托和应用程序中获得管理员同意ServiceHealth.Read在Azure AD中我们的客户端应用程序的Office 365管理API中的权限 如果我们想调用office365管理api,我们无法确定令牌获取过程中需要哪些范围和/或资源 是否为直接令牌获取的客户端\u凭证授权方法 或授权码然后是登录用户方法的令牌 如果它用于client\u凭证grant方法,则更好,但如果必须通过auth代码,也可以 我们已经可以使用以下内容获取报告,但不知道如何允许该身份验证也涵盖Office36
ServiceHealth.Read
在Azure AD中我们的客户端应用程序的Office 365管理API中的权限
如果我们想调用office365管理api,我们无法确定令牌获取过程中需要哪些范围和/或资源
是否为直接令牌获取的客户端\u凭证
授权方法
或授权码
然后是登录用户方法的令牌
如果它用于client\u凭证
grant方法,则更好,但如果必须通过auth代码,也可以
我们已经可以使用以下内容获取报告,但不知道如何允许该身份验证也涵盖Office365管理API服务运行状况
curl --location --request GET "https://login.microsoftonline.com/{tenantid}/oauth2/v2.0/token" \
--header "Content-Type: application/x-www-form-urlencoded" \
--data "client_id={clientid}&client_secret={clientsecret}&scope=https://graph.microsoft.com/.default&grant_type=client_credentials"
当添加ServiceHealth.Read
到末尾或自身时,它返回无效的\u范围作为错误
仅放置时<代码>https://manage.office.com/ServiceHealth.Read/.default
在范围中,它给出了错误无效的\u资源
,其描述包括在租户中找不到资源
尝试获取授权代码并将资源设置为ServiceHealth时出现类似问题。读取,并将其设置为作用域提供了授权代码,结果令牌被视为无效。授权代码授予流
我很快就在Azure AD应用注册中尝试了这一点,该应用注册具有Office 365管理API的代理权限
使用的范围值-https://manage.office.com/ServiceHealth.Read
我能够在授权代码授予流之后成功地获取访问令牌。我将分享稍后传递的详细请求参数,但这应该回答您关于使用什么范围值的直接问题
因为我使用了Azure AD V2端点,所以我实际上不需要指定资源。在问题中提到的示例请求中,我看到您也在使用Azure AD V2端点
详细步骤
步骤1-获取授权码
对于这一步,我直接使用浏览器,然后使用来自Azure AD租户的有效用户登录
// Line breaks only for clear reading. Remove line breaks and paste in browser URL to test.
https://login.microsoftonline.com/mytenant.onmicrosoft.com/oauth2/v2.0/authorize?
client_id=29a95b.....
&response_type=code
&redirect_uri=https://rohitapp/
&response_mode=query
&scope=https://manage.office.com/ServiceHealth.Read
&state=12345
反应应该是这样的
https://rohitapp/?code=
OAQABAAIAAACQN9QBRU....
&state=12345&session_state=f5da06....
步骤2-从令牌端点获取令牌
从上一步获取授权代码
这一步我用了邮递员。您也可以使用CURL
POST https://login.microsoftonline.com/mytenant.onmicrosoft.com/oauth2/v2.0/token
Content-Type: application/x-www-form-urlencoded
POST https://login.microsoftonline.com/mytenant.onmicrosoft.com/oauth2/v2.0/token
Content-Type: application/x-www-form-urlencoded
请求主体
client_id=29a95b....
&scope=https://manage.office.com/ServiceHealth.Read
&code=OAQABAAIAAACQN9QBRU....
&redirect_uri=https://rohitapp/
&grant_type=authorization_code
&client_secret=Aj....
client_id=29a95....
&scope=https://manage.office.com/.default
&grant_type=client_credentials
&client_secret=Aj....
接收到最终令牌,在中解码
客户端凭据授予流
使用的范围值-https://manage.office.com/.default
我确实添加了相关的应用程序许可,并对此表示同意
这次我又用了邮递员。您也可以使用CURL
POST https://login.microsoftonline.com/mytenant.onmicrosoft.com/oauth2/v2.0/token
Content-Type: application/x-www-form-urlencoded
POST https://login.microsoftonline.com/mytenant.onmicrosoft.com/oauth2/v2.0/token
Content-Type: application/x-www-form-urlencoded
请求主体
client_id=29a95b....
&scope=https://manage.office.com/ServiceHealth.Read
&code=OAQABAAIAAACQN9QBRU....
&redirect_uri=https://rohitapp/
&grant_type=authorization_code
&client_secret=Aj....
client_id=29a95....
&scope=https://manage.office.com/.default
&grant_type=client_credentials
&client_secret=Aj....
接收到最终令牌,在中解码
请查看此Microsoft文档,了解有关的范围
值
通常,对于客户端凭据,我使用https://manage.office.com/.default
form as app权限只能静态定义。@juunas谢谢!您的建议一如既往地很有帮助:)我已经编辑了答案,以便将此范围用于客户凭据授予。@juunas有效谢谢您。。。也谢谢你"罗希特·赛加尔"