Giter Club home page Giter Club logo

apple-sign-in-php-sdk's Introduction

Sign-in with Apple SDK

Installation

Recommended and easiest way to installing library is through Composer.

composer require azimolabs/apple-sign-in-php-sdk

Requirements

  • PHP 7.1+
  • OpenSSL Extension

PHP support

PHP version Library version
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

Versioning follows semver standard.

How it works

This description assumes that you already have generated identityToken . Remember that token is valid ONLY for 10 minutes.

The first step to verify the identity token is to generate a public key. To generate public key exponent and modulus values are required. Both information are exposed in Apple API endpoint. Those values differ depending on the algorithm.

The second step is verification if provided identityToken is valid against generated public key. If so we are sure that identityToken wasn't malformed.

The third step is validation if token is not expired. Additionally it is worth to check issuer and audience, examples are shown below.

Basic usage

Once you have cloned repository, make sure that composer dependencies are installed running composer install -o.

$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');

If you don't want to copy-paste above code you can paste freshly generated identityToken in tests/E2e/Auth/AppleJwtFetchingServiceTest.php:53 and run tests with simple command 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)

Todo

It is welcome to open a pull request with a fix for any issue:

Miscellaneous

apple-sign-in-php-sdk's People

Contributors

bastienuh avatar devedup avatar frogermcs avatar gerardnll avatar hywak avatar ovidiuenache avatar reibengu avatar shaggy8871 avatar smconnor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

apple-sign-in-php-sdk's Issues

Uncaught JsonException: Malformed UTF-8 characters, possibly incorrectly encoded

Hi! I'm using PHP 7.4.3 and trying to verify identity token. The response I get: Uncaught JsonException: Malformed UTF-8 characters, possibly incorrectly encoded in /home/x/domains/domain.com/public_html/apple/lcobucci/jwt/src/Parsing/Decoder.php:50. Changing to older PHP version helps, but is there any solution to make it working on >7.4.3? Thanks

Unsupported cryptographic algorithm

I have error frequently 30% happen at 1st time sign with apple
"Cryptographic algorithm W6WcOKB is not supported. Supported algorithms: 86D88Kf,eXaunmL,YuyXoY"

I use your lib code for Apple Sign feature!
Next times when I revoke apple id on app and sign again 2nd, it could be passed.

Cryptographic algorithm `fh6Bs8C` is not supported

Hello,

currently we have an issue relating to the cryptographic algorithm fh6Bs8C.
We are using package version 1.3.0 currently.
Would it be possible to integrate this in the package? Or does it exist already?

Validation of given token failed. Possibly token expired.

Even trying with php vendor/bin/phpunit vendor/azimolabs/apple-sign-in-php-sdk/tests/E2e/Auth/AppleJwtFetchingServiceTest.php with a recent token I'm only getting Validation of given token failed. Possibly token expired.

$validationData = new ValidationData();
$validationData->setIssuer('https://appleid.apple.com');
$validationData->setAudience('com.********');

$appleJwtFetchingService = new Auth\Service\AppleJwtFetchingService(
    new Auth\Jwt\JwtParser(new Parser()),
    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 RSA(),
        new Sha256()
    ),
    new Auth\Jwt\JwtValidator($validationData),
    new Auth\Factory\AppleJwtStructFactory()
);

$payload = $appleJwtFetchingService->getJwtPayload($request->id_token);

Way to handle multiple audience?

Hi, if I have two app (dev and prod) and they have different audience how can I handle that in this library?

At first I have tried this approach but it doesn't work since this library will throw exception when audience doesn't match.

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 \Lcobucci\JWT\Validation\Constraint\PermittedFor('com.c.azimo.stage2'),
                ]
      ),

Implicit conversion of keys from strings is deprecated.

Hi,

I got the error while getting access token from apple.
Implicit conversion of keys from strings is deprecated. Please use InMemory or LocalFileReference classes.

I find it cause by the problem from lcobucci/jwt 3.4.* , so I use "lcobucci/jwt": "3.3.*" in my project and it work perfectly.

The latest version of lcobucci/jwt is 4.1.x, but not released, I hasn't test it too.

email_verified and is_private_email now returned as boolean by Apple's API?

Hi,

It looks like there was a possible change in Apple's API. It now seems the is_private_email and email_verified fields are now returned as boolean rather than a string. So the code in vendor/azimolabs/apple-sign-in-php-sdk/src/Auth/Factory/AppleJwtStructFactory.php:27 is not right anymore.

See response below: (I var_dumped $claims variable)
["email_verified"]=> bool(true) ["auth_time"]=> int(REDACTED) ["nonce_supported"]=> bool(true)

Not sure what's the best way to fix this, so submitting an issue. Possible a boolval() works?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.