代码之家  ›  专栏  ›  技术社区  ›  ebhh2001

如何使用LoginDirect而不是loginPopup?

  •  4
  • ebhh2001  · 技术社区  · 9 年前

    example . 然而,该示例在弹出窗口中进行身份验证。我更喜欢使用重定向而不是弹出窗口。的代码 MSAL Service 弹出式身份验证如下所示:

    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; 
        };
    }
    

    如何使用 loginRedirect 而不是 loginPopup

    2 回复  |  直到 9 年前
        1
  •  2
  •   spottedmahn    9 年前

    接受你的密码 then 从…起 .loginPopup(blah).then()... 把它放在那个街区 // Called after loginRedirect or acquireTokenPopup

        2
  •  -1
  •   Fei Xue    9 年前

    而不是呼叫 loginPopup 登录时,您可以拨打 loginRedirect

    推荐文章