*** See very end for working code but its not ideal as I have to maybe two request to oauth redirect url.
I'm implementing OAUTH2 for my rest service.
I'm doing
$resp = Http::get("https://sandbox.dev.clover.com/oauth/token",[ 'client_id'=>$client_id, 'client_secret'=> $secret, 'code' => $access_code ]);
I'm getting the access code back.
But how the hell do I request a refresh token if the end point is requesting a refresh token that is never sent to me. This seems to be the old way.
I found these new end points but they just give me error messages.
$resp = Http::post("https://apisandbox.dev.clover.com/oauth/v2/token",[ 'client_id'=>$client_id, 'client_secret'=> $secret, 'code' => $access_code ]);
This does not work. And yes all the values are valid.
"{"status":"Unauthorized","message":"Failed to validate authentication code."}"
What is going on?
Also if you set the REST api to give you a token the query string is broken.
http://myapp.test/clover_auth?merchant_id=MIDID&employee_id=AFSD5&client_id=64QJG****#access_token=d8b7e9dc-0d7d-b163-583e-631597747a3a
#access_token should be &access_token
This is driving me insane.
I also tried.
starting the auth flow from my site like so.
return redirect('https://sandbox.dev.clover.com/oauth/v2/authorize?code_challenge='.$code_challenge.'&client_id='.env('CLOVER_APP_ID2').'&redirect_url=https://appdomain.test/clover_auth');
I get sent to a random page this this error:
"There was an issue in getting a response from the Auth Token service."
User is never set back to my auth url set in the REST settings.
I'm at my wits end with this documentation.
Should have some code demos for the OAuth flow for 2.0 from for all examples. Nothing seems to work. It's probably something silly im missing but these docs are not the best.
Please help.
Update: I was able to get the access token and refresh token only when I start the OAuth flow from my site. with this call
https://sandbox.dev.clover.com/oauth/v2/authorize?client_id='.env('CLOVER_APP_ID').'&client_secret='.env('CLOVER_APP_SECRET').'&redirect_url=https://cloverscope.test/clover_auth'
When the OAuth starts from Clover I always get the error.
Why does starting OAuth from clover not work?
This is my working code because if the user initiates the OAuth flow from the link in clover dashboard the initial code sent in the query Fails to Validate. So I send and authorize request with and the code that comes back from that works to request a token... Why I have no idea.
public function register(Request $request){ $MID = $request->get('merchant_id'); $client_id = $request->get('client_id'); $employee_id = $request->get('employee_id',null); $access_code = $request->get('code',null); $secret = env('CLOVER_APP_SECRET'); $resp = Http::post("https://apisandbox.dev.clover.com/oauth/v2/token",[ 'client_id'=>env('CLOVER_APP_ID'), 'client_secret'=> $secret, 'merchant_id' => $MID, 'code' => $access_code ]); if($resp->json('message') == "Failed to validate authentication code."){ return redirect('https://sandbox.dev.clover.com/oauth/v2/authorize?client_id='.env('CLOVER_APP_ID').'&client_secret='.env('CLOVER_APP_SECRET').'&redirect_url=https://myapp.test/clover_auth'); } dd($resp->body()); }