apple sign in php sdk
PHP 8.1 support
推薦且最簡單的安裝庫的方法是透過 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 分鐘內有效。
驗證身份令牌的第一步是產生公鑰。要產生公鑰,需要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
相容