PHPackages                             rs/socialite-healthcare-authenticator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. rs/socialite-healthcare-authenticator

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

rs/socialite-healthcare-authenticator
=====================================

Socialite Healthcare Authenticator

v0.7.1(3mo ago)0535MITPHPPHP ^8.3CI passing

Since Mar 18Pushed 3mo ago4 watchersCompare

[ Source](https://github.com/RedSnapper/socialite-healthcare-authenticator)[ Packagist](https://packagist.org/packages/rs/socialite-healthcare-authenticator)[ Docs](https://github.com/rs/socialite-healthcare-authenticator)[ RSS](/packages/rs-socialite-healthcare-authenticator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (8)Versions (15)Used By (0)

Healthcare Authenticator
========================

[](#healthcare-authenticator)

Allows for web portals for HCPs to seamlessly implement and maintain sign-on, authentication, and/or verification through integration with one of the world’s largest and most accurate sources of HCP data.

[![Latest Version on Packagist](https://camo.githubusercontent.com/0747f86a44efd1bcef24f22119e3c6e28800abf3ddcc3b29a1d497bc589a4fbc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72732f736f6369616c6974652d6865616c7468636172652d61757468656e74696361746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rs/socialite-healthcare-authenticator)[![GitHub Tests Action Status](https://camo.githubusercontent.com/9dfec257cb437481f1ced5686dd97a8d93491f134603f778a355b8fb8a9573cc/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f726564736e61707065722f736f6369616c6974652d6865616c7468636172652d61757468656e74696361746f722f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/redsnapper/socialite-healthcare-authenticator/actions?query=workflow%3Atests+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/16f214a08b579dce5f41c303e66a61247b55ede95857ca940236c9a7585ae7d2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f72732f736f6369616c6974652d6865616c7468636172652d61757468656e74696361746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rs/socialite-healthcare-authenticator)

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require rs/socialite-healthcare-authenticator
```

Installation &amp; Basic Usage
------------------------------

[](#installation--basic-usage)

Please see the [Base Installation Guide](https://socialiteproviders.com/usage/), then follow the provider specific instructions below.

### Add configuration to `config/services.php`

[](#add-configuration-to-configservicesphp)

```
'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')
],
```

Add the API key for user consents and magic links.

### Add provider event listener

[](#add-provider-event-listener)

Configure the package's listener to listen for `SocialiteWasCalled` events.

Add the event to your `listen[]` array in `app/Providers/EventServiceProvider`. See the [Base Installation Guide](https://socialiteproviders.com/usage/) for detailed instructions.

```
protected $listen = [
    \SocialiteProviders\Manager\SocialiteWasCalled::class => [
        // ... other providers
        \RedSnapper\SocialiteProviders\HealthCareAuthenticator\HealthCareAuthenticatorExtendSocialite::class
    ],
];
```

### Usage

[](#usage)

You should now be able to use the provider like you would regularly use Socialite (assuming you have the facade installed):

```
return Socialite::driver('hca')->redirect();
```

Can provide the locale using the with method.

```
return Socialite::driver('hca')->with(['locale'=>'it-IT'])->redirect();
```

Available methods for the returned user.

```
$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();
```

### Professional Code

[](#professional-code)

You can also retrieve the user's professional code using the `getProfessionalCode` method. This returns back a ProfessionalCode object. The professional code has a method for each professional code type.

```
$professionalCode = $user->getProfessionalCode();
$professionalCode->codeFiscale();
```

The code is sourced from Onekey data. If unavailable, it defaults to the code provided during the signup process.

### Consents

[](#consents)

You can also retrieve the user's consents using the `consents` method.

```
$user->consents()->all();
```

This returns back a Laravel collection.

```
$user->consents()->ids(); // [1,2,3]
$user->consents()->captions(); // ['Consent 1','Consent 2']
```

### Handling errors

[](#handling-errors)

When calling the `user` method, the following exceptions may be thrown:

`\RedSnapper\SocialiteProviders\HealthCareAuthenticator\UserNotFoundException`

This exception is thrown when a user is not found in the Healthcare Authenticator system (404 response). It provides access to the user ID and response body.

`\RedSnapper\SocialiteProviders\HealthCareAuthenticator\HealthCareAuthenticatorRequestException`

This exception is thrown if the user cancels the sign-up process or fails to verify as an HCP.

`\Laravel\Socialite\Two\InvalidStateException`

This exception is thrown if the state returned by the HCA service does not match the state stored in the session.

`\Illuminate\Http\Client\RequestException`

This exception is thrown for other HTTP errors (500, 503, etc.).

#### Example exception handling:

[](#example-exception-handling)

```
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.');
}
```

### Magic Links

[](#magic-links)

Magic links are secure, one-time use URLs that allow Healthcare Professionals (HCPs) to quickly sign in or verify their identity without entering credentials. This package now supports generating magic links for HCPs using the Healthcare Authenticator (HCA) API.

To create magic links, use the `MagicLink` class by providing your `client_id`, `api_key`, and `redirect` URI. You then call the `createLinks` method with an array of recipients.

Each recipient must include the following fields:

- `onekey_id` (string): The OneKey identifier of the HCP.
- `email` (string): The email address of the HCP.
- `locale` (string): The locale/language code (e.g., 'en-US', 'it-IT').

You can also specify the expiry time for the links in minutes.

The `createLinks` method returns a `MagicLinkResult` object containing collections of successful and failed links.

Example usage:

```
use RedSnapper\SocialiteProviders\HealthCareAuthenticator\MagicLink;

$magicLink = new MagicLink(
    clientId: config('services.hca.client_id'),
    apiKey: config('services.hca.api_key'),
    redirect: config('services.hca.redirect'),
);

$recipients = [
    ['onekey_id' => '123456', 'email' => 'hcp1@example.com', 'locale' => 'en-US'],
    ['onekey_id' => '789012', 'email' => 'hcp2@example.com', 'locale' => 'it-IT'],
];

$result = $magicLink->createLinks($recipients, expiryMinutes: 60);
```

You can iterate over successful and failed links as follows:

```
foreach ($result->successful() as $link) {
    // $link is a GeneratedMagicLink DTO
    echo "Magic link for {$link->accountEmail}: {$link->url}\n";
}

foreach ($result->failed() as $failed) {
    // $failed is a FailedMagicLink DTO
    echo "Failed to create link for {$failed->requestEmail}: {$failed->error}\n";
}
```

Both successful and failed links are returned as lightweight Data Transfer Objects (DTOs):

- `GeneratedMagicLink` for successful links.
- `FailedMagicLink` for failed link creation attempts.

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Param Dhaliwal](https://github.com/rs)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance82

Actively maintained with recent releases

Popularity16

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 90.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~30 days

Recently: every ~6 days

Total

12

Last Release

91d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6851104?v=4)[rstechnical](/maintainers/rstechnical)[@rstechnical](https://github.com/rstechnical)

---

Top Contributors

[![paramdhal](https://avatars.githubusercontent.com/u/1278858?v=4)](https://github.com/paramdhal "paramdhal (29 commits)")[![joeuk89](https://avatars.githubusercontent.com/u/6736852?v=4)](https://github.com/joeuk89 "joeuk89 (3 commits)")

---

Tags

rshealthcare-authenticator

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/rs-socialite-healthcare-authenticator/health.svg)

```
[![Health](https://phpackages.com/badges/rs-socialite-healthcare-authenticator/health.svg)](https://phpackages.com/packages/rs-socialite-healthcare-authenticator)
```

###  Alternatives

[socialiteproviders/microsoft

Microsoft OAuth2 Provider for Laravel Socialite

326.1M13](/packages/socialiteproviders-microsoft)[socialiteproviders/apple

Apple OAuth2 Provider for Laravel Socialite

618.4M8](/packages/socialiteproviders-apple)[socialiteproviders/instagram

Instagram OAuth2 Provider for Laravel Socialite

421.9M5](/packages/socialiteproviders-instagram)[socialiteproviders/microsoft-azure

Microsoft Azure OAuth2 Provider for Laravel Socialite

556.0M19](/packages/socialiteproviders-microsoft-azure)[socialiteproviders/laravelpassport

LaravelPassport OAuth2 Provider for Laravel Socialite

621.3M7](/packages/socialiteproviders-laravelpassport)[socialiteproviders/discord

Discord OAuth2 Provider for Laravel Socialite

422.0M17](/packages/socialiteproviders-discord)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
