-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgithub.strategy.ts
More file actions
37 lines (30 loc) · 1.11 KB
/
github.strategy.ts
File metadata and controls
37 lines (30 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { Inject, Injectable, Logger } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { PassportStrategy } from '@nestjs/passport';
import strategy from 'passport-github';
@Injectable()
export class GithubStrategy extends PassportStrategy(strategy, 'github') {
private static logger = new Logger(GithubStrategy.name);
constructor(
@Inject(ConfigService)
configService: ConfigService,
) {
const GITHUB_CLIENT_ID =
configService.getOrThrow<string>('GITHUB_CLIENT_ID');
const GITHUB_CLIENT_SECRET = configService.getOrThrow<string>(
'GITHUB_CLIENT_SECRET',
);
const SERVER_URL = configService.getOrThrow<string>('SERVER_URL');
super({
clientID: GITHUB_CLIENT_ID,
clientSecret: GITHUB_CLIENT_SECRET,
redirect_uri: `${SERVER_URL}/api/v1/auth/github/callback`,
scope: 'user:read,user:email',
state: false,
});
}
async validate(accessToken: string, refreshToken: string, profile: any) {
GithubStrategy.logger.debug(`GitHub Login Data ${JSON.stringify(profile)}`);
return { accessToken, refreshToken, profile };
}
}