Skip to content

Commit 499df4d

Browse files
committed
move the password_authsource parameter into the authsource config
it is misplaced in the general module config because only needed specifically in the Supercharged context
1 parent 06d95e0 commit 499df4d

3 files changed

Lines changed: 38 additions & 7 deletions

File tree

README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ You can install this module with composer:
2222

2323
If you are using PHP 7, you also need to install either the GMP extension (recommended) or the BCMath extension.
2424

25-
## How to setup the webauthn module as an authprocfilter
25+
## How to setup the webauthn module as a second-factor (an authprocfilter)
2626

2727
You need to enable the module's authprocfilter at a priority level
2828
so that it takes place AFTER the first-factor authentication. E.g. at 100 and
@@ -100,7 +100,7 @@ will be forced into 2FA.
100100
Then you need to copy config-templates/module_webauthn.php to your config directory
101101
and adjust settings accordingly. See the file for parameters description.
102102

103-
## How to set up Passwordless authentication
103+
## How to set up (pure) Passwordless authentication
104104

105105
In passwordless mode, the module provides an AuthSource, to be configured as
106106
usual in simpleSAMLphp's config/authsources.php
@@ -131,6 +131,27 @@ The authsource takes the following parameters in authsources.php:
131131
],
132132
```
133133

134+
## How to set up simultaneous Passwordless and traditional two-factor
135+
136+
In this mode, the authentication prompt simultaneously allows for either
137+
triggering a Passwordless auth, or to enter a username/password as traditional
138+
first-factor.
139+
140+
The configuration is almost identical to Passwordless above, but requires one
141+
extra required configuration parameter: the authsource that should be used to
142+
validate the username/password, if supplied by the user.
143+
144+
The authsource takes the following parameters in authsources.php:
145+
146+
```php
147+
'name-your-source' => [
148+
'webauthn:Supercharged',
149+
'password_authsource' => 'whatever-authsource',
150+
// 'authncontextclassref' => 'https://refeds.org/profile/mfa',
151+
152+
],
153+
```
154+
134155
## Using storage
135156

136157
The database schema sets itself up on first use automatically. The schema can be

src/Auth/Source/Supercharged.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,23 @@
2222
class Supercharged extends Passwordless
2323
{
2424

25+
/**
26+
* The AuthSource to use when someone enters a username/password
27+
*
28+
* @var string
29+
*/
30+
private $pushbackAuthsource;
31+
2532
public function __construct(array $info, array $config)
2633
{
2734
parent::__construct($info, $config);
35+
36+
$this->pushbackAuthsource = $this->authSourceConfig->getString("password_authsource");
2837
}
2938
public function authenticate(array &$state): void
3039
{
3140
$state['saml:AuthnContextClassRef'] = $this->authnContextClassRef;
41+
$state['pushbackAuthsource'] = $this->pushbackAuthsource;
3242

3343
StaticProcessHelper::prepareStatePasswordlessAuth($this->stateData, $state);
3444
StaticProcessHelper::saveStateAndRedirectSupercharged($state);

src/Controller/PushbackUserPass.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,10 @@ public function main(Request $request): Response {
100100
throw new Error\BadRequest('Missing required StateId query parameter.');
101101
}
102102

103-
$moduleConfig = Configuration::getOptionalConfig('module_webauthn.php');
103+
$state = $this->authState::loadState($stateId, 'webauthn:request');
104+
104105
$authsources = Configuration::getConfig('authsources.php')->toArray();
105-
$authsourceString = $moduleConfig->getString('password_authsource');
106+
$authsourceString = $state['pushbackAuthsource'];
106107
$classname = get_class(Source::getById($authsourceString));
107108
class_alias($classname, 'AuthSourceOverloader');
108109
$overrideSource = new class(['AuthId' => $authsourceString], $authsources[$authsourceString]) extends \AuthSourceOverloader {
@@ -112,9 +113,7 @@ public function loginOverload(string $username, string $password): array {
112113
};
113114

114115
$attribs = $overrideSource->loginOverload($request->request->get("username"), $request->request->get("password"));
115-
116-
$state = $this->authState::loadState($stateId, 'webauthn:request');
117-
116+
118117
// this is the confirmed username, we store it just like the Passwordless
119118
// one would have been
120119

@@ -123,6 +122,7 @@ public function loginOverload(string $username, string $password): array {
123122
// we deliberately do not store any additional attributes - these have
124123
// to be retrieved from the same authproc that would retrieve them
125124
// in Passwordless mode
125+
unset($attribs);
126126

127127
// now properly return our final state to the framework
128128
Source::completeAuth($state);

0 commit comments

Comments
 (0)