首页 > 解决方案 > 无法让 oAuth 与 Laravel 和 BigCommerce 应用程序一起使用

问题描述

我在使用BC PHP API库在 Bigcommerce 上设置“一键式应用程序”oAuth 时遇到问题。

目前的问题是获取实际的身份验证令牌。我尝试了各种方法,并相信这取决于(代码/上下文/范围)获取请求。null他们每次都回来。

我都试过了:

$request->query('code');
$request->get('code');

在 BC 应用程序启动屏幕上,我看到:

Trying to get property 'access_token' of non-object 

这当然是因为令牌返回 null。

这是我在 Laravel 中的控制器

namespace App\Http\Controllers;

use \Illuminate\Http\Request;
use Bigcommerce\Api\Client as Bigcommerce;

class BController extends Controller
{
    //
    public function index(Request $request)
    {
      $object = new \stdClass();
      $object->client_id = 'xxxxxxxxxxxxxx';
      $object->client_secret = 'xxxxxxxxxxxxxxxx';
      $object->redirect_uri = 'https://linkto/process_oauth_result';
      $object->code = $request->query('code');
      $object->context = $request->query('context');
      $object->scope = $request->query('scope');
      Bigcommerce::useJson();

      $authTokenResponse = Bigcommerce::getAuthToken($object);

      // configure BC App
      Bigcommerce::configure([
     'client_id' => env('xxxxxxxxxxxxxx'),
     'auth_token' => $authTokenResponse->access_token,
     'store_hash' => 'xxxxxxx'
   ]);

        Bigcommerce::verifyPeer(false);

        return 'Success!';
    }
}

标签: phplaraveloauthbigcommerce

解决方案


事实证明,这很好用。我正在使用 Runcloud 来管理应用程序,并且该click-jacking选项阻止了应用程序屏幕上的 iframe!


推荐阅读