BigAommerce OAuth API for server script

The latest specification recommends using OAuth to connect to the BigCommerce API, as the simple auth method will be deprecated soon.

I use the BigCommerce API in some PHP scripts that access the Store API for my store. These scripts do relatively simple things, such as product update names, product price updates, etc.

I am confused about how to port these scripts to using the new OAuth system. All I read is that OAuth is based on developing the actual application that the user installs and authorizes to access their store. However, this is clearly not my precedent, and I was very embarrassed.

A simple example would be a script to retrieve products from my store. I just run this code in a PHP file:

Bigcommerce::configure(array(
    'store_url' => 'https://www.my-store.com',
    'username' => 'my_username',
    'api_key' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'
));
Bigcommerce::setCipher('RC4-SHA');
Bigcommerce::verifyPeer(false);

Bigcommmerce::getProducts();

How can I achieve the same using OAuth? Is it possible?

+4
source share
3 answers

I would probably create a quick β€œapplication” to get the client id, client secret and token. Then use these credentials for external authentication. Therefore, you must install an "authentication application", but execute your code outside of BC.

Please note that this is not so different from how the installed iframed application works.

PS, I actually have not tried this, but theoretically it should work.

+2
source

, , , PHP, #, , , , - :

oauth, , , , SSL . URL- , . , , "" , URL-, BC . https://login.bigcommerce.com/oauth2/token . , API, , "" 60-90 , .

+1

@developerscott , , , , oAuth SDK API PHP BC

oAuth client_id , oAuth PHP-. Bigcommerce::configure(), , username api_key:

Bigcommerce::configure(array(
    'store_hash' => 'abcdef',
    'client_id' => '123xxxx321',
    'auth_token' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'
));
Bigcommerce::setCipher('RC4-SHA');
Bigcommerce::verifyPeer(false);

Bigcommmerce::getProducts();
0

Source: https://habr.com/ru/post/1544253/


All Articles