CodeIgniter -> Shopify API. How to log in via OAuth via the CLI? Using shopify-api-php
CodeIgniter -> Shopify API. How to log in via OAuth via the CLI? Using shopify-api-php
I have been racking my brain for ages here - if somebody could enlighten me I would be extremely grateful.
I'm trying to perform a standard OAUTH login, exactly as per the docs here:
https://github.com/Shopify/shopify-api-php
I have the api key, api secret key, host name etc. I am invoking the action using the command line - there is no web interface. I am running the application locally and using Session storage as there are no web cookies as I am not using a web browser.
Where I'm tripping up is on the 'callback' function - this doesn't seem to do anything. I am calling Context::initialize and OAuth::begin(... without issue but that is where things trip up.
I have a corresponding route set up '/auth/callback' which I believe should be invoked once the server returns a response to the initial login request which then provides the code, hmac values etc. needed to validate the session, but nothing happens.
I need to call OAuth::callback(... from within this callback function.
Context::initialize(
apiKey: config('ShopifyConfig')->api_key,
apiSecretKey: config('ShopifyConfig')->api_secret_key,
scopes: config('ShopifyConfig')->api_scopes,
hostName: config('ShopifyConfig')->host_name,
sessionStorage: new FileSessionStorage(),
apiVersion: config('ShopifyConfig')->api_version,
);
$redirectUrl = OAuth::begin(
shop: config('ShopifyConfig')->host_name,
redirectPath: '/auth/callback', // doesn't do anything!
isOnline: false,
setCookieFunction: function (OAuthCookie $cookie) {
$_SESSION['cookie'][] = [
'name' => $cookie->getName(),
'value' => $cookie->getValue(),
'expire' => $cookie->getExpire(),
'secure' => $cookie->isSecure(),
'httpOnly' => $cookie->isHttpOnly(),
];
return true;
}
);
public function logIn(Request $request)
{
OAuth::callback(...)
// Routes file
$routes->get('/auth/callback', 'Home::logIn');
$routes->post('/auth/callback', 'Home::logIn');
$routes->cli('/auth/callback', 'Home::logIn');
Turbo Multi-language Translator
Make the better internet purchasing globaly
Turbosify SEO Speed Booster
5.0 (7)•Free plan available
Get better conversions by improving store loading speed
Installed
Turbo Multi-language Chat - AI Customer service in one hand