Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question regarding storage configuration #40

Closed
dlabey opened this issue Feb 25, 2014 · 5 comments
Closed

Question regarding storage configuration #40

dlabey opened this issue Feb 25, 2014 · 5 comments

Comments

@dlabey
Copy link

dlabey commented Feb 25, 2014

If we have Laravel set to use Redis for sessions and our storage is set to Session, will this use Redis?

@maknz
Copy link

maknz commented Mar 20, 2014

No, it uses PHP's native sessions.

@dlabey
Copy link
Author

dlabey commented Mar 30, 2014

Ok, thanks, do you have an example of how to use Redis? Otherwise I could fork your repo and then submit a pull for Redis if its not implemented yet.

@maknz
Copy link

maknz commented Mar 30, 2014

(Not my repo, I'm just a happy user!)

The underlying library actually has support for Redis, although this package doesn't have a way to instantiate it with a connected Predis instance.

I looked into it briefly (when I thought a bug I was having was due to storage - it wasn't) and implemented a LaravelRedisStorage class, which extends from OAuth\Common\Storage\Redis and implements OAuth\Common\Storage\TokenStorageInterface. All you would have to do is override the constructor to pass in a Predis instance (obtained by a \Redis::connection(), easy!) to the parent. I can't fully remember what $key and $stateKey needed to be, I dare say a closer look how the storage is instantiated might help. Note that the LaravelRedisStorage class needs to be in the OAuth\Common\Storage namespace, as that is how the storage provider is configured. It will need autoloaded separately.

@dlabey
Copy link
Author

dlabey commented Jan 7, 2015

Thank you for the answer, seeing the interface I see how it is done.

@dlabey dlabey closed this as completed Jan 7, 2015
@millar
Copy link

millar commented Jan 6, 2016

In case anyone else stumbles across this, here is my solution as suggested by @maknz.

The class I created looked like so:

<?php

namespace OAuth\Common\Storage;

use Predis\Client as Predis;

class LaravelRedisStorage extends Redis implements TokenStorageInterface {

    public function __construct()
    {
        $this->redis = \Redis::connection();
        $this->key = 'oauth_user_tokens';
        $this->stateKey = 'oauth_user_states';
        $this->cachedTokens = array();
        $this->cachedStates = array();
    }

}

I autoloaded this in my composer.json file and set it to be used in app/config/packages/artdarek/oauth-4-laravel/config.php like so:

/**
 * Storage
 */
'storage' => 'LaravelRedisStorage',

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants