This directory contains examples demonstrating how to use the Kinde PHP SDK with different frameworks and scenarios.
-
Install Dependencies
composer install
-
Set Environment Variables Create a
.envfile in the root directory or set environment variables:export KINDE_DOMAIN="https://your-domain.kinde.com" export KINDE_CLIENT_ID="your_client_id" export KINDE_CLIENT_SECRET="your_client_secret" export KINDE_REDIRECT_URI="http://localhost:8000/auth/callback" export KINDE_GRANT_TYPE="authorization_code" export KINDE_LOGOUT_REDIRECT_URI="http://localhost:8000" export KINDE_SCOPES="openid profile email offline" export KINDE_PROTOCOL="https"
File: management_client_example.php
Description: Demonstrates server-to-server operations using the KindeManagementClient.
Run it:
cd kinde-php-sdk
php playground/management_client_example.phpWhat it does:
- Creates a management client
- Lists users, organizations, applications, feature flags, roles, and permissions
- Shows error handling for API calls
Each framework example includes a complete controller/application that demonstrates:
- OAuth client initialization
- Login/logout flows
- User authentication
- Portal redirection
- Error handling
File: laravel/ExampleController.php
Description: Complete Laravel controller with all authentication endpoints.
To use in Laravel:
- Copy the controller to your Laravel app's
app/Http/Controllers/directory - Add routes to
routes/web.php:Route::get('/auth/login', [KindeAuthController::class, 'login']); Route::get('/auth/callback', [KindeAuthController::class, 'callback']); Route::get('/auth/logout', [KindeAuthController::class, 'logout']); Route::get('/auth/register', [KindeAuthController::class, 'register']); Route::get('/auth/create-org', [KindeAuthController::class, 'createOrg']); Route::get('/user/info', [KindeAuthController::class, 'userInfo']); Route::get('/portal', [KindeAuthController::class, 'portal']);
File: symfony/ExampleController.php
Description: Complete Symfony controller with authentication endpoints.
To use in Symfony:
- Copy the controller to your Symfony app's
src/Controller/directory - Add routes to
config/routes.yamlor use annotations - Install the Kinde SDK:
composer require kinde/kinde-php-sdk
File: codeigniter/ExampleController.php
Description: Complete CodeIgniter controller with authentication endpoints.
To use in CodeIgniter:
- Copy the controller to your CodeIgniter app's
app/Controllers/directory - Add routes to
app/Config/Routes.php - Install the Kinde SDK:
composer require kinde/kinde-php-sdk
# Set environment variables
export KINDE_DOMAIN="https://your-domain.kinde.com"
export KINDE_CLIENT_ID="your_client_id"
export KINDE_CLIENT_SECRET="your_client_secret"
# Run the example
php examples/management_client_example.phpEach framework example can be integrated into its respective framework application. The examples show:
- OAuth Client Setup: How to initialize the KindeClientSDK
- Authentication Flows: Login, logout, registration, and organization creation
- User Management: Getting user information and handling authentication states
- Portal Integration: Redirecting users to Kinde's user portal
- Error Handling: Proper exception handling for OAuth and API errors
All examples use these environment variables:
| Variable | Description | Required |
|---|---|---|
KINDE_DOMAIN |
Your Kinde domain | Yes |
KINDE_CLIENT_ID |
Your application client ID | Yes |
KINDE_CLIENT_SECRET |
Your application client secret | Yes |
KINDE_REDIRECT_URI |
OAuth redirect URI | Yes |
KINDE_GRANT_TYPE |
OAuth grant type (default: authorization_code) | No |
KINDE_LOGOUT_REDIRECT_URI |
Logout redirect URI | No |
KINDE_SCOPES |
OAuth scopes (default: openid profile email offline) | No |
KINDE_PROTOCOL |
Protocol for API calls (default: https) | No |
You can test the examples by:
- Management Client: Run directly with proper environment variables
- Framework Examples: Integrate into your framework application and test the endpoints
- "Class not found" errors: Make sure you've run
composer install - Authentication errors: Verify your environment variables are set correctly
- Redirect URI mismatch: Ensure your redirect URI matches what's configured in Kinde
- CORS issues: Make sure your domain is allowed in Kinde settings
To enable debug output, set:
export KINDE_DEBUG=trueAfter running the examples:
- Customize: Modify the examples to fit your application's needs
- Security: Implement proper session management and CSRF protection
- Error Handling: Add more robust error handling for production use
- Testing: Write tests for your authentication flows
For issues with the examples or SDK, please check: