-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9cf3870
commit e2bb037
Showing
21 changed files
with
296 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,7 +165,7 @@ describe('AuthService', () => { | |
const user = createMock<UserEntity>({ email: '[email protected]' }) | ||
|
||
mockedJwtService.sign.mockReturnValueOnce('j.w.t') | ||
const {refresh_token, access_token} = service.signToken(user) | ||
const { refresh_token, access_token } = service.signToken(user) | ||
|
||
expect(access_token).toEqual(expect.any(String)) | ||
expect(refresh_token).toEqual(expect.any(String)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Injectable } from '@nestjs/common' | ||
import { AuthGuard } from '@nestjs/passport' | ||
|
||
@Injectable() | ||
export class JwtRefreshTokenGuard extends AuthGuard('jwt-refresh-token') {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
apps/api/src/auth/strategies/jwt-refresh-token.strategy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Request } from 'express'; | ||
import { Injectable } from '@nestjs/common'; | ||
import { PassportStrategy } from '@nestjs/passport'; | ||
import { ExtractJwt, Strategy } from 'passport-jwt'; | ||
import { AuthService } from '../auth.service'; | ||
import { JwtPayload } from '@isomera/interfaces'; | ||
|
||
@Injectable() | ||
export class JwtRefreshTokenStrategy extends PassportStrategy( | ||
Strategy, | ||
'jwt-refresh-token', | ||
) { | ||
constructor( | ||
private readonly authService: AuthService, | ||
) { | ||
super({ | ||
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(), | ||
ignoreExpiration: false, | ||
secretOrKey: process.env.APP_SECRET, | ||
passReqToCallback: true, | ||
}); | ||
} | ||
|
||
async validate(request: Request, payload: JwtPayload) { | ||
return await this.authService.getUserIfRefreshTokenMatched( | ||
payload.sub, | ||
request.headers.authorization.split('Bearer ')[1], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.