Requesting access token

Once a client has been created, you are able to use your client ID and secret to request an authorisation code and access token. First, you should make a redirect request to /oauth/authorize route like so:

$query = http_build_query([
        'client_id' => 'client-id',
        'redirect_uri' => 'http://yourapp.com/callback',
        'response_type' => 'code',
        'scope' => 'requested_scopes_here',
        'state' => 'generated_state_value'
    ]);
 
return redirect('https://app.launchcart.com/oauth/authorize?'.$query);

When user approves authorisation request we will make redirect to specified redirect_uri with code and state params in query string.

Using provided code you can request for a token

$response = Http::asForm()->post('https://app.launchcart.com/oauth/token', [
        'grant_type' => 'authorization_code',
        'client_id' => 'client-id',
        'client_secret' => 'client-secret',
        'redirect_uri' => 'http://yourapp.com/callback',
        'code' => $request->code,
    ]);

return $response->json();

This /oauth/token route will return a JSON response containing access_token, refresh_token, and expires_in attributes. The expires_in attribute contains the number of seconds until the access token expires.