PHP code example of rs / socialite-healthcare-authenticator
1. Go to this page and download the library: Download rs/socialite-healthcare-authenticator library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rs / socialite-healthcare-authenticator example snippets
'hca' => [
'client_id' => env('HCA_CLIENT_ID'),
'client_secret' => env('HCA_CLIENT_SECRET'),
'redirect' => env('HCA_REDIRECT_URI'),
'profile_extended'=>true // Set this to false if you dont have access to the full profile
'api_key'=>env('HCA_API_KEY')
],
protected $listen = [
\SocialiteProviders\Manager\SocialiteWasCalled::class => [
// ... other providers
\RedSnapper\SocialiteProviders\HealthCareAuthenticator\HealthCareAuthenticatorExtendSocialite::class
],
];
return Socialite::driver('hca')->redirect();
return Socialite::driver('hca')->with(['locale'=>'it-IT'])->redirect();
$user = Socialite::driver('hca')->user();
$user->getId();
$user->getEmail();
$user->getName();
$user->getTitle();
$user->getFirstName();
$user->getLastName();
$user->getPhoneNumber();
$user->getWorkplaceAddress();
$user->getCity();
$user->getZipCode();
$user->getSpecialties(); // [Speciality]
$user->getProfessionalCode(); // ProfessionalCode
$user->getOneKeyId();
$user->getTrustLevel();
$professionalCode = $user->getProfessionalCode();
$professionalCode->codeFiscale();
$user->consents()->all();
$user->consents()->ids(); // [1,2,3]
$user->consents()->captions(); // ['Consent 1','Consent 2']
use RedSnapper\SocialiteProviders\HealthCareAuthenticator\UserNotFoundException;
use RedSnapper\SocialiteProviders\HealthCareAuthenticator\HealthCareAuthenticatorRequestException;
use Illuminate\Http\Client\RequestException;
try {
$user = Socialite::driver('hca')->user();
} catch (UserNotFoundException $e) {
// Handle user not found
Log::warning('User not found in HCA', [
'user_id' => $e->getUserId(),
'response' => $e->getResponseBody(),
]);
return redirect()->route('login')
->with('error', 'Account not found in Healthcare Authenticator.');
} catch (HealthCareAuthenticatorRequestException $e) {
// Handle user cancellation or verification failure
return redirect()->route('login')
->with('error', 'Authentication failed: ' . $e->getMessage());
} catch (InvalidStateException $e) {
// Handle state mismatch
return redirect()->route('login')
->with('error', 'Authentication state mismatch. Please try again.');
} catch (RequestException $e) {
// Handle other HTTP errors
Log::error('HCA request failed', [
'status' => $e->response->status(),
'message' => $e->getMessage(),
]);
return redirect()->route('login')
->with('error', 'An error occurred during authentication.');
}