Skip to content

Commit

Permalink
Exvhange Lcobucci JWT with Firebase JWT
Browse files Browse the repository at this point in the history
  • Loading branch information
sasa-b committed Dec 21, 2020
1 parent b15a4cb commit 43b9423
Show file tree
Hide file tree
Showing 17 changed files with 367 additions and 263 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,19 @@ echo $response;
require '/vendor/autoload.php';

use SasaB\Apns\Client;
use SasaB\Apns\Provider\JWT;
use SasaB\Apns\Provider\TokenKey;
use SasaB\Apns\Provider\Token\JWT;
use SasaB\Apns\Provider\Token\Key;

use SasaB\Apns\Payload\Aps;
use SasaB\Apns\Payload\Alert;
use SasaB\Apns\Notification;

$tokenKey = new TokenKey('{token_key}');
$tokenKey->loadFromFile('/AuthKey.p8');
$tokenKey = Key::loadFromFile('/AuthKey_{keyId}.p8');

$jwt = JWT::new('{team_id}', $tokenKey);
$jwt = JWT::with('{team_id}', $tokenKey);

if ($jwt->hasExpired()) {
$jwt->refresh($tokenKey);
$jwt->refresh();
}

$client = Client::auth($jwt);
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
"php": ">=8.0",
"guzzlehttp/guzzle": "^6.5",
"ext-json": "*",
"lcobucci/jwt": "^4.0",
"ramsey/uuid": "^4.1"
"ramsey/uuid": "^4.1",
"firebase/php-jwt": "^5.2",
"ext-openssl": "*"
},
"require-dev": {
"phpunit/phpunit": "^9.5"
Expand Down
59 changes: 57 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions example/token.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,18 @@
use Ramsey\Uuid\Uuid;
use SasaB\Apns\Client;
use SasaB\Apns\Notification;
use SasaB\Apns\Provider\JWT;
use SasaB\Apns\Provider\TokenKey;
use SasaB\Apns\Provider\Token\JWT;
use SasaB\Apns\Provider\Token\Key;

$keyId = file_get_contents('../tests/certs/key-id.txt');
$teamId = file_get_contents('../tests/certs/team-id.txt');

$tokenKey = new TokenKey($keyId);
$tokenKey->loadFromFile('../tests/certs/AuthKey.p8');
$tokenKey = Key::loadFromFile('../tests/certs/AuthKey.p8', $keyId);

$jwt = JWT::new($teamId, $tokenKey);
$jwt = JWT::with($teamId, $tokenKey);

if ($jwt->hasExpired()) {
$jwt->refresh($tokenKey);
$jwt->refresh();
}

$client = Client::auth($jwt);
Expand Down
7 changes: 2 additions & 5 deletions src/Provider/Certificate.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ final class Certificate implements Trust
public function __construct(string $file)
{
$this->file = $file;

if (extension_loaded('openssl')) {
$cert = openssl_x509_parse(file_get_contents($file));
$this->pushTopic = $cert['subject']['UID'];
}
$cert = openssl_x509_parse(file_get_contents($file));
$this->pushTopic = $cert['subject']['UID'];
}

public static function fromFile(string $path): Certificate
Expand Down
124 changes: 0 additions & 124 deletions src/Provider/JWT.php

This file was deleted.

15 changes: 15 additions & 0 deletions src/Provider/Token/Exception.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/**
* Created by PhpStorm.
* User: [email protected]
* Date: 21. 12. 2020.
* Time: 11:32
*/

namespace SasaB\Apns\Provider\Token;


class Exception extends \LogicException
{

}
Loading

0 comments on commit 43b9423

Please sign in to comment.