我正在使用SharePoint Provider Hosted app。当 RER 触发器时,我正在令牌助手函数的帮助下生成客户端上下文
using (ClientContext clientContext = TokenHelper.CreateRemoteEventReceiverClientContext(eventReceiverProperties))
{
//some code
}
直到今天,一切都工作正常,但现在我收到以下错误
"XXXXXXXXX"不是目标受众 "C5925A97-CE7B-4291-A5DE-E3F28E6E210F/spapp.mydomain.net@6a3dcb79-0795-408A-A4B0-6613D78B5EB2">
我没有进行任何与代码和 Web 配置相关的更改。我从令牌助手类得到的上述错误
public static SharePointContextToken ReadAndValidateContextToken(string contextTokenString, string appHostName = null)
{
JsonWebSecurityTokenHandler tokenHandler = CreateJsonWebSecurityTokenHandler();
SecurityToken securityToken = tokenHandler.ReadToken(contextTokenString);
JsonWebSecurityToken jsonToken = securityToken as JsonWebSecurityToken;
SharePointContextToken token = SharePointContextToken.Create(jsonToken);
string stsAuthority = (new Uri(token.SecurityTokenServiceUri)).Authority;
int firstDot = stsAuthority.IndexOf('.');
GlobalEndPointPrefix = stsAuthority.Substring(0, firstDot);
AcsHostUrl = stsAuthority.Substring(firstDot + 1);
tokenHandler.ValidateToken(jsonToken);
string[] acceptableAudiences;
if (!String.IsNullOrEmpty(HostedAppHostNameOverride))
{
acceptableAudiences = HostedAppHostNameOverride.Split(';');
}
else if (appHostName == null)
{
acceptableAudiences = new[] { HostedAppHostName };
}
else
{
acceptableAudiences = new[] { appHostName };
}
bool validationSuccessful = false;
string realm = Realm ?? token.Realm;
foreach (var audience in acceptableAudiences)
{
string principal = GetFormattedPrincipal(ClientId, audience, realm);
if (StringComparer.OrdinalIgnoreCase.Equals(token.Audience, principal))
{
validationSuccessful = true;
break;
}
}
if (!validationSuccessful)
{
throw new AudienceUriValidationFailedException(
String.Format(CultureInfo.CurrentCulture,
""{0}" is not the intended audience "{1}"", String.Join(";", acceptableAudiences), token.Audience));
}
return token;
}
此错误是由于最新的 o365 更新而发生的吗? 因为自去年 1 年以来,我的应用程序运行良好。
谢谢穆赫辛·帕坦
本周我们遇到了同样的问题。解决方法是将此行包含在web.config的"appSettings"部分中:
<add key="HostedAppHostNameOverride" value="spapp.mydomain.net" />
有关该主题的更多信息