Sign in with Apple의 ID 토큰을 가져옵니다.
15150 단어 JWTOIDCOpenIdConnecttech
차리다
App ID 만들기
Certificates, Identifiers & Profiles에서 Identifiers+를 눌러 App ID를 만듭니다.
App IDs 확인
Sign in with Apple을 확인한 후 저장합니다.
서비스 ID 만들기
Certificates, Identifiers & Profiles에서 Identifiers+를 눌러 서비스 ID를 만듭니다.
Sign in with Apple을 확인한 후 Configure를 선택합니다.Identifier의 값을 기록합니다.
Domains 및 Subdomains에서 지정
example.com
하고 Returns URLs에서 지정https://example.com
합니다.example.com에 로그인한 계정의 개인 정보는 날아갈 수 있으니 건너뛰기 싫으면 날아갈 수 있는 URL을 지정해 주세요.
Keys 만들기
Certificates, Identifiers & Profiles에서 Keys+를 눌러 Keys를 생성합니다.
Sign in with Apple을 확인한 후 Configure를 선택합니다.
Primary App ID에서 방금 만든 App ID를 선택합니다.
버튼을 다운로드합니다.표시된 키 ID를 기록합니다.
다운로드한 키는 확장자
xxx.p8
, 재명명xxx.pem
이다.로그인 페이지 준비
로컬에서 다음 HTML 파일을 준비합니다.
<html>
<head>
<meta name="appleid-signin-client-id" content="xxxxx">
<meta name="appleid-signin-scope" content="name email">
<meta name="appleid-signin-redirect-uri" content="https://example.com">
<meta name="appleid-signin-state" content="aaa">
<meta name="appleid-signin-nonce" content="bbb">
<meta name="appleid-signin-use-popup" content="false">
</head>
<body>
<div id="appleid-signin" data-color="black" data-border="true" data-type="sign in"></div>
<script type="text/javascript" src="https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/en_US/appleid.auth.js"></script>
</body>
</html>
Applleid-signin-client id에서 서비스 ID의 Identifier 값을 지정하십시오.이번엔 아이디 토큰만 따면 돼, state와 nonce만 따면 돼.
서비스 ID의 Domains 및 Subdomains에 https://example.com 이외의 값을 지정하면 URL을 덮어씁니다.
jwt-cli 설치
토큰 엔드포인트는 JWT의 비밀이 필요하므로 설치jwt-cli합니다.
시험해 보다
Google Chrome으로 만든 HTML을 엽니다.POST에서 만든 정보를 보고 싶어서 개발자 도구의 네트워크 탭을 미리 엽니다.
Sign in with Apple 버튼을 선택하면 Apple ID의 로그인 화면으로 이동합니다.
로그인
Continuehttps://example.com를 선택했을 때
state
,code
,id_token
POST를 진행합니다.POST 이후의
code
및 id_token
값을 기록합니다.포스터의 아이디 토큰을 보도록 하겠습니다.
$ jwt decode eyJxxxx.xxxxx.xxxxx
Token header
------------
{
"alg": "RS256",
"kid": "xxxxx"
}
Token claims
------------
{
"aud": "xxxxx",
"auth_time": 1634526055,
"c_hash": "xxxxx",
"email": "[email protected]",
"email_verified": "true",
"exp": 1634612455,
"iat": 1634526055,
"iss": "https://appleid.apple.com",
"nonce": "bbb",
"nonce_supported": true,
"sub": "xxx"
}
라이센스 코드 및 ID 토큰 교환
비밀 생성
Creating the Client SecretGenerate and Validate Tokens의 단계에 따라 기밀을 생성합니다.
jwt-cli를 사용하여 제작할 때 다음과 같다.
jwt encode -A ES256 -k xxxxx -i xxxxx -a https://appleid.apple.com -s xxxxx -e --secret @/xxxx.pem
옵션에 다음을 지정하십시오.Keys を作成
에 표시된 Key IDService ID を作成
에 표시된 IdentifierKeys を作成
다운로드한 키 경로(jwt-cli는 확장자로 키의 형식을 판단하기 때문에 확장자는 p8이 아닌pem이어야 함)curl -X POST "https://appleid.apple.com/auth/token" \
-H 'content-type: application/x-www-form-urlencoded' \
-d 'client_id=xxx' \
-d 'client_secret=eyJxxxx.xxxxx.xxxxx' \
-d 'code=xxx' \
-d 'grant_type=authorization_code' \
-d 'redirect_uri=https://example.com'
옵션에 다음을 지정하십시오.Service ID を作成
에 표시된 Identifier(비밀 제작 시 -s와 동일シークレットの生成
에서 제작된 비밀https://example.com
의 POST 값code
appleid-signin-redirect-uri
{"access_token":"xxxxx","token_type":"Bearer","expires_in":3600,"refresh_token":"xxxxx","id_token":"eyJxxxx.xxxx.xxxx"}
$ jwt decode eyJxxxx.xxxxx.xxxxx
Token header
------------
{
"alg": "RS256",
"kid": "xxxxx"
}
Token claims
------------
{
"aud": "xxxxx",
"auth_time": 1634526055,
"c_hash": "xxxxx",
"email": "[email protected]",
"email_verified": "true",
"exp": 1634612455,
"iat": 1634526055,
"iss": "https://appleid.apple.com",
"nonce": "bbb",
"nonce_supported": true,
"sub": "xxx"
}
디코딩되었습니다.참고 자료
Reference
이 문제에 관하여(Sign in with Apple의 ID 토큰을 가져옵니다.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://zenn.dev/inabajunmr/articles/sign-in-with-apple-idtoken텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)