omniphx / forrest

A Laravel library for Salesforce
https://omniphx.github.io/forrest/
MIT License
259 stars 120 forks source link

any plans to implement the JWT Bearer Flow? #243

Closed m-lotze closed 4 years ago

m-lotze commented 4 years ago

Are there any plans to also implement the JWT bearer flow for server-to-server integration? https://help.salesforce.com/articleView?id=remoteaccess_oauth_jwt_flow.htm&type=5

Or could you maybe add a file/database store option, so the token does not get lost on php artisan cache:clear? i need a way to setup authentication once and have it working from there on, without the need to reauthenticate when the cache gets cleared.

omniphx commented 4 years ago

Definitely a great idea to support the JWT flow at some point. Just haven't seen it generate a lot of interest.

I actually like the file/database alternative too. The package is pretty open to any type of storage as long as it implements src/Omniphx/Forrest/Interfaces/StorageInterface.php

m-lotze commented 4 years ago

The package is pretty open to any type of storage as long as it implements src/Omniphx/Forrest/Interfaces/StorageInterface.php

That is right, but i think it is kind of hard to add your own storage class. Maybe i am missing something, but think it would be much easier, if you could add a config option like 'storage.class' => MyStorage::class, 'storage.type' => 'custom'. And change the method getStorageType to something like this:

protected function getStorage($storageType)
{
        $customStorage = config('forrest.storage.class');

        if ($storageType === 'custom' 
          && class_exists($customStorage) && new $customStorage() instanceof StorageInterface) {
            return new $customStorage();
        }

        switch ($storageType) {
            case 'session':
                $storage = new LaravelSession(app('config'), app('request')->session());
                break;
            case 'cache':
                $storage = new LaravelCache(app('config'), app('cache')->store());
                break;
            default:
                $storage = new LaravelSession(app('config'), app('request')->session());
        }

        return $storage;
}
cgunnels commented 4 years ago

I was looking for this as well. I already have it setup for my app, but I don't really want to rewrite all the endpoints that your lib offers.

letournj commented 4 years ago

Do you develop it ? Can I have your connexion with JWT ?

omniphx commented 4 years ago

266

omniphx commented 4 years ago

JWT authentication is implemented in Version 2.10.0. Setup guide here: https://github.com/omniphx/forrest#jwt-authentication-flow