pawanmore/stytch-php-sdk
Composer 安装命令:
composer require pawanmore/stytch-php-sdk
包简介
UnOfficial PHP SDK for Stytch Authentication APIs
关键字:
README 文档
README
Stytch PHP SDK
PHP SDK for Stytch Authentication APIs. This SDK provides easy-to-use methods for integrating Stytch's authentication services into your PHP applications.
Features
- B2B API Support: Complete coverage of Stytch's B2B authentication APIs
- Consumer API Support: Full support for consumer authentication endpoints
- Modern PHP: Built for PHP 7.4+ with modern features
- Type Safety: Full type hints and documentation
- Error Handling: Comprehensive error handling and exceptions
- PSR Standards: Follows PSR-4 autoloading and PSR-7 HTTP standards
Installation
Via Composer
composer require pawanmore/stytch-php-sdk
Manual Installation
- Clone this repository
- Run
composer install - Include the autoloader in your project
Quick Start
Initialize the SDK
<?php use Stytch\StytchClient; // Initialize with your project credentials $stytch = new StytchClient([ 'project_id' => 'your-project-id', 'secret' => 'your-secret-key', 'env' => 'test' // or 'live' ]);
B2B API Examples
// Create an organization $response = $stytch->b2b->organizations->create([ 'organization_name' => 'My Company', 'organization_slug' => 'my-company' ]); // Create a member $response = $stytch->b2b->members->create([ 'organization_id' => 'org_123', 'email_address' => 'user@company.com' ]); // Send magic link $response = $stytch->b2b->magicLinks->send([ 'organization_id' => 'org_123', 'email_address' => 'user@company.com' ]);
Consumer API Examples
// Create a user $response = $stytch->consumer->users->create([ 'email' => 'user@example.com' ]); // Send magic link $response = $stytch->consumer->magicLinks->send([ 'email' => 'user@example.com' ]); // Authenticate magic link $response = $stytch->consumer->magicLinks->authenticate([ 'token' => 'magic_link_token' ]);
API Coverage
B2B API
- Organizations: Create, get, update, search, delete
- Members: Create, get, update, search, delete, reactivate
- RBAC: Get RBAC policies
- Magic Links: Send, authenticate, discovery
- OAuth: Google, Microsoft authentication
- Session Management: Get, authenticate, exchange, revoke
- SSO: SAML, OIDC connections
- Discovery: List organizations, create via discovery
- Passwords: Authenticate, reset, strength check, migrate
- MFA: TOTP, OTP, recovery codes
- M2M: Client management, access tokens
- Email OTP: Send, authenticate
- Impersonation: Authenticate tokens
Consumer API
- Users: Create, get, update, search, delete
- Magic Links: Send, authenticate, embeddable
- OTP: SMS, WhatsApp, email
- OAuth: Multiple providers (Google, Apple, GitHub, etc.)
- Session Management: Get, authenticate, revoke
- TOTP: Create, authenticate, recovery codes
- Crypto Wallets: Authenticate
- Passkeys & WebAuthn: Register, authenticate
- Passwords: Authenticate, reset, strength check
Error Handling
The SDK throws specific exceptions for different error types:
try { $response = $stytch->consumer->users->create(['email' => 'invalid-email']); } catch (Stytch\Exceptions\StytchException $e) { echo "Stytch Error: " . $e->getMessage(); } catch (Stytch\Exceptions\StytchError $e) { echo "API Error: " . $e->getMessage(); echo "Error Code: " . $e->getErrorCode(); }
Configuration
Environment Variables
You can also configure the SDK using environment variables:
STYTCH_PROJECT_ID=your-project-id STYTCH_SECRET=your-secret-key STYTCH_ENV=test
Advanced Configuration
$stytch = new StytchClient([ 'project_id' => 'your-project-id', 'secret' => 'your-secret-key', 'env' => 'test', 'timeout' => 30, 'user_agent' => 'MyApp/1.0', 'http_client' => new CustomHttpClient() ]);
Testing
Run the test suite:
composer test
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
License
MIT License - see LICENSE file for details.
Support
- Documentation: https://stytch.com/docs
- API Reference: https://stytch.com/docs/api
- Support: support@stytch.com
pawanmore/stytch-php-sdk 适用场景与选型建议
pawanmore/stytch-php-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 07 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「api」 「Authentication」 「oauth」 「SSO」 「unofficial」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pawanmore/stytch-php-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pawanmore/stytch-php-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pawanmore/stytch-php-sdk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Automatically logs-in users if they are already authenticated by a remote source. (e.g. environment variable REMOTE_USER)
GraphQL authentication for your headless Craft CMS applications.
Laravel middleware to restrict a site or specific routes using HTTP basic authentication
A PSR-7 compatible library for making CRUD API endpoints
Email Toolkit Plugin for CakePHP
A list of dangerous usernames
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 27
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-08