Angular应用程序Msal需要在新标签页中登录
创始人
2024-10-30 13:30:57
0

可以使用Msal/angular插件中的loginRedirect()方法来解决这个问题。这将导致用户在新窗口或标签页中打开身份验证页面,以避免在当前应用程序中打开身份验证页面导致应用程序状态丢失。

代码示例:

import { Component } from '@angular/core';
import * as Msal from 'msal';

const config = {
  auth: {
    clientId: '',
    authority: ''
  },
  cache: {
    cacheLocation: 'localStorage', // This configures where your cache will be stored
    storeAuthStateInCookie: true, // Set this to true if you are having issues on IE11 or Edge
  }
};

const loginRequest = {
  scopes: [ '' ]
};

const myMsal = new Msal.UserAgentApplication(config);
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'app';
  
  ngOnInit() {
    myMsal.handleRedirectCallback((error, response) => {
      if (error) {
        console.error(error);
        return;
      }
      console.log(response);
    });

    myMsal.loginRedirect(loginRequest);
  }

  logout() {
    myMsal.logout();
  }

  getToken() {
    myMsal.acquireTokenSilent(loginRequest).then(token => console.log(token));
  }
}

在此示例中,loginRedirect()方法用于在新的窗口或标签页中打开身份验证页面。该方法将重新定向到/signin-oidcURL,并设置msal.NONCE_IDTOKENcookie,以便在完成身份验证后验证正确性。

相关内容

热门资讯

透视窍门!wepoker私局辅... 透视窍门!wepoker私局辅助(WePoKer视频)竟然是真的有辅助攻略(哔哩哔哩)1、打开软件启...
透视步骤!购买的wpk辅助在哪... 透视步骤!购买的wpk辅助在哪里下载(德普之星辅助软件)果然是真的有辅助攻略(哔哩哔哩)1、完成购买...
透视妙招!hhpoker辅助软... 透视妙招!hhpoker辅助软件是真的么(德普之星透视)好像有辅助技巧(哔哩哔哩)1、金币登录送、破...
透视课程!hhpoker真能买... 透视课程!hhpoker真能买到挂吗(AApoker靠谱)好像有辅助攻略(哔哩哔哩)hhpoker真...
透视教材!pokemomo辅助... 透视教材!pokemomo辅助软件(HHpoker正品)确实是真的有辅助技巧(哔哩哔哩)暗藏猫腻,小...
透视诀窍!wepoker有插件... 透视诀窍!wepoker有插件吗(HHpoker模拟器)原来存在有辅助教程(哔哩哔哩)1、每一步都需...
透视讲义!aapoker脚本(... 透视讲义!aapoker脚本(AApoker免费)一贯存在有辅助神器(哔哩哔哩)1、操作简单,无需a...
透视经验!hhpoker怎么开... 透视经验!hhpoker怎么开透视(WePoKer咨询)竟然是真的有辅助教程(哔哩哔哩)1、进入游戏...
透视机巧!wepoker私人定... 透视机巧!wepoker私人定制透视(HHpoker内部)其实是有辅助方法(哔哩哔哩)1、进入游戏-...
透视总结!epoker底牌透视... 透视总结!epoker底牌透视(WPK四人)竟然有辅助技巧(哔哩哔哩)1.epoker底牌透视 选牌...