承接 rs/socialite-healthcare-authenticator 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rs/socialite-healthcare-authenticator

Composer 安装命令:

composer require rs/socialite-healthcare-authenticator

包简介

Socialite Healthcare Authenticator

README 文档

README

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 GitHub Tests Action Status Total Downloads

Installation

You can install the package via composer:

composer require rs/socialite-healthcare-authenticator

Installation & Basic Usage

Please see the Base Installation Guide, then follow the provider specific instructions below.

Add configuration to config/services.php

'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

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 for detailed instructions.

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

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

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

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

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:

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 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

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

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

Credits

License

The MIT License (MIT). Please see License File for more information.

rs/socialite-healthcare-authenticator 适用场景与选型建议

rs/socialite-healthcare-authenticator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 828 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 03 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「rs」 「healthcare-authenticator」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 rs/socialite-healthcare-authenticator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 rs/socialite-healthcare-authenticator 我们能提供哪些服务?
定制开发 / 二次开发

基于 rs/socialite-healthcare-authenticator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 828
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 14
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 4
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-18