5
5
use OAuth2 \Storage \ClientCredentialsInterface ;
6
6
use OAuth2 \RequestInterface ;
7
7
use OAuth2 \ResponseInterface ;
8
+ use LogicException ;
8
9
9
10
/**
10
11
* Validate a client via Http Basic authentication
@@ -19,14 +20,16 @@ class HttpBasic implements ClientAssertionTypeInterface
19
20
protected $ config ;
20
21
21
22
/**
22
- * @param OAuth2\Storage\ClientCredentialsInterface $clientStorage REQUIRED Storage class for retrieving client credentials information
23
- * @param array $config OPTIONAL Configuration options for the server
24
- * <code>
25
- * $config = array(
26
- * 'allow_credentials_in_request_body' => true, // whether to look for credentials in the POST body in addition to the Authorize HTTP Header
27
- * 'allow_public_clients' => true // if true, "public clients" (clients without a secret) may be authenticated
28
- * );
29
- * </code>
23
+ * Config array $config should look as follows:
24
+ * @code
25
+ * $config = array(
26
+ * 'allow_credentials_in_request_body' => true, // whether to look for credentials in the POST body in addition to the Authorize HTTP Header
27
+ * 'allow_public_clients' => true // if true, "public clients" (clients without a secret) may be authenticated
28
+ * );
29
+ * @endcode
30
+ *
31
+ * @param ClientCredentialsInterface $storage Storage
32
+ * @param array $config Configuration options for the server
30
33
*/
31
34
public function __construct (ClientCredentialsInterface $ storage , array $ config = array ())
32
35
{
@@ -37,14 +40,22 @@ public function __construct(ClientCredentialsInterface $storage, array $config =
37
40
), $ config );
38
41
}
39
42
43
+ /**
44
+ * Validate the OAuth request
45
+ *
46
+ * @param RequestInterface $request
47
+ * @param ResponseInterface $response
48
+ * @return bool|mixed
49
+ * @throws LogicException
50
+ */
40
51
public function validateRequest (RequestInterface $ request , ResponseInterface $ response )
41
52
{
42
53
if (!$ clientData = $ this ->getClientCredentials ($ request , $ response )) {
43
54
return false ;
44
55
}
45
56
46
57
if (!isset ($ clientData ['client_id ' ])) {
47
- throw new \ LogicException ('the clientData array must have "client_id" set ' );
58
+ throw new LogicException ('the clientData array must have "client_id" set ' );
48
59
}
49
60
50
61
if (!isset ($ clientData ['client_secret ' ]) || $ clientData ['client_secret ' ] == '' ) {
@@ -70,6 +81,11 @@ public function validateRequest(RequestInterface $request, ResponseInterface $re
70
81
return true ;
71
82
}
72
83
84
+ /**
85
+ * Get the client id
86
+ *
87
+ * @return mixed
88
+ */
73
89
public function getClientId ()
74
90
{
75
91
return $ this ->clientData ['client_id ' ];
@@ -82,13 +98,14 @@ public function getClientId()
82
98
* According to the spec (draft 20), the client_id can be provided in
83
99
* the Basic Authorization header (recommended) or via GET/POST.
84
100
*
85
- * @return
86
- * A list containing the client identifier and password, for example
101
+ * @param RequestInterface $request
102
+ * @param ResponseInterface $response
103
+ * @return array|null A list containing the client identifier and password, for example:
87
104
* @code
88
- * return array(
89
- * "client_id" => CLIENT_ID, // REQUIRED the client id
90
- * "client_secret" => CLIENT_SECRET, // OPTIONAL the client secret (may be omitted for public clients)
91
- * );
105
+ * return array(
106
+ * "client_id" => CLIENT_ID, // REQUIRED the client id
107
+ * "client_secret" => CLIENT_SECRET, // OPTIONAL the client secret (may be omitted for public clients)
108
+ * );
92
109
* @endcode
93
110
*
94
111
* @see http://tools.ietf.org/html/rfc6749#section-2.3.1
@@ -108,7 +125,6 @@ public function getClientCredentials(RequestInterface $request, ResponseInterfac
108
125
* client_secret can be null if the client's password is an empty string
109
126
* @see http://tools.ietf.org/html/rfc6749#section-2.3.1
110
127
*/
111
-
112
128
return array ('client_id ' => $ request ->request ('client_id ' ), 'client_secret ' => $ request ->request ('client_secret ' ));
113
129
}
114
130
}
0 commit comments