Reputation: 445
How can I implement Azure-Ad Passport Authentication? Can't find any documentation for it, and read online that there are problems with that.
Upvotes: 1
Views: 7361
Reputation: 1955
Use MSAL for FrontEnd.
For Backend use Passport and passport-azure-ad npm.
// my 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';
}
}
try it should work.
Upvotes: 7