2
2
3
3
namespace Zone \Wildduck \Service ;
4
4
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
+
5
12
class TwoFactorAuthenticationService extends AbstractService
6
13
{
7
14
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
9
23
{
10
24
return $ this ->request ('delete ' , $ this ->buildPath ('/users/%s/2fa ' , $ user ), $ params , $ opts );
11
25
}
12
26
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
14
35
{
15
36
return $ this ->request ('delete ' , $ this ->buildPath ('/users/%s/2fa/totp ' , $ user ), $ params , $ opts );
16
37
}
17
38
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
19
47
{
20
48
return $ this ->request ('delete ' , $ this ->buildPath ('/users/%s/2fa/custom ' , $ user ), $ params , $ opts );
21
49
}
22
50
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
24
59
{
25
60
return $ this ->request ('post ' , $ this ->buildPath ('/users/%s/2fa/totp/enable ' , $ user ), $ params , $ opts );
26
61
}
27
62
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
29
71
{
30
72
return $ this ->request ('put ' , $ this ->buildPath ('/users/%s/2fa/custom ' , $ user ), $ params , $ opts );
31
73
}
32
74
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
34
83
{
35
84
return $ this ->request ('post ' , $ this ->buildPath ('/users/%s/2fa/totp/setup ' , $ user ), $ params , $ opts );
36
85
}
37
86
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
39
95
{
40
96
return $ this ->request ('post ' , $ this ->buildPath ('/users/%s/2fa/totp/check ' , $ user ), $ params , $ opts );
41
97
}
42
98
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
44
123
{
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 );
46
125
}
47
126
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
49
137
{
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 );
51
139
}
52
140
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
54
151
{
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 );
56
153
}
57
154
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
59
165
{
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 );
61
167
}
62
168
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
64
179
{
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 );
66
181
}
67
182
}
0 commit comments