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
兼容