-
Notifications
You must be signed in to change notification settings - Fork 5
modified to serve as an OAuth2 introspection endpont #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
6c3c381
4dec874
23aff03
63b7be9
cb4e18f
7aab53c
2b4ddd7
fc36a39
895cebc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -253,15 +253,57 @@ function invalidRequest(): void | |
| header('HTTP/1.1 415 Unsupported Media Type'); | ||
| exit(); | ||
| } | ||
| $revoke = filter_input(INPUT_POST, 'action', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '@^revoke$@']]); | ||
| if (is_string($revoke)) { | ||
| $token = filter_input(INPUT_POST, 'token', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '@^[0-9a-f]+_[0-9a-f]+$@']]); | ||
| $action = filter_input(INPUT_GET, 'action', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '@^(revoke|introspect|authorize)$@']]); | ||
| $token = filter_input(INPUT_POST, 'token', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '@^[0-9a-f]+_[0-9a-f]+$@']]); | ||
| if (!is_string($action)) { | ||
| invalidRequest(); | ||
| } | ||
| // check if is POST+revoke request | ||
| if ($action === 'revoke') { | ||
| if (is_string($token)) { | ||
| revokeToken($token); | ||
| } | ||
| header('HTTP/1.1 200 OK'); | ||
| exit(); | ||
| } | ||
| // check if is POST+introspection request | ||
| if ($action === 'introspect') { | ||
| $tokenInfo = retrieveToken($token); | ||
| if ($tokenInfo === null || $tokenInfo['active'] === '0') { | ||
| header('HTTP/1.1 200 OK'); | ||
| header('Content-Type: application/json;charset=UTF-8'); | ||
| exit(json_encode([ | ||
| 'active' => false, | ||
| ])); | ||
| } | ||
| // Authorize resource server as per specification (see https://indieauth.spec.indieweb.org/#access-token-verification-response-p-1) | ||
| // For us this means we are expecting the Basic user to be the client ID of the consumer. | ||
| // With basic, everything after the first colon (:) is considered the password. | ||
| // Since we are working with URIs to identify, we need to handle | ||
| // the pattern scheme://domain/path:password | ||
| // To do this, we assume (and enforce) that the password is a single underscore (_). | ||
|
Comment on lines
+279
to
+284
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should also verify that the request is from the client specified, checking their certificate to do so. |
||
| $basicAuth = $_SERVER['PHP_AUTH_USER'] . ':' . $_SERVER['PHP_AUTH_PW']; | ||
| $storedAuth = $tokenInfo['auth_client_id'] . ':_'; | ||
| $storedAuthEncoded = urlencode($tokenInfo['auth_client_id']) . ':_'; | ||
| if ($storedAuth !== $basicAuth && $storedAuthEncoded !== $basicAuth) { | ||
| header('WWW-Authenticate: Basic'); | ||
| header('HTTP/1.0 401 Unauthorized'); | ||
| exit('Unauthorized'); | ||
| } | ||
| header('HTTP/1.1 200 OK'); | ||
| header('Content-Type: application/json;charset=UTF-8'); | ||
| exit(json_encode([ | ||
carrvo marked this conversation as resolved.
Show resolved
Hide resolved
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should also |
||
| 'token_type' => 'Bearer', | ||
| 'me' => $tokenInfo['auth_me'], | ||
carrvo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 'sub' => $tokenInfo['auth_me'], | ||
| 'client_id' => $tokenInfo['auth_client_id'], | ||
| 'scope' => $tokenInfo['auth_scope'], | ||
| 'iat' => strtotime($tokenInfo['created']), | ||
| 'exp' => strtotime($tokenInfo['revoked']), | ||
| 'active' => true, | ||
| ])); | ||
| } | ||
| // else is a POST+authorization request | ||
| $request = array_merge( | ||
| filter_input_array(INPUT_POST, [ | ||
| 'grant_type' => [ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.