Skip to content

Commit 069bb7f

Browse files
Joosep JõelehtJoosep Jõeleht
Joosep Jõeleht
authored and
Joosep Jõeleht
committed
release(1.3.0) - Implemented new WebAuthN endpoints to TwoFactorAuthenticationService.php
Also removed old U2F endpoints support.
1 parent 9b7e535 commit 069bb7f

File tree

2 files changed

+133
-18
lines changed

2 files changed

+133
-18
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "",
44
"type": "library",
55
"license": "EUPL-1.1",
6-
"version": "1.2.8",
6+
"version": "1.3.0",
77
"require": {
88
"php": "^7.4|^8.0|^8.1",
99
"ext-curl": "*",

src/Service/TwoFactorAuthenticationService.php

+132-17
Original file line numberDiff line numberDiff line change
@@ -2,66 +2,181 @@
22

33
namespace Zone\Wildduck\Service;
44

5+
use Zone\Wildduck\Exception\ApiConnectionException;
6+
use Zone\Wildduck\Exception\AuthenticationFailedException;
7+
use Zone\Wildduck\Exception\InvalidAccessTokenException;
8+
use Zone\Wildduck\Exception\RequestFailedException;
9+
use Zone\Wildduck\Exception\ValidationException;
10+
use Zone\Wildduck\WildduckObject;
11+
512
class TwoFactorAuthenticationService extends AbstractService
613
{
714

8-
public function disable(string $user, $params = null, $opts = null)
15+
/**
16+
* @throws RequestFailedException
17+
* @throws InvalidAccessTokenException
18+
* @throws AuthenticationFailedException
19+
* @throws ApiConnectionException
20+
* @throws ValidationException
21+
*/
22+
public function disable(string $user, $params = null, $opts = null): WildduckObject
923
{
1024
return $this->request('delete', $this->buildPath('/users/%s/2fa', $user), $params, $opts);
1125
}
1226

13-
public function disableTOTPAuth(string $user, $params = null, $opts = null)
27+
/**
28+
* @throws RequestFailedException
29+
* @throws InvalidAccessTokenException
30+
* @throws AuthenticationFailedException
31+
* @throws ApiConnectionException
32+
* @throws ValidationException
33+
*/
34+
public function disableTOTPAuth(string $user, $params = null, $opts = null): WildduckObject
1435
{
1536
return $this->request('delete', $this->buildPath('/users/%s/2fa/totp', $user), $params, $opts);
1637
}
1738

18-
public function disableCustom(string $user, $params = null, $opts = null)
39+
/**
40+
* @throws RequestFailedException
41+
* @throws InvalidAccessTokenException
42+
* @throws AuthenticationFailedException
43+
* @throws ApiConnectionException
44+
* @throws ValidationException
45+
*/
46+
public function disableCustom(string $user, $params = null, $opts = null): WildduckObject
1947
{
2048
return $this->request('delete', $this->buildPath('/users/%s/2fa/custom', $user), $params, $opts);
2149
}
2250

23-
public function enableTOTPSeed(string $user, $params = null, $opts = null)
51+
/**
52+
* @throws RequestFailedException
53+
* @throws InvalidAccessTokenException
54+
* @throws AuthenticationFailedException
55+
* @throws ApiConnectionException
56+
* @throws ValidationException
57+
*/
58+
public function enableTOTPSeed(string $user, $params = null, $opts = null): WildduckObject
2459
{
2560
return $this->request('post', $this->buildPath('/users/%s/2fa/totp/enable', $user), $params, $opts);
2661
}
2762

28-
public function enableCustom(string $user, $params = null, $opts = null)
63+
/**
64+
* @throws RequestFailedException
65+
* @throws InvalidAccessTokenException
66+
* @throws AuthenticationFailedException
67+
* @throws ApiConnectionException
68+
* @throws ValidationException
69+
*/
70+
public function enableCustom(string $user, $params = null, $opts = null): WildduckObject
2971
{
3072
return $this->request('put', $this->buildPath('/users/%s/2fa/custom', $user), $params, $opts);
3173
}
3274

33-
public function generateTOTPSeed(string $user, $params = null, $opts = null)
75+
/**
76+
* @throws RequestFailedException
77+
* @throws InvalidAccessTokenException
78+
* @throws AuthenticationFailedException
79+
* @throws ApiConnectionException
80+
* @throws ValidationException
81+
*/
82+
public function generateTOTPSeed(string $user, $params = null, $opts = null): WildduckObject
3483
{
3584
return $this->request('post', $this->buildPath('/users/%s/2fa/totp/setup', $user), $params, $opts);
3685
}
3786

38-
public function validateTOTPToken(string $user, $params = null, $opts = null)
87+
/**
88+
* @throws RequestFailedException
89+
* @throws InvalidAccessTokenException
90+
* @throws AuthenticationFailedException
91+
* @throws ApiConnectionException
92+
* @throws ValidationException
93+
*/
94+
public function validateTOTPToken(string $user, $params = null, $opts = null): WildduckObject
3995
{
4096
return $this->request('post', $this->buildPath('/users/%s/2fa/totp/check', $user), $params, $opts);
4197
}
4298

43-
public function generateU2F(string $user, $params = null, $opts = null)
99+
/**
100+
* Gets the challenge used to register a new WebAuthN key
101+
*
102+
* @throws RequestFailedException
103+
* @throws InvalidAccessTokenException
104+
* @throws AuthenticationFailedException
105+
* @throws ApiConnectionException
106+
* @throws ValidationException
107+
*/
108+
public function webAuthNCredentials(string $user, $params = null, $opts = null): WildduckObject
109+
{
110+
return $this->requestCollection('get', $this->buildPath('/users/%s/2fa/webauthn/credentials', $user), $params, $opts);
111+
}
112+
113+
/**
114+
* Gets the challenge used to register a new WebAuthN key
115+
*
116+
* @throws RequestFailedException
117+
* @throws InvalidAccessTokenException
118+
* @throws AuthenticationFailedException
119+
* @throws ApiConnectionException
120+
* @throws ValidationException
121+
*/
122+
public function webAuthNRegistrationChallenge(string $user, $params = null, $opts = null): WildduckObject
44123
{
45-
return $this->request('post', $this->buildPath('/users/%s/2fa/u2f/setup', $user), $params, $opts);
124+
return $this->request('post', $this->buildPath('/users/%s/2fa/webauthn/registration-challenge', $user), $params, $opts);
46125
}
47126

48-
public function enableU2F(string $user, $params = null, $opts = null)
127+
/**
128+
* Attests the credential used to register a new WebAuthN key
129+
*
130+
* @throws RequestFailedException
131+
* @throws InvalidAccessTokenException
132+
* @throws AuthenticationFailedException
133+
* @throws ApiConnectionException
134+
* @throws ValidationException
135+
*/
136+
public function webAuthNRegistrationAttestation(string $user, $params = null, $opts = null): WildduckObject
49137
{
50-
return $this->request('post', $this->buildPath('/users/%s/2fa/u2f/enable', $user), $params, $opts);
138+
return $this->request('post', $this->buildPath('/users/%s/2fa/webauthn/registration-attestation', $user), $params, $opts);
51139
}
52140

53-
public function disableU2F(string $user, $params = null, $opts = null)
141+
/**
142+
* Removes the credential for the user
143+
*
144+
* @throws RequestFailedException
145+
* @throws InvalidAccessTokenException
146+
* @throws AuthenticationFailedException
147+
* @throws ApiConnectionException
148+
* @throws ValidationException
149+
*/
150+
public function webAuthNRemoveCredential(string $user, string $credentialId, $params = null, $opts = null): WildduckObject
54151
{
55-
return $this->request('delete', $this->buildPath('/users/%s/2fa/u2f', $user), $params, $opts);
152+
return $this->request('delete', $this->buildPath('/users/%s/2fa/webauthn/credentials/%s', $user, $credentialId), $params, $opts);
56153
}
57154

58-
public function startU2F(string $user, $params = null, $opts = null)
155+
/**
156+
* Gets the challenge used for authentication with a WebAuthN compatible key
157+
*
158+
* @throws RequestFailedException
159+
* @throws InvalidAccessTokenException
160+
* @throws AuthenticationFailedException
161+
* @throws ApiConnectionException
162+
* @throws ValidationException
163+
*/
164+
public function webAuthNAuthenticationChallenge(string $user, $params = null, $opts = null): WildduckObject
59165
{
60-
return $this->request('post', $this->buildPath('/users/%s/2fa/u2f/start', $user), $params, $opts);
166+
return $this->request('post', $this->buildPath('/users/%s/2fa/webauthn/authentication-challenge', $user), $params, $opts);
61167
}
62168

63-
public function validateU2F(string $user, $params = null, $opts = null)
169+
/**
170+
* Asserts that the credential returned from the WebAuthN compatible key is allowed for the user
171+
*
172+
* @throws RequestFailedException
173+
* @throws InvalidAccessTokenException
174+
* @throws AuthenticationFailedException
175+
* @throws ApiConnectionException
176+
* @throws ValidationException
177+
*/
178+
public function webAuthNAuthenticationAssertion(string $user, $params = null, $opts = null): WildduckObject
64179
{
65-
return $this->request('post', $this->buildPath('/users/%s/2fa/u2f/check', $user), $params, $opts);
180+
return $this->request('post', $this->buildPath('/users/%s/2fa/webauthn/authentication-assertion', $user), $params, $opts);
66181
}
67182
}

0 commit comments

Comments
 (0)