@point3/logto-module 1.1.5 → 1.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/errors.ts CHANGED
@@ -56,3 +56,10 @@ export class SignOutUriGenerationError extends LogtoError {
56
56
  }
57
57
  }
58
58
 
59
+ export class PersonalAccessTokenFetchError extends LogtoError {
60
+ constructor() {
61
+ super('Personal Access Token을 사용한 액세스 토큰 발급에 실패했습니다.');
62
+ this.name = "PersonalAccessTokenFetchError";
63
+ }
64
+ }
65
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@point3/logto-module",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
4
4
  "description": "포인트3 내부 logto Authentication 모듈입니다",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -15,15 +15,17 @@
15
15
  "@nestjs/common": "^11.1.3",
16
16
  "@nestjs/config": "^4.0.2",
17
17
  "@nestjs/core": "^11.1.3",
18
+ "@nestjs/graphql": "^13.2.4",
18
19
  "@nestjs/testing": "^11.1.3",
19
20
  "axios": "^1.9.0",
20
21
  "jest": "^30.0.0",
21
22
  "jose": "^5.10.0",
22
- "point3-common-tool": "^1.0.13"
23
+ "point3-common-tool": "^1.0.31"
23
24
  },
24
25
  "devDependencies": {
25
26
  "@types/jest": "^29.5.14",
26
- "typescript": "^5.8.3"
27
+ "typescript": "^5.8.3",
28
+ "@nestjs/core": "^11.1.3"
27
29
  },
28
30
  "repository": {
29
31
  "type": "git",
@@ -1,12 +1,13 @@
1
- import {
2
- Injectable,
3
- CanActivate,
4
- ExecutionContext,
5
- UnauthorizedException,
1
+ import {
2
+ Injectable,
3
+ CanActivate,
4
+ ExecutionContext,
5
+ UnauthorizedException,
6
6
  InternalServerErrorException,
7
- Inject,
8
- HttpStatus
7
+ Inject,
8
+ HttpStatus
9
9
  } from '@nestjs/common';
10
+ import { GqlExecutionContext } from '@nestjs/graphql';
10
11
  import { Reflector } from '@nestjs/core';
11
12
  import { IncomingHttpHeaders } from 'http';
12
13
 
@@ -14,6 +15,7 @@ import { errors } from 'jose';
14
15
 
15
16
  import { p3Values } from 'point3-common-tool';
16
17
  import { LogtoTokenVerifier, LogtoTokenVerifierToken } from '../token';
18
+ import { ConfigService } from '@nestjs/config';
17
19
 
18
20
  export const LogtoTokenGuardToken = Symbol('LogtoTokenGuard');
19
21
 
@@ -21,19 +23,22 @@ export const LogtoTokenGuardToken = Symbol('LogtoTokenGuard');
21
23
  export class LogtoTokenGuard implements CanActivate {
22
24
  private reflector: Reflector = new Reflector();
23
25
  constructor(
24
- // @Inject(Reflector)
25
- // private reflector: Reflector,
26
-
27
26
  @Inject(LogtoTokenVerifierToken)
28
- private tokenVerifier: LogtoTokenVerifier
27
+ private tokenVerifier: LogtoTokenVerifier,
28
+
29
+ private configService: ConfigService
29
30
  ) { }
30
31
 
31
32
  async canActivate(context: ExecutionContext): Promise<boolean> {
33
+ if (this.configService.get<string>('NODE_ENV') === 'local') {
34
+ return true;
35
+ }
36
+
32
37
  //매타데이터에서 필요한 스코프와 역할을 가져온다.
33
38
  const requiredScopes = this.reflector.get<string[]>('requiredScopes', context.getHandler());
34
39
  const requiredRoles = this.reflector.get<string[]>('requiredRoles', context.getHandler());
35
40
 
36
- const request = context.switchToHttp().getRequest();
41
+ const request = this.getRequest(context);
37
42
 
38
43
  //헤더에서 베어러 토큰을 추출한다
39
44
  try {
@@ -75,4 +80,17 @@ export class LogtoTokenGuard implements CanActivate {
75
80
 
76
81
  return headers.authorization.slice(bearerTokenIdentifier.length + 1);
77
82
  };
83
+
84
+ private getRequest(context: ExecutionContext): any {
85
+ // Works for both REST and GraphQL
86
+ if (context.getType<'http' | 'graphql'>() === 'graphql') {
87
+ const gqlCtx = GqlExecutionContext.create(context);
88
+ // depends on what you return from GraphQLModule context: ({ req }) => ({ req })
89
+ return gqlCtx.getContext().req;
90
+ }
91
+
92
+ return context.switchToHttp().getRequest();
93
+ }
94
+
95
+
78
96
  }