Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Jwt Laravel Package

vonage/jwt

PHP 8.1+ library to generate JWTs for authenticating with Vonage APIs. Install via Composer, create a TokenGenerator with your Vonage Application ID and private key, then call generate() to get a bearer token for requests.

View on GitHub
Deep Wiki
Context7

JWT Client Library for PHP

Contributor Covenant Build Status Latest Stable Version License codecov

This library requires a minimum PHP version of 8.1

This is the PHP library for generating JWTs to use Vonage's API. To use this, you'll need a Vonage account. Sign up for free at vonage.com/dashboard.

Installation

To use the client library you'll need to have created a Vonage account.

To install the PHP client library to your project, we recommend using Composer.

composer require vonage/jwt

You don't need to clone this repository to use this library in your own projects. Use Composer to install it from Packagist.

If you're new to Composer, here are some resources that you may find useful:

Usage

If you're using Composer, make sure the autoloader is included in your project's bootstrap file:

require_once "vendor/autoload.php";

Create a Token Generator with the Application ID and Private Key of the Vonage Application you want to access:

$generator = new Vonage\JWT\TokenGenerator('d70425f2-1599-4e4c-81c4-cffc66e49a12', file_get_contents('/path/to/private.key'));

You can then retrieve a generated JWT token by calling the generate() method on the Token Generator:

$token = $generator->generate();

This will return a string token that can be used for Bearer Authentication to Vonage APIs that require JWTs.

Examples

Generating a token with a specific Time To Live

By default, Vonage JWT tokens are generated with an Time To Live, or TTL, of 15 minutes after generation. In cases where the token lifetime should be different, you can override this setting by calling the setTTL() method on the Token Generator and passing the length of seconds that the token should be valid for

$generator->setTTL(30 * 60); // Set expiration to 30 minutes after token creation

Setting ACLs

Vonage JWTs will default to full access to all of the paths for an application, but this may not be desirable for cases where clients may need restricted access. You can specify the paths that a JWT token is valid for by using the setPaths() or addPath() methods to set the path information in bulk, or add individual paths in a more fluent interface.

// Set paths in bulk
$generator->setPaths([
    '/*/users/**',
    '/*/conversations/**'
]);

// Set paths individually
$generator->addPath('/*/users/**');
$generator->addPath('/*/conversations/**');

For more information on assigning ACL information, please see How to generate JWTs on the Vonage Developer Platform

Contributing

This library is actively developed and we love to hear from you! Please feel free to create an issue or open a pull request with your questions, comments, suggestions and feedback.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport