我正在使用 Angular 9 创建 Office 加载项,并且该应用程序在 Outlook 窗口中成功运行,但是当我尝试打开身份验证对话框(使用 Microsoft 登录)时,它会重定向到默认的 Windows 浏览器而不是内部弹出窗口。(Office.context.ui 不工作)
如何使用 Angular 中的登录按钮打开 Microsoft 对话框登录,如下所示? (没有约曼)
Office.context.ui.displayDialogAsync(url, options, callback);
我的代码:
索引.html:
<script src="https://appsforoffice.microsoft.com/lib/1/hosted/Office.js" type="text/javascript"></script>
主要的.ts
declare const Office: any;
Office.initialize = function () {
const platform = platformBrowserDynamic();
platform.bootstrapModule(AppModule);
};
app.module.ts
imports:[
MsalModule.forRoot({
auth: {
clientId: environment.uiClienId, // This is your client ID
authority: 'https://login.microsoftonline.com/' + environment.tenantId, // This is your tenant ID
redirectUri: environment.redirectUrl// This is your redirect URI
},
cache: {
cacheLocation: 'localStorage',
storeAuthStateInCookie: isIE, // Set to true for Internet Explorer 11
},
framework:{
isAngular:true
}
}, {
popUp: true,
consentScopes: [
'user.read',
'openid',
'profile',
],
unprotectedResources: [],
protectedResourceMap: [
['https://graph.microsoft.com/v1.0/me', ['user.read']]
],
extraQueryParameters: {}
})]
app.component.ts
myFunction() {
this.zone.run(() => {
});
login.component.ts -> Button click function (try with both function)
this.authService.loginRedirect({
extraScopesToConsent: ["user.read", "openid", "profile"]
});
或者
this.authService.loginPopup({
extraScopesToConsent: ["user.read", "openid", "profile"]
});