Skip to content

Commit

Permalink
Merge pull request #139 from lscar/feature-certificate
Browse files Browse the repository at this point in the history
feat: Add support for certificate
  • Loading branch information
dwightwatson authored Mar 1, 2023
2 parents a09c69b + 37ea6bb commit b3b1fd7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,42 @@ Before using the APN Service, [enable Push Notifications in your app](https://he

Collect your Key ID, as well as your Team ID (displayed at the top right of the Apple Developer page) and app bundle ID and configure as necessary in `config/broadcasting.php`.

## JWT Token Authentication

```php
'connections' => [
'apn' => [
'key_id' => env('APN_KEY_ID'),
'team_id' => env('APN_TEAM_ID'),
'app_bundle_id' => env('APN_BUNDLE_ID'),
// Enable either `private_key_path` or `private_key_content` depending on your environment
// 'private_key_path' => env('APN_PRIVATE_KEY'),
'private_key_content' => env('APN_PRIVATE_KEY'),
'private_key_secret' => env('APN_PRIVATE_SECRET'),
'production' => env('APN_PRODUCTION', true),
],
],
```

See the [`pushok` docs](https://github.com/edamov/pushok) for more information about what arguments can be supplied to the client - for example you can also use `private_key_path` and `private_key_secret`.
See the [Establishing a token-based connection to APNs](https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/establishing_a_token-based_connection_to_apns) which will guide you how to obtain the values of the necessary parameters.

## Using Certificate (.pem) Authentication

```php
'connections' => [
'apn' => [
'app_bundle_id' => env('APN_BUNDLE_ID'),
'certificate_path' => env('APN_CERTIFICATE_PATH'),
'certificate_secret' => env('APN_CERTIFICATE_SECRET'),
'production' => env('APN_PRODUCTION', true),
],
],
```
If you are connecting with certificate based APNs, `key_id` and `team_id` are not needed. You can refer to [Send a Push Notification Using a Certificate](https://developer.apple.com/documentation/usernotifications/sending_push_notifications_using_command-line_tools#3694578)

See the [Establishing a certificate-based connection to APNs](https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/establishing_a_certificate-based_connection_to_apns) which will guide you how to obtain the values of the necessary parameters.

See the [`pushok` docs](https://github.com/edamov/pushok) for more information about what arguments can be supplied to the client.

## Usage

Expand Down
8 changes: 5 additions & 3 deletions src/ApnServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

use Illuminate\Support\Arr;
use Illuminate\Support\ServiceProvider;
use Pushok\AuthProvider\Certificate;
use Pushok\AuthProvider\Token;
use Pushok\AuthProviderInterface;
use Pushok\Client;

class ApnServiceProvider extends ServiceProvider
Expand All @@ -16,14 +18,14 @@ class ApnServiceProvider extends ServiceProvider
*/
public function register()
{
$this->app->bind(Token::class, function ($app) {
$this->app->bind(AuthProviderInterface::class, function ($app) {
$options = Arr::except($app['config']['broadcasting.connections.apn'], 'production');

return Token::create($options);
return Arr::exists($options, 'certificate_path') ? Certificate::create($options) : Token::create($options);
});

$this->app->bind(Client::class, function ($app) {
return new Client($app->make(Token::class), $app['config']['broadcasting.connections.apn.production']);
return new Client($app->make(AuthProviderInterface::class), $app['config']['broadcasting.connections.apn.production']);
});
}
}

0 comments on commit b3b1fd7

Please sign in to comment.