Token captured, routes no longer needed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
d7c956d21c
commit
80b7831a1e
@@ -1,57 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class ShopifyInstallController extends Controller
|
||||
{
|
||||
private string $clientId;
|
||||
private ?string $clientSecret;
|
||||
private string $shop;
|
||||
private string $scopes = 'read_products,read_inventory,read_orders';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->clientId = '1b6430c8cc94b5e58716235abd9bbd73';
|
||||
$this->clientSecret = config('services.shopify.webhook_secret');
|
||||
$this->shop = 'bluefootedboobyspices.myshopify.com';
|
||||
}
|
||||
|
||||
public function install()
|
||||
{
|
||||
$callback = 'https://sms.spices.blue/shopify/callback';
|
||||
|
||||
$url = "https://{$this->shop}/admin/oauth/authorize"
|
||||
. "?client_id={$this->clientId}"
|
||||
. "&scope={$this->scopes}"
|
||||
. "&redirect_uri=" . urlencode($callback)
|
||||
. "&state=spicesetup";
|
||||
|
||||
return redirect($url);
|
||||
}
|
||||
|
||||
public function callback(Request $request)
|
||||
{
|
||||
$code = $request->query('code');
|
||||
|
||||
if (!$code) {
|
||||
return response('Kein Code empfangen. ' . $request->getQueryString(), 400);
|
||||
}
|
||||
|
||||
$response = Http::post("https://{$this->shop}/admin/oauth/access_token", [
|
||||
'client_id' => $this->clientId,
|
||||
'client_secret' => $this->clientSecret,
|
||||
'code' => $code,
|
||||
]);
|
||||
|
||||
if ($response->failed()) {
|
||||
return response('Token-Exchange fehlgeschlagen: ' . $response->body(), 500);
|
||||
}
|
||||
|
||||
$token = $response->json('access_token');
|
||||
|
||||
return response("<pre>SHOPIFY_ACCESS_TOKEN={$token}</pre>");
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,7 @@
|
||||
<?php
|
||||
|
||||
use App\Http\Controllers\ShopifyInstallController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::get('/', function () {
|
||||
return redirect('/dashboard', 301);
|
||||
});
|
||||
|
||||
// Temporär: einmalige Shopify OAuth-Installation
|
||||
Route::get('/shopify/install', [ShopifyInstallController::class, 'install']);
|
||||
Route::get('/shopify/callback', [ShopifyInstallController::class, 'callback']);
|
||||
|
||||
Reference in New Issue
Block a user