diff --git a/oauth2_server.api.php b/oauth2_server.api.php index e7ae38e..f90dcf8 100644 --- a/oauth2_server.api.php +++ b/oauth2_server.api.php @@ -23,6 +23,24 @@ function hook_oauth2_server_pre_authorize() { } /** + * Execute operations before OAuth2 Server sends a token response. + * + * @param \OAuth2Server $server + * @param \OAuth2\Request $request + * @param \OAuth2\Response $response + */ +function hook_oauth2_server_token(\OAuth2Server $server, \OAuth2\Request $request, \OAuth2\Response $response) { + // Example: if the response is not successful, log a message. + if ($response->getStatusCode() != 200) { + watchdog('mymodule', 'Failed token response from server @server: @code @body', array( + '@server' => $server->name, + '@code' => $response->getStatusCode(), + '@body' => $response->getResponseBody(), + )); + } +} + +/** * Alter user claims about the provided account. * * The provided claims can be included in the id_token and / or returned from diff --git a/oauth2_server.pages.inc b/oauth2_server.pages.inc index 38d7ba7..a74beac 100644 --- a/oauth2_server.pages.inc +++ b/oauth2_server.pages.inc @@ -164,6 +164,10 @@ function oauth2_server_token_page() { $response = new OAuth2\Response(); $oauth2_server = oauth2_server_start($server); $oauth2_server->handleTokenRequest($request, $response); + + // Allow other modules to act before the token response is sent. + module_invoke_all('oauth2_server_token', $server, $request, $response); + return oauth2_server_send_response($response); }