使用 Graph API(混合设置)访问 Exchange 2016 本地邮箱 [英] Exchange 2016 on-premise mailbox access using Graph API (Hybrid Setup)

本文介绍了使用 Graph API(混合设置)访问 Exchange 2016 本地邮箱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 prem 交换服务器上有一个邮箱(处于混合模式)abc@onprem.com 我正在尝试通过图形 api (/messages) 访问它.如果我在图形资源管理器中执行此操作,这将非常有效,但是当我通过实现执行此操作时会失败.

在 Azure 应用注册门户中提供了所需的应用权限.实现使用 grant_type 作为带有证书的 client_credentials,这非常适合云用户.

API 响应

{ '错误': {内部错误":{'日期': '2019-02-28T14:17:45',请求 ID":6a85f8c3-4e13-4cf0-84b2-ddc934241afd"},'信息': '',代码":未知错误"}}

IIS 日志

  1. 来自图表浏览器的电话

2019-02-28 15:02:31 172.31.10.98GET/api/V2.0/Users('abc@onprem.com')/Messages/$count &CorrelationID=;&cafeReqId=bc8e8aef-de46-4c72-bcf4-b4f567bc45dd;443 S-1-5-21-1392771109-4043059535-3934338706-1147 20.190.145.177Mozilla/5.0+(Macintosh;+Intel+Mac+OS+X+10_14_3)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/71.0.3578.80+Safari/537.36 - 200 0 0 287

  1. 用于来自已实施应用的调用

2019-02-28 15:00:05 172.31.10.98GET/api/V2.0/Users('abc@onprem.com')/Messages/$count &CorrelationID=;&cafeReqId=c504b658-b9df-43b5-9dbb-8e83050c3d2f;443 - 20.190.128.103- - 401 0 0 102

<块引用>

  1. 此身份验证失败的原因是什么,可能是因为该令牌是由 azure AD 提供的,它是已针对本地进行身份验证?

更新

添加了一些更多的日志记录头,发现下面是错误.

2019-03-04 04:05:13 172.31.10.98 GET/api/V2.0/Users('abc@onprem.com')/Messages &CorrelationID=;&cafeReqId=2823c302-3c84-4847-b586-accced4b6dd5;443 - 20.190.145.177 PostmanRuntime/7.6.0 - 401 0 0 332 Bearer+eyJ0 blah blah.....blah blah.....hSd mail.onprem.com - - - Bearer+client_id="00000002-0000-0ff1-ce00-000000000000",+token_types="app_asserted_user_v1+service_asserted_app_v1",+authorization_uri="https://login.windows.net/common/oauth2/authorize",+error="invalid_token" 2000001;reason="This+token+profile+'V1S2SAppOnly'+is+not+applicable+for+the+current+protocol.";error_category="invalid_token"

我们在交换服务器上使用自签名证书,这会导致这个问题吗?如果想知道图形浏览器中的一切是如何工作的.

解决方案

问题实际上出在其他地方 - Exchange 似乎不支持 client_credentials 流.但是,您可以通过以下 PowerShell 强制执行此操作(确保在应用后重新启动 IIS):

$apps = Get-PartnerApplication# Microsoft Graph 是数组中的第二个项目,如果不确定,请先调用 $apps 列出项目$apps[1] |Set-PartnerApplication -AppOnlyPermissions $apps[1].ActAsPermissions

完整的解释可以在这里找到:https://blog.thenetw.org/2019/05/13/using-client_credentials-with-microsoft-graph-in-hybrid-exchange-setup/

I have a mailbox in on prem exchange server (which is in hybrid mode) abc@onprem.com and i am trying to access this via graph api (/messages). This works perfectly if i do this in graph explorer, but fails when i do via implementation.

Required application permission is given in Azure app registration portal. Implementation uses grant_type as client_credentials with certificate and this works perfectly for cloud users.

Response of API

{ 'error': {
    'innerError': {
        'date': '2019-02-28T14:17:45', 
        'request-id': '6a85f8c3-4e13-4cf0-84b2-ddc934241afd'
    },
    'message': '', 
    'code': 'UnknownError'
    }}

IIS Logs

  1. For call came from graph explorer

2019-02-28 15:02:31 172.31.10.98GET /api/V2.0/Users('abc@onprem.com')/Messages/$count &CorrelationID=;&cafeReqId=bc8e8aef-de46-4c72-bcf4-b4f567bc45dd; 443 S-1-5-21-1392771109-4043059535-3934338706-1147 20.190.145.177Mozilla/5.0+(Macintosh;+Intel+Mac+OS+X+10_14_3)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/71.0.3578.80+Safari/537.36 - 200 0 0 287

  1. For call from implemented app

2019-02-28 15:00:05 172.31.10.98GET /api/V2.0/Users('abc@onprem.com')/Messages/$count &CorrelationID=;&cafeReqId=c504b658-b9df-43b5-9dbb-8e83050c3d2f; 443 - 20.190.128.103- - 401 0 0 102

  1. What would be reason for this authentication failure , could it be because that token is provided by azure AD which is authenticated against onprem ?

Update

Added some more headers for logging and found that below is the error.

2019-03-04 04:05:13 172.31.10.98 GET /api/V2.0/Users('abc@onprem.com')/Messages &CorrelationID=;&cafeReqId=2823c302-3c84-4847-b586-accced4b6dd5; 443 - 20.190.145.177 PostmanRuntime/7.6.0 - 401 0 0 332 Bearer+eyJ0 blah blah.....blah blah.....hSd mail.onprem.com - - - Bearer+client_id="00000002-0000-0ff1-ce00-000000000000",+token_types="app_asserted_user_v1+service_asserted_app_v1",+authorization_uri="https://login.windows.net/common/oauth2/authorize",+error="invalid_token" 2000001;reason="This+token+profile+'V1S2SAppOnly'+is+not+applicable+for+the+current+protocol.";error_category="invalid_token"

We are using self signed certificate on exchange server , can this lead to this issue ? If so wondering how everything is working from graph explorer.

解决方案

The issue is actually somewhere else - Exchange doesn't seem to support client_credentials flow. You can, however force it via following PowerShell (make sure to restart your IIS after applying):

$apps = Get-PartnerApplication
# Microsoft Graph is 2nd item in the array, if you are unsure, list the items by calling $apps first
$apps[1] | Set-PartnerApplication -AppOnlyPermissions $apps[1].ActAsPermissions

The full explanation can be found here: https://blog.thenetw.org/2019/05/13/using-client_credentials-with-microsoft-graph-in-hybrid-exchange-setup/

这篇关于使用 Graph API(混合设置)访问 Exchange 2016 本地邮箱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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