@Injectable()
export class AzureADStrategy extends PassportStrategy(OIDCStrategy, 'azuread') {
constructor() {
super({
identityMetadata: 'https://login.microsoftonline.com/xxx/v2.0/.well-known/openid-configuration',
clientID: 'xxx',
redirectUrl: 'http://localhost/auth/azure',
responseType: 'id_token',
responseMode: 'form_post',
allowHttpForRedirectUrl: true,
passReqToCallback: true,
//customState: 'custom state test' ??
});
i tried to above code, and check passport-azure-ad docs, however, i can not get a way to pass custom state to azure ad and receive it in nestjs callback controller. please help to resolve, many thanks
It's not obvious, but you can use a custom AuthGuard for this, and override the
getAuthenticateOptionsmethod. For example, if you wanted to get the state from the initial URL's?state=<state>param:and when the auth redirects, read the state in your controller: