title: Problem with accessing values in Request Session that I put into
body: <p>I am fairly new to Laravel. This may have an obvious solution but I can't seem to find it so far. Therefore I am asking for help.</p>
  <p><strong>Question In Short:</strong>
  I use Illuminate\Http\Request session ($request-&gt;session()) to store some data I get from BigCommerce API. But I can't get them when I need the data.</p>
  <p><strong>Context:</strong>
  I am building a sample app/boilerplate app for BigCommerce platform using Laravel/React. I have built the app using official documentation, semi-official posts released by BigCommerce team and sample codebase provided by them as well.</p>
  <p>App works fine with local credentials from a specific store because they are given as environment variables to the app. However I can't read <code>store_hash</code> (which is necessary to fetch data from BigCommerce) and <code>access token</code>. Both I have put in $request-&gt;session() object.</p>
  <p>I will paste the AppController.php code below, also code is publicly available <a href="https://github.com/afgonullu/bigCommerce-app" rel="nofollow noreferrer">here</a>:</p>
  <p>In the <code>makeBigCommerceAPIRequest</code> method below (as you can see my debugging efforts :)) I can get <code>$this-&gt;getAppClientId()</code>, but I can't get anything from <code>$request-&gt;session()-&gt;get('store_hash')</code> or <code>$request-&gt;session()-&gt;get('access_token')</code> which returns from <code>$this-&gt;getAccessToken($request)</code>.</p>
  <p>I have tried putting store hash into a global variable, but it didn't work.</p>
  <p>From everything I have experienced so far, <code>$request</code> is not working as expected.</p>
  <p>Any help appriciated, thanks in advance.</p>
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers;
  
  use Illuminate\Http\Request;
  use Illuminate\Http\Response;
  use mysql_xdevapi\Exception;
  use Oseintow\Bigcommerce\Bigcommerce;
  use GuzzleHttp\Client;
  use GuzzleHttp\Exception\RequestException;
  use Bigcommerce\Api\Client as BigcommerceClient;
  use Illuminate\Support\Facades\Storage;
  use App\Config;  //Database Connection
  use Bigcommerce\Api\Connection;
  
  class AppController extends Controller
  {
    protected $bigcommerce;
    private $client_id;
    private $client_secret;
    private $access_token;
    private $storehash;
    private $redirect_uri;
  
    public function __construct(Bigcommerce $bigcommerce)
    {
      $this-&gt;bigcommerce = $bigcommerce;
      $this-&gt;client_id = \config('app.clientId');
      $this-&gt;client_secret = \config('app.clientSecret');
      $this-&gt;redirect_uri = \config('app.authCallback');
    }
  
    public function getAppClientId()
    {
      if (\config('app.appEnv') === 'local') {
        return \config('app.localClientId');
      } else {
        return \config('app.clientId');
      }
    }
  
    public function getAppSecret()
    {
      if (\config('app.appEnv') === 'local') {
        return \config('app.localClientSecret');
      } else {
        return \config('app.clientSecret');
      }
    }
  
    public function getAccessToken(Request $request)
    {
      if (\config('app.appEnv') === 'local') {
        return \config('app.localAccessToken');
      } else {
        return $request-&gt;session()-&gt;get('access_token');
      }
    }
  
    public function getStoreHash(Request $request)
    {
      if (\config('app.appEnv') === 'local') {
        return \config('app.localStoreHash');
      } else {
        return $request-&gt;session()-&gt;get('store_hash');
      }
    }
  
    public function error(Request $request)
    {
      $errorMessage = &quot;Internal Application Error&quot;;
  
      if ($request-&gt;session()-&gt;has('error_message')) {
        $errorMessage = $request-&gt;session()-&gt;get('error_message');
      }
  
      echo '&lt;h4&gt;An issue has occurred:&lt;/h4&gt; &lt;p&gt;' . $errorMessage . '&lt;/p&gt; &lt;a href=&quot;' . $this-&gt;baseURL . '&quot;&gt;Go back to home&lt;/a&gt;';
    }
  
    public function load(Request $request)
    {
      $signedPayload = $request-&gt;get('signed_payload');
      if (!empty($signedPayload)) {
        echo &quot;hello&quot;;
        $verifiedSignedRequestData = $this-&gt;verifySignedRequest($signedPayload);
        if ($verifiedSignedRequestData !== null) {
          echo &quot;positive return&quot;;
  
          $request-&gt;session()-&gt;put('user_id', $verifiedSignedRequestData['user']['id']);
          $request-&gt;session()-&gt;put('user_email', $verifiedSignedRequestData['user']['email']);
          $request-&gt;session()-&gt;put('owner_id', $verifiedSignedRequestData['owner']['id']);
          $request-&gt;session()-&gt;put('owner_email', $verifiedSignedRequestData['owner']['email']);
          $request-&gt;session()-&gt;put('store_hash', $verifiedSignedRequestData['context']);
          echo $request-&gt;session()-&gt;get('store_hash');
          $this-&gt;storehash = $verifiedSignedRequestData['context'];
          echo '   store hash is at the moment : ' . $this-&gt;storehash . '      .....';
        } else {
          return &quot;The signed request from BigCommerce could not be validated.&quot;;
          // return redirect()-&gt;action([AppController::class, 'error'])-&gt;with('error_message', 'The signed request from BigCommerce could not be validated.');
        }
      } else {
        return &quot;The signed request from BigCommerce was empty.&quot;;
        // return redirect()-&gt;action([AppController::class, 'error'])-&gt;with('error_message', 'The signed request from BigCommerce was empty.');
      }
  
      return redirect(\config('app.appUrl'));
    }
  
    public function install(Request $request)
    {
      // Make sure all required query params have been passed
      if (!$request-&gt;has('code') || !$request-&gt;has('scope') || !$request-&gt;has('context')) {
        echo 'Not enough information was passed to install this app.';
        // return redirect()-&gt;action('MainController@error')-&gt;with('error_message', 'Not enough information was passed to install this app.');
      }
  
      try {
        $client = new Client();
        $result = $client-&gt;request('POST', 'https://login.bigcommerce.com/oauth2/token', [
          'json' =&gt; [
            'client_id' =&gt; $this-&gt;client_id,
            'client_secret' =&gt; $this-&gt;client_secret,
            'redirect_uri' =&gt; $this-&gt;redirect_uri,
            'grant_type' =&gt; 'authorization_code',
            'code' =&gt; $request-&gt;input('code'),
            'scope' =&gt; $request-&gt;input('scope'),
            'context' =&gt; $request-&gt;input('context'),
          ]
        ]);
  
        $statusCode = $result-&gt;getStatusCode();
        $data = json_decode($result-&gt;getBody(), true);
  
        if ($statusCode == 200) {
          $request-&gt;session()-&gt;put('store_hash', $data['context']);
          $request-&gt;session()-&gt;put('access_token', $data['access_token']);
          $request-&gt;session()-&gt;put('user_id', $data['user']['id']);
          $request-&gt;session()-&gt;put('user_email', $data['user']['email']);
  
          // $configValue = Config::select('*')-&gt;where('storehash', $data['context'])-&gt;get()-&gt;toArray();
  
          // if (count($configValue) != 0) {
          //   $id = $configValue[0]['id'];
          //   $configObj = Config::find($id);
          //   $configObj-&gt;access_token = $data['access_token'];
          //   $configObj-&gt;save();
          // } else {
          //   $configObj = new Config;
          //   $configObj-&gt;email = $data['user']['email'];
          //   $configObj-&gt;storehash = $data['context'];
          //   $configObj-&gt;access_token = $data['access_token'];
          //   $configObj-&gt;save();
          // }
  
          // If the merchant installed the app via an external link, redirect back to the 
          // BC installation success page for this app
          if ($request-&gt;has('external_install')) {
            return redirect('https://login.bigcommerce.com/app/' . $this-&gt;getAppClientId() . '/install/succeeded');
          }
        }
  
        return redirect(\config('app.appUrl'));
      } catch (RequestException $e) {
        $statusCode = $e-&gt;getResponse()-&gt;getStatusCode();
        echo $statusCode;
        $errorMessage = &quot;An error occurred.&quot;;
  
        if ($e-&gt;hasResponse()) {
          if ($statusCode != 500) {
            echo &quot;some error other than 500&quot;;
            // $errorMessage = Psr7\str($e-&gt;getResponse());
          }
        }
  
        // If the merchant installed the app via an external link, redirect back to the 
        // BC installation failure page for this app
        if ($request-&gt;has('external_install')) {
          return redirect('https://login.bigcommerce.com/app/' . $this-&gt;getAppClientId() . '/install/failed');
        } else {
          echo &quot;fail&quot;;
          // return redirect()-&gt;action('MainController@error')-&gt;with('error_message', $errorMessage);
        }
      }
      // return view('index');
    }
  
    public function verifySignedRequest($signedRequest)
    {
      list($encodedData, $encodedSignature) = explode('.', $signedRequest, 2);
  
      // decode the data
      $signature = base64_decode($encodedSignature);
      $jsonStr = base64_decode($encodedData);
      echo $jsonStr;
      $data = json_decode($jsonStr, true);
  
      // confirm the signature
      $expectedSignature = hash_hmac('sha256', $jsonStr, $this-&gt;client_secret, $raw = false);
      if (!hash_equals($expectedSignature, $signature)) {
        error_log('Bad signed request from BigCommerce!');
        return null;
      }
      return $data;
    }
  
    public function makeBigCommerceAPIRequest(Request $request, $endpoint)
    {
      echo ' ...... trying to make an apiRequest now     : with storehash    : ' . $this-&gt;storehash . '    .............';
      echo '...........................................';
      echo 'other variables at the moment :::: ............... client ID :' . $this-&gt;getAppClientId() . '...................... token : ' . $this-&gt;getAccessToken($request) . '...............';
  
      $requestConfig = [
        'headers' =&gt; [
          'X-Auth-Client' =&gt; $this-&gt;getAppClientId(),
          'X-Auth-Token'  =&gt; $this-&gt;getAccessToken($request),
          'Content-Type'  =&gt; 'application/json',
        ]
      ];
  
      if ($request-&gt;method() === 'PUT') {
        $requestConfig['body'] = $request-&gt;getContent();
      }
  
  
  
      $client = new Client();
      $result = $client-&gt;request($request-&gt;method(), 'https://api.bigcommerce.com/' . $this-&gt;storehash . '/' . $endpoint, $requestConfig);
      return $result;
    }
  
    public function proxyBigCommerceAPIRequest(Request $request, $endpoint)
    {
      if (strrpos($endpoint, 'v2') !== false) {
        // For v2 endpoints, add a .json to the end of each endpoint, to normalize against the v3 API standards
        $endpoint .= '.json';
      }
  
      echo ' asadssada ...... trying to make an apiRequest now     : with storehash    : ' . $this-&gt;storehash . '    .............' . $request-&gt;session()-&gt;get('store_hash') . '    ............        ';
  
      $result = $this-&gt;makeBigCommerceAPIRequest($request, $endpoint);
  
      return response($result-&gt;getBody(), $result-&gt;getStatusCode())-&gt;header('Content-Type', 'application/json');
    }
  }
  
  </code></pre>