Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 如何使用LoginDirect而不是LoginPup?_Angular_Azure Active Directory_Azure Ad B2c_Msal - Fatal编程技术网

Angular 如何使用LoginDirect而不是LoginPup?

Angular 如何使用LoginDirect而不是LoginPup?,angular,azure-active-directory,azure-ad-b2c,msal,Angular,Azure Active Directory,Azure Ad B2c,Msal,我正在尝试使用Azure AD B2C为Angular 2+应用程序实现身份验证。我觉得这很棒。但是,该示例在弹出窗口中执行身份验证。我更喜欢使用重定向而不是弹出窗口。进行弹出式身份验证的代码如下所示: import { Injectable } from '@angular/core'; declare var bootbox: any; declare var Msal:any; @Injectable() export class MsalService { access_tok

我正在尝试使用Azure AD B2C为Angular 2+应用程序实现身份验证。我觉得这很棒。但是,该示例在弹出窗口中执行身份验证。我更喜欢使用重定向而不是弹出窗口。进行弹出式身份验证的代码如下所示:

import { Injectable } from '@angular/core';
declare var bootbox: any;
declare var Msal:any;
@Injectable()
export class MsalService {

    access_token: string;

    tenantConfig = {
        tenant: "fabrikamb2c.onmicrosoft.com",
        clientID: '90c0fe63-bcf2-44d5-8fb7-b8bbc0b29dc6',
        signUpSignInPolicy: "b2c_1_susi",
        b2cScopes: ["https://fabrikamb2c.onmicrosoft.com/demoapi/demo.read"]
    };

    // Configure the authority for Azure AD B2C

    authority = "https://login.microsoftonline.com/tfp/" + this.tenantConfig.tenant + "/" + this.tenantConfig.signUpSignInPolicy;

    /*
     * B2C SignIn SignUp Policy Configuration
     */
    clientApplication = new Msal.UserAgentApplication(
        this.tenantConfig.clientID, this.authority, 
        function (errorDesc: any, token: any, error: any, tokenType: any) {
            // Called after loginRedirect or acquireTokenPopup
        }
    );

    public login(): void {
       var _this = this;
        this.clientApplication.loginPopup(this.tenantConfig.b2cScopes).then(function (idToken: any) {
            _this.clientApplication.acquireTokenSilent(_this.tenantConfig.b2cScopes).then(
                function (accessToken: any) {
                    _this.access_token = accessToken;
                }, function (error: any) {
                    _this.clientApplication.acquireTokenPopup(_this.tenantConfig.b2cScopes).then(
                        function (accessToken: any) {
                            _this.access_token = accessToken;
                        }, function (error: any) {
                            bootbox.alert("Error acquiring the popup:\n" + error);
                        });
                })
        }, function (error: any) {
            bootbox.alert("Error during login:\n" + error);
        });
    }

    logout(): void {
        this.clientApplication.logout();
    };

    isOnline(): boolean {
        return this.clientApplication.getUser() != null; 
    };
}

如何使用
loginDirect
而不是
loginPopup
更改此代码以执行相同的操作?

而不是调用
loginPopup
进行登录,你可以调用
loginDirect
函数来与Azure AD交互以进行重定向,而不是弹出窗口。

中获取你在
中的代码,然后从
中获取
。然后()
,并将其放在块中,在loginDirect或acquireTokenPopup
之后调用的

是的,我估计了很多。但是
.loginPopup
.then(function…
)后面的其余代码呢。这是怎么回事?谢谢你的回答。你是否知道为什么上面代码中的
login
函数同时调用
acquireTokenSilent
acguireTokenPopup
?它似乎应该调用其中一个,但不能同时调用两个。如果它不能以静默方式获取令牌,则必须提示用户采取一些行动,如再次登录