edamov / pushok

PHP client for Apple Push Notification Service (APNs) - Send push notifications to iOS using the new APNs HTTP/2 protocol with token-based (JWT with p8 private key)
MIT License
378 stars 120 forks source link

Started getting InvalidArgumentException "Unable to load the key." #160

Open trevorgehman opened 1 year ago

trevorgehman commented 1 year ago

Have been working fine except when we updated from 0.14.2 to 0.14.5.

I believe it is due to https://github.com/edamov/pushok/pull/158

Here is what we're doing:

       $options = [
            'key_id' => '***',
            'team_id' =>  '***',
            'app_bundle_id' =>  '***',
            'private_key_content' =>  '***',
        ];

        $tokenString = Token::create($options)->get(); // <-- Exception is thrown here

        $authProvider = Token::useExisting($tokenString, $options);

        $client = new Client($authProvider, config('apns.live'));

        // Create notifications here

        $client->addNotifications($notifications);

        $client->push();
edamov commented 1 year ago

@trevorgehman Could you please send the text of exception?

trevorgehman commented 1 year ago

Sure thing. @edamov

We downgraded back to 0.14.2 and everything works properly again. We double checked to make sure it's not a caching issue as well.

InvalidArgumentException Unable to load the key. 
    vendor/web-token/jwt-key-mgmt/KeyConverter/KeyConverter.php:214 Jose\Component\KeyManagement\KeyConverter\KeyConverter::tryToLoadECKey
    vendor/web-token/jwt-key-mgmt/KeyConverter/KeyConverter.php:194 Jose\Component\KeyManagement\KeyConverter\KeyConverter::loadKeyFromPEM
    vendor/web-token/jwt-key-mgmt/KeyConverter/KeyConverter.php:122 Jose\Component\KeyManagement\KeyConverter\KeyConverter::loadFromKey
    vendor/web-token/jwt-key-mgmt/JWKFactory.php:281 Jose\Component\KeyManagement\JWKFactory::createFromKey
    vendor/edamov/pushok/src/AuthProvider/Token.php:195 Pushok\AuthProvider\Token::generatePrivateECKey
    vendor/edamov/pushok/src/AuthProvider/Token.php:240 Pushok\AuthProvider\Token::generate
    vendor/edamov/pushok/src/AuthProvider/Token.php:111 Pushok\AuthProvider\Token::create
    app/Services/Pushok/PushokClient.php:23 Clearstream\Services\Pushok\PushokClient::Clearstream\Services\Pushok\{closure}
    vendor/laravel/framework/src/Illuminate/Cache/Repository.php:397 Illuminate\Cache\Repository::remember
    vendor/laravel/framework/src/Illuminate/Cache/CacheManager.php:419 Illuminate\Cache\CacheManager::__call
    vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:338 Illuminate\Support\Facades\Facade::__callStatic
    app/Services/Pushok/PushokClient.php:24 Clearstream\Services\Pushok\PushokClient::__construct
    [internal] ReflectionClass::newInstanceArgs
    vendor/laravel/framework/src/Illuminate/Container/Container.php:929 Illuminate\Container\Container::build
    vendor/laravel/framework/src/Illuminate/Container/Container.php:770 Illuminate\Container\Container::resolve
    vendor/laravel/framework/src/Illuminate/Foundation/Application.php:856 Illuminate\Foundation\Application::resolve
    vendor/laravel/framework/src/Illuminate/Container/Container.php:706 Illuminate\Container\Container::make
    vendor/laravel/framework/src/Illuminate/Foundation/Application.php:841 Illuminate\Foundation\Application::make
    vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:120 app
    vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:777 resolve
    app/Listeners/SendReplyIOsPushNotification.php:59 Clearstream\Listeners\SendReplyIOsPushNotification::handle
    vendor/laravel/framework/src/Illuminate/Events/CallQueuedListener.php:107 Illuminate\Events\CallQueuedListener::handle
    vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:36 Illuminate\Container\BoundMethod::Illuminate\Container\{closure}
    vendor/laravel/framework/src/Illuminate/Container/Util.php:41 Illuminate\Container\Util::unwrapIfClosure
    vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:93 Illuminate\Container\BoundMethod::callBoundMethod
    vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:37 Illuminate\Container\BoundMethod::call
    vendor/laravel/framework/src/Illuminate/Container/Container.php:661 Illuminate\Container\Container::call
    vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php:128 Illuminate\Bus\Dispatcher::Illuminate\Bus\{closure}
    vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:141 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
    vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:116 Illuminate\Pipeline\Pipeline::then
    vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php:132 Illuminate\Bus\Dispatcher::dispatchNow
    vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php:124 Illuminate\Queue\CallQueuedHandler::Illuminate\Queue\{closure}
    vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:141 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
    vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:116 Illuminate\Pipeline\Pipeline::then
    vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php:126 Illuminate\Queue\CallQueuedHandler::dispatchThroughMiddleware
    vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php:70 Illuminate\Queue\CallQueuedHandler::call
    vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php:98 Illuminate\Queue\Jobs\Job::fire
    vendor/laravel/framework/src/Illuminate/Queue/Worker.php:425 Illuminate\Queue\Worker::process
    vendor/laravel/framework/src/Illuminate/Queue/Worker.php:375 Illuminate\Queue\Worker::runJob
    vendor/laravel/framework/src/Illuminate/Queue/Worker.php:173 Illuminate\Queue\Worker::daemon
    vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php:147 Illuminate\Queue\Console\WorkCommand::runWorker
    vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php:130 Illuminate\Queue\Console\WorkCommand::handle
    vendor/laravel/horizon/src/Console/WorkCommand.php:51 Laravel\Horizon\Console\WorkCommand::handle
    vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:36 Illuminate\Container\BoundMethod::Illuminate\Container\{closure}
    vendor/laravel/framework/src/Illuminate/Container/Util.php:41 Illuminate\Container\Util::unwrapIfClosure
    vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:93 Illuminate\Container\BoundMethod::callBoundMethod
    vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:37 Illuminate\Container\BoundMethod::call
    vendor/laravel/framework/src/Illuminate/Container/Container.php:661 Illuminate\Container\Container::call
    vendor/laravel/framework/src/Illuminate/Console/Command.php:183 Illuminate\Console\Command::execute
    vendor/symfony/console/Command/Command.php:312 Symfony\Component\Console\Command\Command::run
    vendor/laravel/framework/src/Illuminate/Console/Command.php:153 Illuminate\Console\Command::run
    vendor/symfony/console/Application.php:1022 Symfony\Component\Console\Application::doRunCommand
    vendor/symfony/console/Application.php:314 Symfony\Component\Console\Application::doRun
    vendor/symfony/console/Application.php:168 Symfony\Component\Console\Application::run
    vendor/laravel/framework/src/Illuminate/Console/Application.php:102 Illuminate\Console\Application::run
    vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:155 Illuminate\Foundation\Console\Kernel::handle
    artisan:37 [main]

CleanShot 2023-02-03 at 08 38 20@2x

mha1der commented 1 year ago

I had the same problem. I think the problem is v3.0 of jwt-key-mgmt - seems to be fixed with newer versions (https://github.com/web-token/jwt-key-mgmt/commit/c2444ff948c315ff663fb2248f5cbf6f35d079b6)

paulandroshchuk commented 1 year ago

Any chance this difference can be the reason?

CleanShot 2023-05-04 at 17 45 11@2x