subfission / cas

Simple CAS Authentication for Laravel 5 - 10.
MIT License
151 stars 70 forks source link

CasManager.php error after server upgrade #100

Closed fbmfbm closed 3 years ago

fbmfbm commented 3 years ago

Hi all, I need to update my Cas authentification on an laravel app after the Cas server update from new version (2.0 protocol to 3.0) and i'm facing some CasManager.php error :

phpCAS error: phpCAS::checkAuthentication(): this method should be used only after CAS_Client::forceAuthentication() or CAS_Client::isAuthenticated() in D:\Documents\www\dev1\pp_plateforme\vendor\subfission\cas\src\Subfission\Cas\CasManager.php on line 299

i'm using this handle middleware for test :

` public function handle($request, Closure $next) {

    if( ! cas()->checkAuthentication())
    {
        if ($request->ajax()) {
            return response('Unauthorized.', 401);
        }
        cas()->authenticate();
    }
    session()->put('cas_user', cas()->user() );
    $user = User::where('email', 'ILIKE', cas()->user())->first();
    dd(cas()->getAttributes());
    return $next($request);

} `

but cas()->authenticate seam to create this error.

i'm checked for cas config and remove SAML enabled cas and set cas version to 3.0 but nothing to do!

this is my cas config for Subfission/cas version 4.0:

'cas_hostname' => env('CAS_HOSTNAME', 'xxxxxxxx.fr'), cas_real_hosts' => env('CAS_REAL_HOSTS', 'xxxxxxx.fr'), 'cas_session_name' => env('CAS_SESSION_NAME', 'CASAuth'), 'cas_control_session' => env('CAS_CONTROL_SESSIONS', false), 'cas_proxy' => env('CAS_PROXY', false), 'cas_port' => env('CAS_PORT', 443), 'cas_uri' => env('CAS_URI', '/cas'), 'cas_validation' => env('CAS_VALIDATION', '') 'cas_cert' => env('CAS_CERT', ''), cas_validate_cn' => env('CAS_VALIDATE_CN', true), 'cas_login_url' => env('CAS_LOGIN_URL', ''), 'cas_logout_url' => env('CAS_LOGOUT_URL', 'xxxxxxxxxxxx.rf/cas/logout'), 'cas_logout_redirect' => env('CAS_LOGOUT_REDIRECT', ''), cas_redirect_path' => env('CAS_REDIRECT_PATH', ''), 'cas_enable_saml' => env('CAS_ENABLE_SAML', false), 'cas_version' => env('CAS_VERSION', "3.0"), 'cas_debug' => env('CAS_DEBUG', true), 'cas_verbose_errors' => env('CAS_VERBOSE_ERRORS', true), 'cas_masquerade' => env('CAS_MASQUERADE', '')

What's about this error ?

subfission commented 3 years ago

What version of this package are you using?

fbmfbm commented 3 years ago

Thank's for your answer. As i said in my message, i'm using the last one (4.0.1)

I found the solution : cas_validate_cn config variable must be to false for me to working.

Bye!

subfission commented 3 years ago

I'd try version 4.1 0b4912a, but it sounds like you got it working. Cheers~