uju's Tech

[Node.js] Apple sign in 연동 취소 시 Server Notification 본문

Node

[Node.js] Apple sign in 연동 취소 시 Server Notification

ujusy 2021. 7. 12. 21:36

<본 포스팅은공부목적으로 작성되었습니다. 혹시 틀린 부분이 있거나 문제가 되는 부분이 있다면 답글 달아주세요!>

 

애플로 회원가입 시 사용자가 기기 내에서 앱 연결 끊기 를 할 수 있다.

 

이 경우 앱 연결을 끊게 되면 어떠한 action을 할 것인지 api를 등록하여 지정할 수 있다.

 

apple developer의 identifiers에서 App IDs를 들어간다.

소셜 로그인이 설정되어있는 app id에 들어가보자.

 

Sign in with Apple에서 Edit을 누르면 아래와 같이 나오는데 여기서 url을 설정해주면 해당 url로 웹훅이 호출된다.

 

 해당 url에 POST 방식으로 호출되므로 POST 로 요청되도록 구현해주어야한다.

 

그리고 apple이 api로 payload  라는 body값을 주는데 이는 JWT 형식이다.

 

해당 값을 decode 해보면 아래와 같이 나온다고 한다.

아래 공식 문서를 참고해보자.

https://developer.apple.com/documentation/sign_in_with_apple/processing_changes_for_sign_in_with_apple_accounts

더보기
{
    "iss": "https://appleid.apple.com",
    "aud": "com.mytest.app",
    "iat": 1508184845,
    "jti": "abede...67890",
    "events": [
        {
            "type": "email-enabled",
            "sub": "820417.faa325acbc78e1be1668ba852d492d8a.0219",
            "email": "ep9ks2tnph@privaterelay.appleid.com",
            "is_private_email": "true"
            "event_time": 1508184845
        }
    ]
}

 

근데.. 공식문서에는

events를 배열로 준다고했는데.. 

 

실제로는 

{

iss: 'https://appleid.apple.com',

aud: ',,,',

exp: 1625712202,

iat: 1625625802,

jti: ',,,',

events: '{"type":"consent-revoked","sub":"값","event_time":값}'

}

 위와 같은 형식으로 왔다.

 

객체가 아닌 string 형식이다.

 

로그를 token.envents  이런식으로 확인해서 문자열인지 몰랐는데 계속 undefinded가 떠서 다시 확인해보니 문자열이었다.

 

JSON.parse(token.events)  를 해주어 사용해주었다.

 

,,,,,, (string인거 계속 객체로 접근해서 왜 안되는지 머리 싸맸다.)ㅜㅜㅜㅜ애플 공식문서 업데이트 좀..해주세요

 

 

Comments