![](/img/trans.png)
[英]`The property Hashtags is valid only for Exchange Exchange2015 or later versions.' when `EmailMessage.Bind`
[英]EWS using OAUth (app only) for multiple tenants throwing Access is denied /401 unauthorised on EmailMessage.Bind()
我已经注册了一个 OAuth 的应用程序,具有 Azure 和 Exchange 365 许可(完全访问作为应用程序)。
当我尝试从我的 web 应用程序访问 EmailMessage.Bind(service, fixedId, propertySet) 时,它会抛出此错误。
Microsoft.Exchange.WebServices.Data.ServiceResponseException:访问被拒绝。 检查凭据并重试。,进程未能获得正确的属性。
在所有管理员同意的情况下,也尝试提供明确的权限(日历、联系人、电子邮件设置)。
尽管我能够发送 email 并创建任务。
我有什么想念的吗? 我将不胜感激任何帮助。
谢谢,AK
更新:
我正在使用以下代码和应用程序注册(仅限应用程序): https://learn.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-authenticate-an- ews-application-by-using-oauth
我有 2 个租户 A 和 B,注册应用程序的租户 A 的帐户很好,但租户 B 的帐户失败并出现此错误:SMTP 地址没有与之关联的邮箱。
两个租户的同意和权限设置为:
允许用户同意应用
属性集是这样创建的:
var propertySet = new
PropertySet(BasePropertySet.FirstClassProperties);
if (!string.IsNullOrWhiteSpace(propertyName))
{
var extendedPropertyDefinition = new
ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings,
propertyName, MapiPropertyType.String);
propertySet.Add(extendedPropertyDefinition);
}
else
{
propertySet.Add(new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, PersonIdPropertyName, MapiPropertyType.String));
propertySet.Add(new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, PersonDataPropertyName, MapiPropertyType.String));
propertySet.Add(new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, PersonContextPropertyName, MapiPropertyType.String));
}
回答我的问题。
问题 1: “未经授权的 401 错误”是由于未在消费者租户目录中授予管理员同意。
问题 2: “SMTP 地址没有与之关联的邮箱”是由于 OAuth 在不同的租户中注册(在多租户的情况下)
如果 Auth 应用程序由多个租户提供服务,那么您需要注意两件事:
1:支持的账号应该是:任意组织目录下的账号(任意Azure AD目录-Multitenant)和个人微软账号(如Skype,Xbox)注册auth app。
2:使用'''构建应用程序生成器
代替
var cca = ConfidentialClientApplicationBuilder.Create(appId).WithClientSecret(clientSecret).WithTenantId(tenantId).Build();
例如:
如果 auth 应用程序在 A 中注册,并且您想验证租户 B 中的 office365 帐户,则租户 B 中的管理员应使用此链接https://login.microsoftonline.com/{tennatid of tenant B}/ 向管理员授予应用程序许可adminconsent?client_id={clientid of auth app} 并在创建应用程序构建器时使用权限作为“https://login.microsoftonline.com/{tenant id tenant B}。
'''
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.