ruvi
ruvi

Reputation: 129

How to logout from simplesamlphp

Can someone share the code how to logout from simplesamlphp?

<?php
  session_start();
  require_once('/var/www/usage-tracker/simplesamlphp/lib/_autoload.php');

  $as = new SimpleSAML_Auth_Simple('wso2-sp');
  $as->requireAuth();

  $auth_dataArray=$as-> getAuthDataArray ();

  $auth_data=$as-> getAuthData();
  $name=$as-> getAuthData("saml:sp:NameID");
  $name['Value'];
  $username=$name['Value'];
  $_SESSION['username']=$username;
  include 'ldap_groups.php';

This is my index page, it will redirected to another index page after the authentication how can I logout after that process?

Upvotes: 2

Views: 9116

Answers (4)

Lake Sachtleben
Lake Sachtleben

Reputation: 1

I created a logout page as follows that does the trick:

<?php
    require_once('/var/simplesamlphp/lib/_autoload.php');
    $as = new SimpleSAML_Auth_Simple ( 'default-sp' );
    // the param to logout is where you want to land after logging out.
    $as->logout("https://www`enter code here`.whereYouWantToEndUp.html");
?>

Upvotes: 0

Dan Gurin
Dan Gurin

Reputation: 341

At the end of docs/simplesamlphp-sp-api.md: You can easily create your own links without using this function (getLogoutURL). The URL should be:

.../simplesaml/module.php/core/as_logout.php?AuthId=<authentication source>&ReturnTo=<return URL>

For example:

.../simplesaml/module.php/core/as_logout.php?AuthId=default-sp&ReturnTo=/user

Upvotes: 1

Ruwantha
Ruwantha

Reputation: 2653

Just redirect to the logout URL

Ex : Zend Framework

    if($as->isAuthenticated()){
        return $this->redirect()->toUrl($as->getLogoutURL());  
    }

Upvotes: 0

rsabir
rsabir

Reputation: 736

Here's a code that can be used :

$URL_AFTER_LOGOUT = "/";
header("Location: ".$as->getLogoutURL($URL_AFTER_LOGOUT));

Hope that will help someone.

Upvotes: 2

Related Questions