-
Notifications
You must be signed in to change notification settings - Fork 14
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
aa63818
commit bc29120
Showing
11 changed files
with
88 additions
and
8 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Module } from "@nestjs/common"; | ||
import { JwtModule } from "@nestjs/jwt"; | ||
import { PassportModule } from "@nestjs/passport"; | ||
// import { AuthService } from "./auth.service"; | ||
import { jwtConstants } from "./constants"; | ||
import { JwtStrategy } from "./strategies/jwt.strategy"; | ||
// import { LocalStrategy } from "./strategies/local.strategy"; | ||
// import { AuthController } from "./auth.controller"; | ||
// import { PrismaModule } from "../prisma/prisma.module"; | ||
// import { OauthgitproviderService } from "./services/oauthgitprovider.service"; | ||
|
||
@Module({ | ||
imports: [ | ||
PassportModule, | ||
JwtModule.register({ | ||
secret: jwtConstants.secret, | ||
signOptions: { expiresIn: "10y" }, | ||
}), | ||
], | ||
controllers: [], | ||
providers: [JwtStrategy], | ||
exports: [], | ||
}) | ||
export class AuthModule {} |
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,3 @@ | ||
export const jwtConstants = { | ||
secret: "secretKey", | ||
}; |
13 changes: 13 additions & 0 deletions
13
packages/canyon-collect/src/apps/auth/guards/jwt-auth.guard.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,13 @@ | ||
import { ExecutionContext, Injectable } from "@nestjs/common"; | ||
import { AuthGuard } from "@nestjs/passport"; | ||
import { Reflector } from "@nestjs/core"; | ||
// import { IS_PUBLIC_KEY } from "../../decorators/public.decorator"; | ||
@Injectable() | ||
export class JwtAuthGuard extends AuthGuard("jwt") { | ||
constructor(private reflector: Reflector) { | ||
super(); | ||
} | ||
canActivate(context: ExecutionContext): any { | ||
return super.canActivate(context); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/canyon-collect/src/apps/auth/guards/local-auth.guard.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,5 @@ | ||
import { Injectable } from "@nestjs/common"; | ||
import { AuthGuard } from "@nestjs/passport"; | ||
|
||
@Injectable() | ||
export class LocalAuthGuard extends AuthGuard("local") {} |
19 changes: 19 additions & 0 deletions
19
packages/canyon-collect/src/apps/auth/strategies/jwt.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,19 @@ | ||
import { Injectable } from "@nestjs/common"; | ||
import { PassportStrategy } from "@nestjs/passport"; | ||
import { ExtractJwt, Strategy } from "passport-jwt"; | ||
import { jwtConstants } from "../constants"; | ||
|
||
@Injectable() | ||
export class JwtStrategy extends PassportStrategy(Strategy) { | ||
constructor() { | ||
super({ | ||
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(), | ||
ignoreExpiration: false, | ||
secretOrKey: jwtConstants.secret, | ||
}); | ||
} | ||
|
||
async validate(payload: any) { | ||
return payload; | ||
} | ||
} |
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
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