Apple client_secret은 6개월 마다 갱신이 필요한데 Socialite와 해당 문서(링크)들의 내용을 바탕으로
매번 client_secret을 생성 및 설정했지만 Key(p8 인증서)는 Lcobucci\JWT에서 작동하지 않음.
p8(PKSC#8)→PKCS#1 standard로 변환했지만 해당 파일을 CI/CD에서 직접 추가할 수 없어
env나 config에 추가하기 위해 base64로 변환하여 해결함
openssl pkcs8 -nocrypt -in AuthKey_ABCD1234.p8 -out AuthKey.pem
base64 -i AuthKey.pem -o EncodeKey.txt
cat EncodeKey.txt
private function getToken(): void
{
$now = CarbonImmutable::now();
$token = $this->jwtConfig->builder()
->issuedBy(config('services.apple.team_id'))
->issuedAt($now)
->expiresAt($now->addHour())
->permittedFor('<https://appleid.apple.com>')
->relatedTo(config('services.apple.client_id'))
->withHeader('kid', config('services.apple.key_id'))
->getToken($this->jwtConfig->signer(), $this->jwtConfig->signingKey());
config()->set('services.apple.client_secret', $token->toString());
}
public function callback(CallbackRequest $request): array
{
config()->set('services.apple.redirect', $request->redirect_uri);
$this->getToken();
$token = Socialite::driver('apple')->getAccessTokenResponse($request->code);
$socialUser = Socialite::driver('apple')->userFromToken($token['id_token']);
logger($socialUser);
...