-
Notifications
You must be signed in to change notification settings - Fork 28
Deprecated: Hybrid 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.
With the newest release of the API, you can now authenticate using 'OpenId' and 'OAuth2' method (opposed to just the 'OAuth2' alone method). This page goes over the new Hybrid Authentication:
// Sets the OpenId/OAuth2 Hybrid Authentication
$api = new SparkAPI_Hybrid($client_id, $client_secret, $application_callback_uri);
// This is similar to our OAuth2 only 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);
}