Skip to content

Commit

Permalink
Merge pull request #328 from Quickchive/fix/use-rs-256
Browse files Browse the repository at this point in the history
fix: get private key
  • Loading branch information
stae1102 authored May 11, 2024
2 parents 05f76d2 + fe094a5 commit f3c7349
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"name": "개발 디버그",
"skipFiles": ["<node_internals>/**"],
"runtimeExecutable": "npm",
"runtimeArgs": ["run", "start:dev"],
"runtimeArgs": ["run", "start:local"],
"autoAttachChildProcesses": true,
"restart": true,
"sourceMaps": true,
Expand Down
38 changes: 22 additions & 16 deletions src/auth/util/oauth.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,25 @@ import {
} from '../dtos/kakao.dto';
import { JwtService } from '@nestjs/jwt';
import appleSignin from 'apple-signin-auth';
import { ConfigService } from '@nestjs/config';

@Injectable()
export class OAuthUtil {
constructor(private readonly jwtService: JwtService) {}
constructor(
private readonly jwtService: JwtService,
private readonly configService: ConfigService,
) {}

private readonly CLIENT_ID = process.env.APPLE_CLIENT_ID;
private readonly TEAM_ID = process.env.APPLE_TEAM_ID;
private readonly PRIMARY_KEY = String(process.env.APPLE_SECRET_KEY)
private readonly APPLE_CLIENT_ID = this.configService.get('APPLE_CLIENT_ID');
private readonly APPLE_TEAM_ID = this.configService.get('APPLE_TEAM_ID');
private readonly APPLE_PRIVATE_KEY = String(
this.configService.get('APPLE_SECRET_KEY'),
)
.split(String.raw`'\n`)
.join('\n');
private readonly KEY_ID = process.env.APPLE_KEY_ID;
private readonly APPLE_KEY_ID = this.configService.get('APPLE_KEY_ID');
private readonly APPLE_REDIRECT_URI =
this.configService.get('APPLE_REDIRECT_URI');

// Get access token from Kakao Auth Server
async getKakaoAccessToken(code: string): Promise<GetKakaoAccessTokenOutput> {
Expand Down Expand Up @@ -80,21 +88,19 @@ export class OAuthUtil {
}
}

getClientSecret(): string {
return appleSignin.getClientSecret({
clientID: this.CLIENT_ID!,
teamID: this.TEAM_ID!,
privateKey: this.PRIMARY_KEY!,
keyIdentifier: this.KEY_ID!,
async getAppleToken(code: string) {
const clientSecret = appleSignin.getClientSecret({
clientID: this.APPLE_CLIENT_ID,
teamID: this.APPLE_TEAM_ID,
privateKey: this.APPLE_PRIVATE_KEY,
keyIdentifier: this.APPLE_KEY_ID,
expAfter: 300,
});
}

async getAppleToken(code: string) {
return await appleSignin.getAuthorizationToken(code, {
clientID: this.CLIENT_ID!,
redirectUri: process.env.APPLE_REDIRECT_URI!,
clientSecret: this.getClientSecret(),
clientID: this.APPLE_CLIENT_ID,
redirectUri: this.APPLE_REDIRECT_URI,
clientSecret,
});
}
}

0 comments on commit f3c7349

Please sign in to comment.