Logout and close session
See original GitHub issueWe are using this library along with nest. We use the following code:
import { AuthenticationService } from './authentication.service';
import { Inject } from '@nestjs/common';
import { AcInterface, IdentityBaseRepositoryInterface, IdentitySessionRepositoryInterface, ProfileRepositoryInterface } from '.';
import { EventBus } from '@nestjs/cqrs';
import { LoggingInterface } from 'shared';
import { OidcSettingsRepositoryInterface } from './oidc-settings-repository-interface';
import { IdentitySession, OidcSettings } from '../domain';
import { OIDCStrategy, IProfile, VerifyCallback } from 'passport-azure-ad';
import { Request } from 'express';
import { PassportStrategy } from '@nestjs/passport';
import { AuthenticationServiceInterface } from './authentication.service.interface';
export class OidcPassportStrategy extends PassportStrategy(OIDCStrategy) {
private static oidcService: AuthenticationServiceInterface;
constructor(
private readonly settings: OidcSettings,
@Inject('oidcService') oidcService: AuthenticationServiceInterface,
) {
super({
identityMetadata: settings.openIdProviderUrl,
clientID: settings.clientId,
responseType: settings.responseType,
responseMode: settings.responseMode,
scope: settings.scope,
redirectUrl: settings.relyingPartyUrl,
passReqToCallback: true,
useCookieInsteadOfSession: true,
cookieEncryptionKeys: [
{
key: key,
iv: iv,
},
],
},
OidcPassportStrategy.process,
);
OidcPassportStrategy.oidcService = oidcService;
}
private static process(req, profile, done) {
OidcPassportStrategy.oidcService.validateUser(profile); // This stores the session of the users in our system and creates the session
return done(null, profile.upn, profile);
}
}
async configure(_consumer: MiddlewareConsumer) {
_consumer
.apply(
authenticate('azuread-openidconnect', { session: false }),
)
.forRoutes({
path: '/auth/login',
method: RequestMethod.ALL,
});
}
And it works correctly.
However, we can’t find a way to handle the logout. We are able to destroy the sessions in our system, but cannot redirect the user to the OpenID Provider.
We tried this:
import { ApiUseTags, ApiBearerAuth, ApiOperation, ApiResponse } from '@nestjs/swagger';
import { Controller, Inject, Get, HttpCode, Post, Req, Res } from '@nestjs/common';
import { Request, Response } from 'express';
@ApiUseTags('auth')
@ApiBearerAuth()
@Controller('/auth')
export class OidcAuthenticationController {
constructor(
) { }
@Get('login')
async login(): Promise<void> {
}
@Post('login')
async oidcLogin(@Req() request: Request) {
return {
};
}
@Get('logout')
async oidcLogout(@Req() request: Request, @Res() response: Response) {
request.logout();
response.redirect('/api/v1');
}
}
Could you please point us to the documentation for this?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:8 (4 by maintainers)
Top Results From Across the Web
What are the different ways to log out or kill a session ... - Quora
There's no easy way to logout. Most websites respond to a login by creating a session token as a cookie, which the browser...
Read more >proper way to logout from a session in PHP - Stack Overflow
session_start(); // Unset all of the session variables. $_SESSION = array(); // If it's desired to kill the session, also delete the session...
Read more >End session when user closes the tab or browser without ...
Hi,. How to end the session if user closes the tab or browser without logging out. If the user opens the page on...
Read more >Closing web application with logout or IE close button - MSDN
I designed login and logout for the application. When logout is clicked, it will call a method to clear the session variables and...
Read more >Linux Kill and Logout Users Command - nixCraft
Learn how to logout Linux users forcefully. You can kill all processes and logout users with the pkill and other Linux commands.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Did you ever find an Fix or this? I have the same issue 😦
This will be handled by MSAL Node, closing.