webfox / laravel-xero-oauth2

A Laravel integration for Xero using the Oauth 2.0 spec
MIT License
50 stars 32 forks source link

Callback details are not saved in the repository #7

Closed Cindy7979 closed 4 years ago

Cindy7979 commented 4 years ago

Hello.

I got the callback from Xero successfully but the details weren't stored in the cache.

Webfox\Xero\OauthCredentialManager.php

$this->cache->set($this->cacheKey, [
            'token'         => $token->getToken(),
            'refresh_token' => $token->getRefreshToken(),
            'id_token'      => $token->getValues()['id_token'],
            'expires'       => $token->getExpires(),
            'tenant_id'     => $tenantId ?? $this->data('tenant_id')
        ]);

After this

$this->cache->has($this->cacheKey); This code returns false and there is nothing saved.

I am using Laravel 5.6 The minimum required version is 5.5 so I hope this is not a version issue. Do I need to set up 'config/cache.php' file? If so, can you please let me know what I need to set up in the file?

Thanks.

hailwood commented 4 years ago

Hi @Cindy7979,

Can you please test if your cache is working at all?

Setup a couple of routes

Route::get('/set-cache', function() {
    Cache::put('test-cache', 'testing the cache');
});

Route::get('/get-cache', function() {
    return Cache::get('test-cache', function() {
        return 'Nothing in cache';
    });
});

Then hit /set-cache and then /get-cache and let me know what it spits out.

Cindy7979 commented 4 years ago

Hi @hailwood

Thanks for your quick reply.

I tested it but it returned 'Nothing in cache'.

Any ideas? Thanks.

hailwood commented 4 years ago

I suspect your cache driver is set to array. Try setting it to file.

Cindy7979 commented 4 years ago

Hi @hailwood

This is my config/cache.php file

return [

    /*
    |--------------------------------------------------------------------------
    | Default Cache Store
    |--------------------------------------------------------------------------
    |
    | This option controls the default cache connection that gets used while
    | using this caching library. This connection is used when another is
    | not explicitly specified when executing a given caching function.
    |
    | Supported: "apc", "array", "database", "file", "memcached", "redis"
    |
    */

    'default' => env('CACHE_DRIVER', 'file'),

    /*
    |--------------------------------------------------------------------------
    | Cache Stores
    |--------------------------------------------------------------------------
    |
    | Here you may define all of the cache "stores" for your application as
    | well as their drivers. You may even define multiple stores for the
    | same cache driver to group types of items stored in your caches.
    |
    */

    'stores' => [

        'apc' => [
            'driver' => 'apc',
        ],

        'array' => [
            'driver' => 'array',
        ],

        'database' => [
            'driver' => 'database',
            'table' => 'cache',
            'connection' => null,
        ],

        'file' => [
            'driver' => 'file',
            'path' => storage_path('framework/cache/data'),
        ],

        'memcached' => [
            'driver' => 'memcached',
            'persistent_id' => env('MEMCACHED_PERSISTENT_ID'),
            'sasl' => [
                env('MEMCACHED_USERNAME'),
                env('MEMCACHED_PASSWORD'),
            ],
            'options' => [
                // Memcached::OPT_CONNECT_TIMEOUT  => 2000,
            ],
            'servers' => [
                [
                    'host' => env('MEMCACHED_HOST', '127.0.0.1'),
                    'port' => env('MEMCACHED_PORT', 11211),
                    'weight' => 100,
                ],
            ],
        ],

        'redis' => [
            'driver' => 'redis',
            'connection' => 'default',
        ],

    ],

    /*
    |--------------------------------------------------------------------------
    | Cache Key Prefix
    |--------------------------------------------------------------------------
    |
    | When utilizing a RAM based store such as APC or Memcached, there might
    | be other applications utilizing the same cache. So, we'll specify a
    | value to get prefixed to all our keys so we can avoid collisions.
    |
    */

    'prefix' => env(
        'CACHE_PREFIX',
        str_slug(env('APP_NAME', 'laravel'), '_').'_cache'
    ),

];

It is already set as 'file'

And I retried with your code and changed 'put' to 'forever' then it returned 'testing the cache'.

Route::get('/set-cache', function() {
  Cache::forever('test-cache', 'testing the cache');
});
hailwood commented 4 years ago

Hi @Cindy7979

Can you please update this line https://github.com/webfox/laravel-xero-oauth2/blob/master/src/OauthCredentialManager.php#L90 to rememberForever instead of set and let me know if that fixes the issue for you?

If it does I'll push out an update.

accesstechnology-mike commented 4 years ago

throws the error "rememberForever() must be an instance of Closure, array given"

needs to be just 'forever'