Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Phpcas Laravel Package

apereo/phpcas

Apereo PHP CAS is a PHP client library for Central Authentication Service (CAS) single sign-on. It handles CAS login/logout flows, ticket validation, session management, and proxy support, with configurable endpoints for integrating CAS authentication into PHP apps.

View on GitHub
Deep Wiki
Context7

Apereo PHP CAS Client

Frequently asked questions about Phpcas
How do I integrate apereo/phpcas into a Laravel application for CAS SSO?
Start by installing the package via Composer (`composer require apereo/phpcas`), then configure the CAS server settings in your `config/services.php` or a custom config file. Use the provided `CASMiddleware` in Laravel’s middleware pipeline to protect routes, like `Route::middleware(['web', 'cas'])->group(...);`. For user resolution, extend Laravel’s auth system with a custom `CasUserProvider` or integrate with existing guards.
Does apereo/phpcas support Laravel’s stateless APIs (e.g., API routes with Sanctum/Passport)?
No, apereo/phpcas relies on PHP sessions for CAS ticket validation, which conflicts with Laravel’s stateless APIs. For API-first apps, consider using a hybrid approach (e.g., CAS for web, tokens for APIs) or explore alternatives like OAuth2 libraries. Ensure your session driver (e.g., Redis) is distributed if scaling horizontally.
What Laravel versions does apereo/phpcas officially support?
The package is designed for Laravel 8+ and is actively maintained, but compatibility may vary. Test thoroughly with your Laravel version (e.g., 10.x or 11.x). For older versions, check the package’s release notes or backport changes manually. Ensure your PHP version (8.0+) aligns with Laravel’s requirements.
How do I configure apereo/phpcas for a CAS 3.0 server with custom attributes?
Configure the CAS server URL and protocol version (e.g., `CAS_3_0`) in your config. For custom attributes, extend the `CasUserProvider` to map CAS attributes (e.g., `eduPersonPrincipalName`) to Laravel’s user model fields. Example: `return $this->mapAttribute('email', $attributes['eduPersonPrincipalName']);`. Validate these mappings in your CAS server’s attribute release policy.
Can I use apereo/phpcas alongside Laravel’s default authentication (e.g., database auth)?
Yes, you can implement a hybrid auth system. Use `CASMiddleware` for CAS-protected routes and fall back to Laravel’s default auth (e.g., `Auth::guard('web')->attempt()`) for others. For seamless switching, create a custom guard or extend `CasGuard` to delegate to the default guard when CAS fails. Example: `Auth::guard('cas')->user() ?? Auth::guard('web')->user();`
What are common issues when testing apereo/phpcas in production?
Common pitfalls include misconfigured CAS server URLs, session timeouts, or proxy settings. Test thoroughly with your staging CAS server, especially for ticket validation timeouts (default: 5 minutes). Monitor session storage (e.g., Redis) for scalability under load. Use logging (`monolog`) to debug CAS protocol errors or failed validations.
How do I handle CAS authentication failures (e.g., server downtime) in Laravel?
Implement fallback mechanisms by catching exceptions (e.g., `CasException`) and redirecting users to a backup auth method or a maintenance page. Example: `try { Auth::guard('cas')->attempt(); } catch (CasException $e) { return redirect()->route('fallback.auth'); }`. For graceful degradation, configure a retry policy or notify admins via Laravel’s `Event` system.
Does apereo/phpcas work with Laravel’s queue system for async CAS validation?
No, apereo/phpcas performs synchronous CAS ticket validation during the request lifecycle. For async workflows, consider validating tickets in a middleware or job triggered by a session event (e.g., `starting`). Offload heavy CAS attribute processing to queues, but ensure session data remains consistent. Avoid async validation for critical paths like login.
Are there alternatives to apereo/phpcas for CAS SSO in Laravel?
Yes, alternatives include `league/cas-client` (modern, PSR-compliant) or `phpCAS` (legacy). `league/cas-client` offers better Laravel integration (e.g., middleware, guards) and supports CAS 1.0/2.0/3.0. For OAuth2-based SSO, consider `laravel/socialite` with CAS-compatible providers. Evaluate based on your CAS protocol version and Laravel compatibility needs.
How do I mock CAS responses for unit testing apereo/phpcas in Laravel?
Use PHP’s `Mockery` or Laravel’s `Http` facade to mock HTTP requests to the CAS server. Example: `Http::fake([$casServerUrl => Http::response($casResponse)]);`. For testing ticket validation, create a fake `CasClient` instance with predefined responses. Test edge cases like expired tickets or malformed responses. Integrate with Laravel’s `Testing` traits for seamless assertions.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor