Skip to content

Commit 490203b

Browse files
committed
Fix SAML-Toolkits#84. Retrieve Session Timeout after processResponse
1 parent 7d41f06 commit 490203b

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

lib/Saml2/Auth.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,21 @@ class OneLogin_Saml2_Auth
3737

3838

3939
/**
40-
* SessionIndex. When the user is logged, this stored the
40+
* SessionIndex. When the user is logged, this stored it
4141
* from the AuthnStatement of the SAML Response
42+
*
43+
* @var string
4244
*/
4345
private $_sessionIndex;
4446

47+
/**
48+
* SessionNotOnOrAfter. When the user is logged, this stored it
49+
* from the AuthnStatement of the SAML Response
50+
*
51+
* @var DateTime
52+
*/
53+
private $_sessionExpiration;
54+
4555
/**
4656
* If any error.
4757
*
@@ -106,6 +116,7 @@ public function processResponse($requestId = null)
106116
$this->_nameid = $response->getNameId();
107117
$this->_authenticated = true;
108118
$this->_sessionIndex = $response->getSessionIndex();
119+
$this->_sessionExpiration = $response->getSessionNotOnOrAfter();
109120
} else {
110121
$this->_errors[] = 'invalid_response';
111122
$this->_errorReason = $response->getError();
@@ -236,6 +247,16 @@ public function getSessionIndex()
236247
return $this->_sessionIndex;
237248
}
238249

250+
/**
251+
* Returns the SessionNotOnOrAfter
252+
*
253+
* @return DateTime|null The SessionNotOnOrAfter of the assertion
254+
*/
255+
public function getSessionExpiration()
256+
{
257+
return $this->_sessionExpiration;
258+
}
259+
239260
/**
240261
* Returns if there were any error
241262
*

tests/src/OneLogin/Saml2/AuthTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public function testProcessNoResponse()
9292
* @covers OneLogin_Saml2_Auth::getNameId
9393
* @covers OneLogin_Saml2_Auth::getErrors
9494
* @covers OneLogin_Saml2_Auth::getSessionIndex
95+
* @covers OneLogin_Saml2_Auth::getSessionExpiration
9596
* @covers OneLogin_Saml2_Auth::getLastErrorReason
9697
*/
9798
public function testProcessResponseInvalid()
@@ -105,6 +106,7 @@ public function testProcessResponseInvalid()
105106
$this->assertEmpty($this->_auth->getAttributes());
106107
$this->assertNull($this->_auth->getNameId());
107108
$this->assertNull($this->_auth->getSessionIndex());
109+
$this->assertNull($this->_auth->getSessionExpiration());
108110
$this->assertNull($this->_auth->getAttribute('uid'));
109111
$this->assertEquals($this->_auth->getErrors(), array('invalid_response'));
110112
$this->assertEquals($this->_auth->getLastErrorReason(), "Reference validation failed");
@@ -152,6 +154,7 @@ public function testProcessResponseInvalidRequestId()
152154
* @covers OneLogin_Saml2_Auth::getAttribute
153155
* @covers OneLogin_Saml2_Auth::getNameId
154156
* @covers OneLogin_Saml2_Auth::getSessionIndex
157+
* @covers OneLogin_Saml2_Auth::getSessionExpiration
155158
* @covers OneLogin_Saml2_Auth::getErrors
156159
*/
157160
public function testProcessResponseValid()
@@ -168,6 +171,9 @@ public function testProcessResponseValid()
168171
$sessionIndex = $this->_auth->getSessionIndex();
169172
$this->assertNotNull($sessionIndex);
170173
$this->assertEquals('_6273d77b8cde0c333ec79d22a9fa0003b9fe2d75cb', $sessionIndex);
174+
$sessionExpiration = $this->_auth->getSessionExpiration();
175+
$this->assertNotNull($sessionExpiration);
176+
$this->assertEquals('1392802621', $sessionExpiration);
171177
}
172178

173179
/**

0 commit comments

Comments
 (0)