PHP code example of efumanti / cohesion2-library

1. Go to this page and download the library: Download efumanti/cohesion2-library library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

efumanti / cohesion2-library example snippets


      $cohesion = new Cohesion2;
      $cohesion->useSSO(false);
      $cohesion->auth();

       use andreaval\Cohesion2\Cohesion2;
      use andreaval\Cohesion2\Cohesion2Exception;
      try{
          $cohesion = new Cohesion2;
          $cohesion->auth();
      }
      catch(Cohesion2Exception $e){
          die($e->getMessage());
      }
      if($cohesion->isAuth()){
          echo 'Utente autenticato: '.$cohesion->username.'<br>';
          echo 'Id SSO: '.$cohesion->id_sso.'<br>';
          echo 'Id Aspnet: '.$cohesion->id_aspnet.'<br>';
          echo 'Profilo: <pre>'.var_export($cohesion->profile,1).'</pre>';
      } 

$cohesion = new Cohesion2('cohesion2', null, null, 'PORTALE_AZIENDA');

$cohesion = new Cohesion2('cohesion2', ['app.example.it', 'www.example.it']);
$cohesion->auth();

// La libreria legge automaticamente $_ENV / $_SERVER / getenv() in questo
// ordine. È compatibile con vlucas/phpdotenv, Symfony Dotenv e Laravel.
$cohesion = new Cohesion2();
$cohesion->auth();

$cohesion = new Cohesion2('cohesion2', null, true);

      $cohesion = new Cohesion2;
      $cohesion->useSAML20(true);
      $cohesion->enableEIDASLogin(); //per abilitare il login eIDAS
      $cohesion->enableSPIDProLogin(['PF','PG','LP']); //per abilitare il login SPID Professionale
      $cohesion->auth();

      echo $cohesion->profile['nome'].' '.$cohesion->profile['cognome'];

      $cohesion = new Cohesion2;
      $cohesion->logout();

      $cohesion = new Cohesion2;
      $cohesion->logoutLocal();

      $cohesion->setAuthRestriction('1,2,3');

      if($cohesion->profile['tipo_autenticazione']!='PW'){
          echo 'OK puoi usare il servizio';
      }
      else echo 'Autenticazione debole non permessa';
xml
<dsAuth xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://tempuri.org/Auth.xsd">
    <auth>
        <user/>
        <id_sa/>
        <id_sito>TEST</id_sito>
        <esito_auth_sa/>
        <id_sessione_sa/>
        <id_sessione_aspnet_sa/>
        <url_validate><![CDATA[https://app.example.it/login.php?cohesionCheck=1]]></url_validate>
        <url_richiesta><![CDATA[https://app.example.it/login.php?cohesionCheck=1]]></url_richiesta>
        <esito_auth_sso/>
        <id_sessione_sso/>
        <id_sessione_aspnet_sso/>
        <stilesheet>AuthRestriction=0,1,2,3</stilesheet>
        <AuthRestriction xmlns="">0,1,2,3</AuthRestriction>
    </auth>
</dsAuth>
xml
<dsAuth xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://tempuri.org/Auth.xsd">
    <auth>
        <user>nome.cognome</user>
        <id_sa>1</id_sa>
        <id_sito>TEST</id_sito>
        <esito_auth_sa>OK</esito_auth_sa>
        <id_sessione_sa>B0C0E8C2C6ECACB4D096FA8C14D37B25...</id_sessione_sa>
        <id_sessione_aspnet_sa>1h5h2f3r0nfeoazu3seeue4f</id_sessione_aspnet_sa>
        <url_validate>https://app.example.it/login.php?cohesionCheck=1</url_validate>
        <url_richiesta>https://app.example.it/login.php?cohesionCheck=1</url_richiesta>
        <esito_auth_sso>OK</esito_auth_sso>
        <id_sessione_sso>179422C462F5C75194F9D0863025EC34...</id_sessione_sso>
        <id_sessione_aspnet_sso>1h5h2f3r0nfeoazu3seeue4f</id_sessione_aspnet_sso>
        <stilesheet/>
        <tipoAutenticazione xmlns="">Password</tipoAutenticazione>
        <ip xmlns="">cohesion2.regione.marche.it</ip>
    </auth>
</dsAuth>