我使用办公室-js-助手是为了在Outlook外接程序中获得一个OAuth令牌,这样我就可以将它与EWS一起用于OAuthCredentials (代码在使用ASP.NET web的Azure中)。
我已经将我的应用程序注册配置在我的TestOffice365个租户中(例如mytenant.onmicrosoft.com,它与托管web应用程序的Azure订阅不同--如果这很重要的话)为一个本地应用程序,oauth2AllowImplicitFlow设置为true。我使用了一个本地应用程序类型,而不是一个Web/API应用程序来绕过一个意外的错误,表明我的应用程序需要管理员的同意--即使没有请求应用程序的权限--但这是另一回事(也许我必须使用本机--不是100%确定)。
我确保应用程序注册中的重定向URI (也称为reply URL)指向与Outlook外接程序(例如https://mywebapp.azurewebsites.net/MessageRead.html)相同的页面。
这是我的应用程序清单:
{ "appId": "a11aaa11-1a5c-484a-b1d6-86c298e8f250", "appRoles": [], "availableToOtherTenants": true, "displayName": "My App", "errorUrl": null, "groupMembershipClaims": null, "optionalClaims": null, "acceptMappedClaims": null, "homepage": "https://myapp.azurewebsites.net/MessageRead.html", "identifierUris": [], "keyCredentials": [], "knownClientApplications": [], "logoutUrl": null, "oauth2AllowImplicitFlow": true, "oauth2AllowUrlPathMatching": false, "oauth2Permissions": [], "oauth2RequiredPostResponse": false, "objectId": "a11aaa11-99a1-4044-a950-937b484deb8e", "passwordCredentials": [], "publicClient": true, "supportsConvergence": null, "replyUrls": [ "https://myapp.azurewebsites.net/MessageRead.html" ], "requiredResourceAccess": [ { "resourceAppId": "00000003-0000-0000-c000-000000000000", "resourceAccess": [ { "id": "e1fe6dd8-ba31-4d61-89e7-88639da4683d", "type": "Scope" } ] }, { "resourceAppId": "00000002-0000-0000-c000-000000000000", "resourceAccess": [ { "id": "311a71cc-e848-46a1-bdf8-97ff7156d8e6", "type": "Scope" }, { "id": "a42657d6-7f20-40e3-b6f0-cee03008a62a", "type": "Scope" } ] }, { "resourceAppId": "00000002-0000-0ff1-ce00-000000000000", "resourceAccess": [ { "id": "2e83d72d-8895-4b66-9eea-abb43449ab8b", "type": "Scope" }, { "id": "ab4f2b77-0b06-4fc1-a9de-02113fc2ab7c", "type": "Scope" }, { "id": "5eb43c10-865a-4259-960a-83946678f8dd", "type": "Scope" }, { "id": "3b5f3d61-589b-4a3c-a359-5dd4b5ee5bd5", "type": "Scope" } ] } ], "samlMetadataUrl": null }
我还确保将权限URL添加到我的外接程序清单中:
<AppDomains>
<AppDomain>https://login.windows.net</AppDomain>
<AppDomain>https://login.microsoftonline.com</AppDomain>
</AppDomains>这是我在使用office-js-helpers进行身份验证的外接程序中使用的代码:
// The Office initialize function must be run each time a new page is loaded.
Office.initialize = function(reason) {
$(document).ready(function () {
// Determine if we are running inside of an authentication dialog
// If so then just terminate the running function
if (OfficeHelpers.Authenticator.isAuthDialog()) {
// Adding code here isn't guaranteed to run as we need to close the dialog
// Currently we have no realistic way of determining when the dialog is completely
// closed.
return;
}
// Create a new instance of Authenticator
var authenticator = new OfficeHelpers.Authenticator();
authenticator.endpoints.registerAzureADAuth('a11aaa11-1a5c-484a-b1d6-86c298e8f250', 'mytenant.onmicrosoft.com');
// Add event handler to the button
$('#login').click(function () {
$('#token', window.parent.document).text('Authenticating...');
authenticator.authenticate('AzureAD', true)
.then(function (token) {
// Consume and store the acess token
$('#token', window.parent.document).text(prettify(token));
authToken = token.access_token;
})
.catch(function (error) {
// Handle the error
$('#token', window.parent.document).text(prettify(error));
});
});
});
};现在,外接程序中的代码可以正确地在用户中签名并请求所需的权限,但是单击应用程序授权步骤上的Accept按钮后,将返回以下错误:
AADSTS50011:回复地址'https://mywebapp.azurewebsites.net‘与为应用程序配置的回复地址不匹配:’a11aa11-1a5c-484a-b1d6-86c298e8f250‘。更多详细信息:未指定
每次单击Login按钮时,错误都会返回(用户不再被提示登录)。它从来没有找回过记号。完整的auth URL是:
我做错了什么?问题可能是因为web应用程序的主机名(重定向URI)与承载应用注册的Azure AD租户的域名不匹配吗?如果是的话,如何从承载没有Office 365或Exchange Online的web应用程序的Azure订阅中授予Exchange Online的权限?我是否必须向我的测试Office 365租户添加Azure订阅,以便它也可以承载web应用程序??
发布于 2017-11-14 07:23:40
从您的应用程序清单中,我发现您使用https://myapp.azurewebsites.net/MessageRead.html作为replyUrls之一。下面是您用于获得用户同意的url。
如果您观察到上面的url,您将redirect_uri称为https://myapp.azurewebsites.net。但是redirect_uri应该至少与应用程序清单中提到的replyUrls中的一个匹配。
尝试在授权url中将https://myapp.azurewebsites.net替换为https://myapp.azurewebsites.net/MessageRead.html。
我已经更新了他们在下面的网址,如果你想你可以直接尝试以下网址。
https://stackoverflow.com/questions/47276315
复制相似问题