How to use the bigcommerce.connection.OAuthConnection function in bigcommerce

To help you get started, we’ve selected a few bigcommerce examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bigcommerce / bigcommerce-api-python / tests / test_connection.py View on Github external
def test_full_path(self):
        connection = OAuthConnection(client_id='123', store_hash='abcdef')
        self.assertEqual(connection.full_path('time'), 'https://api.bigcommerce.com/stores/abcdef/v2/time')
github bigcommerce / bigcommerce-api-python / tests / test_connection.py View on Github external
def test_alternate_api_endpoint(self):
        connection = OAuthConnection(client_id='123', store_hash='abcdef', host='barbaz.com')
        self.assertEqual(connection.full_path('time'), 'https://barbaz.com/stores/abcdef/v2/time')
github bigcommerce / bigcommerce-api-python / tests / test_connection.py View on Github external
def test_fetch_token(self):
        client_id = 'abc123'
        client_secret = '123abc'
        code = 'hellosecret'
        context = 'stores/abc'
        scope = 'store_v2_products'
        redirect_uri = 'http://localhost/callback'
        result = {'access_token': '12345abcdef'}

        connection = OAuthConnection(client_id, store_hash='abc')
        connection.post = MagicMock()
        connection.post.return_value = result

        res = connection.fetch_token(client_secret, code, context, scope, redirect_uri)
        self.assertEqual(res, result)
        self.assertDictEqual(connection._session.headers,
                             {'X-Auth-Client': 'abc123', 'X-Auth-Token': '12345abcdef',
                              'Accept': 'application/json', 'Accept-Encoding': 'gzip'})
        connection.post.assert_called_once_with('https://login.bigcommerce.com/oauth2/token',
                                                {
                                                    'client_id': client_id,
                                                    'client_secret': client_secret,
                                                    'code': code,
                                                    'context': context,
                                                    'scope': scope,
                                                    'grant_type': 'authorization_code',
github bigcommerce / bigcommerce-api-python / tests / test_api.py View on Github external
def test_create_basic(self):
        api = bigcommerce.api.BigcommerceApi(host='store.mybigcommerce.com', basic_auth=('admin', 'abcdef'))
        self.assertIsInstance(api.connection, Connection)
        self.assertNotIsInstance(api.connection, OAuthConnection)
github bigcommerce / bigcommerce-api-python / tests / test_api.py View on Github external
def test_create_oauth(self):
        api = bigcommerce.api.BigcommerceApi(client_id='123456', store_hash='abcdef', access_token='123abc')
        self.assertIsInstance(api.connection, OAuthConnection)
github bigcommerce / bigcommerce-api-python / bigcommerce / api.py View on Github external
def __init__(self, host=None, basic_auth=None,
                 client_id=None, store_hash=None, access_token=None, rate_limiting_management=None):
        self.api_service = os.getenv('BC_API_ENDPOINT', 'api.bigcommerce.com')
        self.auth_service = os.getenv('BC_AUTH_SERVICE', 'login.bigcommerce.com')

        if host and basic_auth:
            self.connection = connection.Connection(host, basic_auth)
        elif client_id and store_hash:
            self.connection = connection.OAuthConnection(client_id, store_hash, access_token, self.api_service,
                                                         rate_limiting_management=rate_limiting_management)
        else:
            raise Exception("Must provide either (client_id and store_hash) or (host and basic_auth)")