Skip to content

Commit f5f6efa

Browse files
committed
don't send state parameter in token request
A common mistake in the OAuth flow is expecting the client to send the state parameter in the token request. This fixes the token endpoint to not require that parameter. https://tools.ietf.org/html/rfc6749#section-4.1.3
1 parent 29ec8de commit f5f6efa

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,11 @@ To get an access token, the client makes a POST request to the token endpoint, p
134134
* `me` - the user's URL
135135
* `redirect_uri` - must match the redirect URI used in the request to obtain the authorization code
136136
* `client_id` - must match the client ID used in the initial request
137-
* `state` - must match the state parameter used in the initial request
138137

139138
The following function will make a POST request to the token endpoint and parse the result.
140139

141140
```php
142-
$token = IndieAuth\Client::getAccessToken($tokenEndpoint, $_GET['code'], $_GET['me'], $redirect_uri, $client_id, $_GET['state']);
141+
$token = IndieAuth\Client::getAccessToken($tokenEndpoint, $_GET['code'], $_GET['me'], $redirect_uri, $client_id);
143142
```
144143

145144
The `$token` variable will look like the following:

src/IndieAuth/Client.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public static function build_url($parsed_url) {
166166
}
167167

168168
// Used by clients to get an access token given an auth code
169-
public static function getAccessToken($tokenEndpoint, $code, $me, $redirectURI, $clientID, $state, $debug=false) {
169+
public static function getAccessToken($tokenEndpoint, $code, $me, $redirectURI, $clientID, $debug=false) {
170170
$ch = curl_init();
171171
self::_setUserAgent($ch);
172172
curl_setopt($ch, CURLOPT_URL, $tokenEndpoint);
@@ -177,7 +177,6 @@ public static function getAccessToken($tokenEndpoint, $code, $me, $redirectURI,
177177
'me' => $me,
178178
'code' => $code,
179179
'redirect_uri' => $redirectURI,
180-
'state' => $state,
181180
'client_id' => $clientID
182181
)));
183182
$response = curl_exec($ch);
@@ -201,7 +200,7 @@ public static function getAccessToken($tokenEndpoint, $code, $me, $redirectURI,
201200
}
202201

203202
// Used by a token endpoint to verify the auth code
204-
public static function verifyIndieAuthCode($authorizationEndpoint, $code, $me, $redirectURI, $clientID, $state, $debug=false) {
203+
public static function verifyIndieAuthCode($authorizationEndpoint, $code, $me, $redirectURI, $clientID, $debug=false) {
205204
$ch = curl_init();
206205
self::_setUserAgent($ch);
207206
curl_setopt($ch, CURLOPT_URL, $authorizationEndpoint);
@@ -210,7 +209,6 @@ public static function verifyIndieAuthCode($authorizationEndpoint, $code, $me, $
210209
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array(
211210
'code' => $code,
212211
'redirect_uri' => $redirectURI,
213-
'state' => $state,
214212
'client_id' => $clientID
215213
)));
216214
$response = curl_exec($ch);

0 commit comments

Comments
 (0)