라이브러리를 설치하는 권장되고 가장 쉬운 방법은 Composer를 이용하는 것입니다.
composer require azimolabs/apple-sign-in-php-sdk
| PHP 버전 | 라이브러리 버전 |
|---|---|
5.x | NOT SUPPORTED |
> 7.0 <= 7.3 | 1.4.x |
>= 7.4 < 8.0 | 1.5.x |
>= 8.0 & ^7.4 | 2.0.x |
>= 8.1 | 3.0.x |
버전 관리는 semver 표준을 따릅니다.
이 설명에서는 IdentityToken 을 이미 생성했다고 가정합니다. 토큰은 10분 동안만 유효하다는 점을 기억하세요.
ID 토큰을 확인하는 첫 번째 단계는 공개 키를 생성하는 것입니다. 공개 키를 생성하려면 exponent 와 modulus 값이 필요합니다. 두 정보 모두 Apple API 엔드포인트에 노출됩니다. 해당 값은 알고리즘에 따라 다릅니다.
두 번째 단계는 제공된 identityToken 이 생성된 공개 키에 대해 유효한지 확인하는 것입니다. 그렇다면 identityToken 의 형식이 잘못되지 않았음을 확신합니다.
세 번째 단계는 토큰이 만료되지 않은 경우 유효성 검사입니다. 또한 issuer 와 audience 확인하는 것이 좋습니다. 예는 아래에 나와 있습니다.
저장소를 복제한 후에는 composer install -o 실행하여 Composer 종속성이 설치되었는지 확인하세요.
$ appleJwtFetchingService = new Auth Service AppleJwtFetchingService (
new Auth Jwt JwtParser ( new Lcobucci JWT Token Parser ( new Lcobucci JWT Encoding JoseEncoder ())),
new Auth Jwt JwtVerifier (
new Api AppleApiClient (
new GuzzleHttp Client (
[
' base_uri ' => ' https://appleid.apple.com ' ,
' timeout ' => 5 ,
' connect_timeout ' => 5 ,
]
),
new Api Factory ResponseFactory ()
),
new Lcobucci JWT Validation Validator (),
new Lcobucci JWT Signer Rsa Sha256 ()
),
new Auth Jwt JwtValidator (
new Lcobucci JWT Validation Validator (),
[
new Lcobucci JWT Validation Constraint IssuedBy ( ' https://appleid.apple.com ' ),
new Lcobucci JWT Validation Constraint PermittedFor ( ' com.c.azimo.stage ' ),
]
),
new Auth Factory AppleJwtStructFactory ()
);
$ appleJwtFetchingService -> getJwtPayload ( ' your.identity.token ' ); 위의 코드를 복사하여 붙여넣고 싶지 않은 경우 새로 생성된 identityToken tests/E2e/Auth/AppleJwtFetchingServiceTest.php:53 에 붙여넣고 간단한 명령 php vendor/bin/phpunit tests/E2e 사용하여 테스트를 실행할 수 있습니다.
$ php vendor/bin/phpunit tests/E2e
PHPUnit 9.2.5 by Sebastian Bergmann and contributors.
Random seed: 1594414420
. 1 / 1 (100%)
Time: 00:00.962, Memory: 8.00 MB
OK (1 test, 1 assertion)모든 문제에 대한 수정 사항이 포함된 풀 요청을 여는 것을 환영합니다.
phpseclib/phpseclib 버전 3.0.7 로 업그레이드하세요. lcobucci/jwt 버전 4.x 로 업그레이드합니다. 보고 내용: 문자열의 암시적 키 변환은 더 이상 사용되지 않습니다. #2 7.4.3 과 호환되게 만드세요. Uncaught JsonException에서 보고됨: 잘못된 UTF-8 문자 8.0.0 과 호환되는 라이브러리 만들기