简体   繁体   English

如何强制用户对 MSAL angular 使用双因素身份验证?

[英]how can I force users to use two factor authentication with MSAL angular?

I am trying to implement two-factor sign in using msal-angular, I want to force users to use two factor authentication, preferably Authenticator App.我正在尝试使用 msal-angular 实现双因素登录,我想强制用户使用双因素身份验证,最好是 Authenticator App。

So far I only managed to configure it the way users only required to enter password.到目前为止,我只设法按照用户只需要输入密码的方式进行配置。

my settings:我的设置:

const isIE = window.navigator.userAgent.indexOf('MSIE ') > -1 || window.navigator.userAgent.indexOf('Trident/') > -1;


export const protectedResourceMap: [string, string[]][] = [
  ['https://graph.microsoft.com/v1.0/me', ['user.read']]
];


@NgModule({
  imports: [
    CommonModule,
    MsalModule.forRoot({
      auth: {
        clientId: '*******',
        authority: 'https://login.microsoftonline.com/*****/',
        validateAuthority: true,
        redirectUri: 'http://localhost:4200/',
        postLogoutRedirectUri: 'http://localhost:4200/',
        navigateToLoginRequestUrl: true,
      },
      cache: {
        cacheLocation: 'localStorage',
        storeAuthStateInCookie: isIE, // set to true for IE 11
      },
    },
      {
        popUp: !isIE,
        consentScopes: [
          'user.read',
          'openid',
          'profile',
          'api://**********/access_as_user'
        ],
        unprotectedResources: ['https://www.microsoft.com/en-us/'],
        protectedResourceMap,
        extraQueryParameters: {}
      }
    )
  ],
  declarations: [

  ],
  providers: [
    MsalLoginService,
    {
      provide: HTTP_INTERCEPTORS,
      useClass: MsalInterceptor,
      multi: true
    }
  ]
})
export class MsalLoginModule { }

due to angular version I use msal-angilar@1.1.2 here is my code:由于 angular 版本我使用 msal-angilar@1.1.2 这是我的代码:

@Injectable({
  providedIn: 'root'
})
export class MsalLoginService {
  loginDisplay = false;

  constructor(
    private broadcastService: BroadcastService,
    private authService: MsalService
  ) {
    this.checkoutAccount();

    this.authService.handleRedirectCallback((authError, response) => {
      if (authError) {
        console.error('Redirect Error: ', authError.errorMessage);
        return;
      }

      console.log('Redirect Success: ', response);
    });

    this.authService.setLogger(new Logger((logLevel, message, piiEnabled) => {
      console.log('MSAL Logging: ', message);
    }, {
      correlationId: CryptoUtils.createNewGuid(),
      piiLoggingEnabled: false
    }));

  }

  checkoutAccount() {
    this.loginDisplay = !!this.authService.getAccount();
  }

  loginPopup(): Observable<any> {
    return new Observable((subscriber) => {

      this.authService.loginPopup({ scopes: ['user.read'], prompt: 'select_account' }).then(res => {
        this.authService.acquireTokenSilent({ scopes: ['user.read'] }).then((response: any) => {
          // send token for validation on server
          subscriber.next(response);
        }).catch(ex => subscriber.error(ex));
      }).catch(ex => subscriber.error(ex));

    });
  }

  logout() {
    this.authService.logout();
  }

}

just in case although I suppose the problem is in the setting in Azure.以防万一,尽管我认为问题出在 Azure 的设置中。

Edit: There are several ways to force multi-factor login through the Azure Portal, however most of them are visible only through paid/trial account编辑:有几种方法可以通过 Azure 门户强制进行多因素登录,但是其中大多数只能通过付费/试用帐户看到

Yes, you can force users to use two factor authentication with MSAL angular. Your angular configuration is looking OK.是的,您可以强制用户使用 MSAL angular 的双重身份验证。您的angular 配置看起来没问题。 Now you need to recheck your azure configurations.现在您需要重新检查您的 azure 配置。 You can configure your settings here .您可以在此处配置您的设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我无法使用 Twilio 电话号码进行 Apple 双因素身份验证 - I'm unable to use a Twilio phone number for Apple Two Factor authentication 登录后如何获取用户名?我正在尝试使用 MSAL (@azure/msal-angular) 进行 Azure 登录 - How to get username after logged in?.I am trying with MSAL (@azure/msal-angular) for Azure Signin msal angular - 在路由上使用 MsalGuard 进行身份验证时持续重新加载 - msal angular - continuous reloading while authentication using MsalGuard on routing Twilio 双重身份验证 Model 为 Web - Twilio Two Factor Authentication Model for Web 如何让 MSAL4J 和 azure-security-keyvault-* 协同工作? - How can I make MSAL4J and azure-security-keyvault-* work together? 如何将我的数据从 firestore 转换为身份验证用户 - How do I convert my data from firestore into authentication users 如何在初始回调时从 msal-react 检索令牌? - How can I retrieve a token from msal-react on initial callback? MSAL - 如何使用 Angular 13 兼容的 MSAL 库获取 ID 令牌 - MSAL - How to get ID token using Angular 13 compatible MSAL Library 使用@azure-msal-angular 进行 Microsoft AD 身份验证时出现 performanceMeasurement.startMeasurement 错误 - performanceMeasurement.startMeasurement error when using @azure-msal-angular for Microsoft AD authentication 如何强制 devDependency 使用 AWS-CDK 中的依赖项 - How do I force a devDependency to use the dependency in AWS-CDK
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM