simplesamlphp /
simplesamlphp-module-webauthn
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace SimpleSAML\Module\webauthn\Controller; |
||
| 6 | |||
| 7 | use Exception; |
||
| 8 | use SimpleSAML\Auth; |
||
| 9 | use SimpleSAML\Configuration; |
||
| 10 | use SimpleSAML\Error; |
||
| 11 | use SimpleSAML\HTTP\RunnableResponse; |
||
| 12 | use SimpleSAML\Logger; |
||
| 13 | use SimpleSAML\Module\webauthn\Auth\Source\AuthSourceOverloader; |
||
|
0 ignored issues
–
show
|
|||
| 14 | use SimpleSAML\Session; |
||
| 15 | use Symfony\Component\HttpFoundation\Request; |
||
| 16 | use Symfony\Component\HttpFoundation\Response; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Controller class for the webauthn module. |
||
| 20 | * |
||
| 21 | * This class serves the different views available in the module. |
||
| 22 | * |
||
| 23 | * @package SimpleSAML\Module\webauthn |
||
| 24 | */ |
||
| 25 | class PushbackUserPass |
||
| 26 | { |
||
| 27 | /** @var \SimpleSAML\Auth\State|string */ |
||
| 28 | protected $authState = Auth\State::class; |
||
| 29 | |||
| 30 | /** @var \SimpleSAML\Logger|string */ |
||
| 31 | protected $logger = Logger::class; |
||
| 32 | |||
| 33 | |||
| 34 | /** |
||
| 35 | * Controller constructor. |
||
| 36 | * |
||
| 37 | * It initializes the global configuration and session for the controllers implemented here. |
||
| 38 | * |
||
| 39 | * @param \SimpleSAML\Configuration $config The configuration to use by the controllers. |
||
| 40 | * @param \SimpleSAML\Session $session The session to use by the controllers. |
||
| 41 | * |
||
| 42 | * @throws \Exception |
||
| 43 | */ |
||
| 44 | public function __construct( |
||
| 45 | protected Configuration $config, |
||
| 46 | protected Session $session, |
||
| 47 | ) { |
||
| 48 | } |
||
| 49 | |||
| 50 | |||
| 51 | /** |
||
| 52 | * Inject the \SimpleSAML\Auth\State dependency. |
||
| 53 | * |
||
| 54 | * @param \SimpleSAML\Auth\State $authState |
||
| 55 | */ |
||
| 56 | public function setAuthState(Auth\State $authState): void |
||
| 57 | { |
||
| 58 | $this->authState = $authState; |
||
| 59 | } |
||
| 60 | |||
| 61 | |||
| 62 | /** |
||
| 63 | * Inject the \SimpleSAML\Logger dependency. |
||
| 64 | * |
||
| 65 | * @param \SimpleSAML\Logger $logger |
||
| 66 | */ |
||
| 67 | public function setLogger(Logger $logger): void |
||
| 68 | { |
||
| 69 | $this->logger = $logger; |
||
| 70 | } |
||
| 71 | |||
| 72 | |||
| 73 | /** |
||
| 74 | * @param \Symfony\Component\HttpFoundation\Request $request |
||
| 75 | * @return ( |
||
|
0 ignored issues
–
show
|
|||
| 76 | * \Symfony\Component\HttpFoundation\RedirectResponse| |
||
| 77 | * \SimpleSAML\HTTP\RunnableResponse |
||
| 78 | * ) A Symfony Response-object. |
||
| 79 | */ |
||
| 80 | public function main(Request $request): Response |
||
| 81 | { |
||
| 82 | $this->logger::info('FIDO2 Supercharged - Redirecting to username/password validation'); |
||
| 83 | |||
| 84 | $stateId = $request->query->get('StateId'); |
||
| 85 | if ($stateId === null) { |
||
| 86 | throw new Error\BadRequest('Missing required StateId query parameter.'); |
||
| 87 | } |
||
| 88 | |||
| 89 | $state = $this->authState::loadState($stateId, 'webauthn:request'); |
||
| 90 | |||
| 91 | $authsources = Configuration::getConfig('authsources.php')->toArray(); |
||
| 92 | $authsourceString = $state['pushbackAuthsource']; |
||
| 93 | $authsourceClass = Auth\Source::getById($authsourceString); |
||
| 94 | if (is_null($authsourceClass)) { |
||
| 95 | throw new Exception("password authsource not found"); |
||
| 96 | } |
||
| 97 | $classname = get_class($authsourceClass); |
||
| 98 | class_alias($classname, '\SimpleSAML\Module\webauthn\Auth\Source\AuthSourceOverloader'); |
||
| 99 | $overrideSource = new class ( |
||
| 100 | ['AuthId' => $authsourceString], |
||
| 101 | $authsources[$authsourceString], |
||
| 102 | ) extends AuthSourceOverloader |
||
| 103 | { |
||
| 104 | public function loginOverload(string $username, string $password): array |
||
| 105 | { |
||
| 106 | return $this->login($username, $password); |
||
| 107 | } |
||
| 108 | }; |
||
| 109 | |||
| 110 | $attribs = $overrideSource->loginOverload( |
||
| 111 | $request->request->get("username"), |
||
| 112 | $request->request->get("password"), |
||
| 113 | ); |
||
| 114 | |||
| 115 | // this is the confirmed username, we store it just like the Passwordless |
||
| 116 | // one would have been |
||
| 117 | $state['Attributes'][$state['FIDO2AttributeStoringUsername']] = [ $request->request->get("username") ]; |
||
| 118 | |||
| 119 | // we deliberately do not store any additional attributes - these have |
||
| 120 | // to be retrieved from the same authproc that would retrieve them |
||
| 121 | // in Passwordless mode |
||
| 122 | unset($attribs); |
||
| 123 | |||
| 124 | // now properly return our final state to the framework |
||
| 125 | return new RunnableResponse([Auth\Source::class, 'completeAuth'], [&$state]); |
||
| 126 | } |
||
| 127 | |||
| 128 | |||
| 129 | public function login(string $username, string $password): array |
||
| 130 | { |
||
| 131 | throw new Exception("Ugh ($username, $password)."); |
||
| 132 | } |
||
| 133 | } |
||
| 134 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths