-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCAS.php
More file actions
111 lines (92 loc) · 2.95 KB
/
CAS.php
File metadata and controls
111 lines (92 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
declare(strict_types=1);
namespace SimpleSAML\Module\cas\Controller;
use Exception;
use SimpleSAML\Assert\Assert;
use SimpleSAML\Auth;
use SimpleSAML\Configuration;
use SimpleSAML\Error;
use SimpleSAML\HTTP\RunnableResponse;
use SimpleSAML\Module\cas\Auth\Source\CAS as CASSource;
use Symfony\Component\HttpFoundation\Request;
/**
* Controller class for the cas module.
*
* This class serves the different views available in the module.
*
* @package simplesamlphp/simplesamlphp-module-cas
*/
class CAS
{
/**
* @var \SimpleSAML\Auth\State|string
* @psalm-var \SimpleSAML\Auth\State|class-string
*/
protected $authState = Auth\State::class;
/**
* @var \SimpleSAML\Auth\Source|string
* @psalm-var \SimpleSAML\Auth\Source|class-string
*/
protected $authSource = Auth\Source::class;
/**
* Controller constructor.
*
* It initializes the global configuration and session for the controllers implemented here.
*
* @param \SimpleSAML\Configuration $config The configuration to use by the controllers.
*
* @throws \Exception
*/
public function __construct(
protected Configuration $config,
) {
}
/**
* Inject the \SimpleSAML\Auth\State dependency.
*
* @param \SimpleSAML\Auth\State $authState
*/
public function setAuthState(Auth\State $authState): void
{
$this->authState = $authState;
}
/**
* Inject the \SimpleSAML\Auth\Source dependency.
*
* @param \SimpleSAML\Auth\Source $authSource
*/
public function setAuthSource(Auth\Source $authSource): void
{
$this->authSource = $authSource;
}
/**
* Handle linkback-response from CAS.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* @return \SimpleSAML\HTTP\RunnableResponse
*/
public function linkback(Request $request): RunnableResponse
{
if (!$request->query->has('stateId')) {
throw new Error\BadRequest('Missing stateId parameter.');
}
$stateId = $request->query->getString('stateId');
/** @var array<mixed> $state */
$state = $this->authState::loadState($stateId, CASSource::STAGE_INIT);
if (!$request->query->has('ticket')) {
throw new Error\BadRequest('Missing ticket parameter.');
}
$ticket = $request->query->getString('ticket');
$state['cas:ticket'] = $ticket;
// Find authentication source
Assert::keyExists($state, CASSource::AUTHID);
$sourceId = $state[CASSource::AUTHID];
/** @var \SimpleSAML\Module\cas\Auth\Source\CAS|null $source */
$source = $this->authSource::getById($sourceId);
if ($source === null) {
throw new Exception('Could not find authentication source with id ' . $sourceId);
}
$source->finalStep($state);
return new RunnableResponse([Auth\Source::class, 'completeAuth'], [&$state]);
}
}