gpt4 book ai didi

angular - 如何使用 loginRedirect 而不是 loginPopup?

转载 作者:太空狗 更新时间:2023-10-29 18:30:34 25 4
gpt4 key购买 nike

我正在尝试使用 Azure AD B2C 为 Angular 2+ 应用程序实现身份验证。发现这个很棒 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 更改此代码以执行相同的操作?

最佳答案

.loginPopup(blah).then()... 中获取您在 then 中的代码,并将其放入 //调用的 block 中在 loginRedirect 或 acquireTokenPopup 之后。

关于angular - 如何使用 loginRedirect 而不是 loginPopup?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46417709/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com