我目前正在建立一个Office365网站,用于管理onedrive和您的sharepoint文件中的文件。目前虽然我有一个问题,如果sharepoint不是根地址一(即https://mysharepoint.sharepoint.com)但是是单独的(即https://intergendev1.sharepoint.com/anothersite或https://intergendev1.sharepoint.com/sites/moarsite)我无法获得默认情况下,令牌我无法使用Office API中的令牌获取sharepoint站点的令牌。我的理论是我使用的是不正确的ResourceId或ServiceEndpointUri,目前我只使用https://intergendev1.sharepoint.com/anothersite两者,而且我无法获取令牌,但它适用于https://intergendev1.sharepoint.com/。
提前感谢您的帮助。如果有帮助,这是我的AquireToken代码:
internal static async Task<SharepointApiClient> GetExtenalSharepoint(Uri serviceEndpointUri,
string serviceResourceId)
{
var signInUserId = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;
var userObjectId = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;
AuthenticationContext authContext = new AuthenticationContext(SettingsHelper.AzureADAuthority, new AdTokenCache.AdTokenCache(signInUserId));
try
{
return new SharepointApiClient(serviceEndpointUri,
async () =>
{
var authResult = await authContext.AcquireTokenSilentAsync(serviceResourceId,
new ClientCredential(SettingsHelper.ClientId,
SettingsHelper.AppKey),
new UserIdentifier(userObjectId,
UserIdentifierType.UniqueId));
return authResult.AccessToken;
})
{
ResourceId = serviceResourceId
};
}
catch (AdalException exception)
{
//Partially handle token acquisition failure here and bubble it up to the controller
if (exception.ErrorCode == AdalError.FailedToAcquireTokenSilently)
{
authContext.TokenCache.Clear();
throw exception;
}
return null;
}
}