Yah*_*tzi 0 authentication azure passport.js passport-azure-ad nestjs
如何实施 Azure-Ad Passport 身份验证?找不到任何相关文档,并在网上阅读发现存在问题。
将 MSAL 用于前端。对于后端,请使用 Passport 和Passport-azure-ad npm。
// 我的 auth-guard.ts
import { AuthGuard, PassportStrategy } from '@nestjs/passport';
import { BearerStrategy } from 'passport-azure-ad';
import { Injectable } from '@nestjs/common';
@Injectable()
export class AzureADStrategy extends PassportStrategy(
BearerStrategy,
'azure-ad',
) {
constructor() {
super({
identityMetadata: `https://login.microsoftonline.com/${tenantID}/v2.0/.well-known/openid-configuration`,
clientID,
});
}
async validate(data) {
return data;
}
}
export const AzureADGuard = AuthGuard('azure-ad');
// app.controller.ts
@UseGuards(AzureADGuard)
@Get('/api')
get_api(): string {
return 'OK';
}
}
Run Code Online (Sandbox Code Playgroud)
尝试一下应该可以。
归档时间: |
|
查看次数: |
5815 次 |
最近记录: |