Skip to content

Deprecated: OAuth2 Only Authentication

dgmyrek edited this page Mar 21, 2018 · 1 revision

This authentication method is now deprecated. Please see the OpenID Connect Authentication or Access Token Authentication wiki pages.

One of the options to authenticate with is using 'OAuth2' alone method. This page goes over the OAuth2 Authentication:

Example

 // Sets the OAuth2 only Authentication
 $api = new SparkAPI_OAuth($client_id, $client_secret, $application_uri);
 
 // This is similar to our OpenId and OAuth2 Hybrid authentication call.  The interface for each client is identical.
 // To build the URI to redirect the end user to, invoke the "authentication_endpoint_uri" method, e.g.:
 header("Location: " . $api->authentication_endpoint_uri());
 
 // After this "code" is retrieved and you are redirected back, you will need to issue a Grant request with the "code" value brought back.  Once the Grant is returned, you'll want to test that it was successful and set your Access Token and Refresh Token
 $grant = $api->Grant($result, "authorization_code");

 if ($grant == true) {
    // These values can be saved and reused in future request then.
    $accesst = $api->SetAccessToken($api->oauth_access_token);
    $refresht = $api->SetRefreshToken($api->oauth_refresh_token); 
 } else {
      print_r("Something went wrong.");
      echo "API Error Code: {$api->last_error_code}<br>\n";
      echo "API Error Message: {$api->last_error_mess}<br>\n";
 };

 // After this is settled, you should be able to make pulls from the system, for example:

 $resultGetListings = $api->GetListings();
 if ($resultGetListings === false) {
      echo "API Error Code: {$api->last_error_code}<br>\n";
      echo "API Error Message: {$api->last_error_mess}<br>\n";
      exit;
 } else {
      print_r($resultGetListings);
 } 	

Spark Platform Documentation

OAuth 2 Only Protocol

Clone this wiki locally