![](/img/trans.png)
[英]I'm unable to use a Twilio phone number for Apple Two Factor authentication
[英]how can I force users to use two factor authentication with MSAL angular?
我正在嘗試使用 msal-angular 實現雙因素登錄,我想強制用戶使用雙因素身份驗證,最好是 Authenticator App。
到目前為止,我只設法按照用戶只需要輸入密碼的方式進行配置。
我的設置:
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 { }
由於 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();
}
}
以防萬一,盡管我認為問題出在 Azure 的設置中。
編輯:有幾種方法可以通過 Azure 門戶強制進行多因素登錄,但是其中大多數只能通過付費/試用帳戶看到
是的,您可以強制用戶使用 MSAL angular 的雙重身份驗證。您的angular 配置看起來沒問題。 現在您需要重新檢查您的 azure 配置。 您可以在此處配置您的設置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.