From 1c447e4a8e331ea21e3908eb1e64bb5f8a947a03 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Fri, 6 Jul 2012 19:21:11 +0100 Subject: [PATCH] Added newAuthCode function --- src/oauth2server/Server.php | 46 +++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/oauth2server/Server.php b/src/oauth2server/Server.php index d70620b0..e336fcf0 100644 --- a/src/oauth2server/Server.php +++ b/src/oauth2server/Server.php @@ -173,6 +173,52 @@ class Server return $params; } + public function newAuthCode(string $clientId, $type = 'user', + string $typeId, string $redirectUri, $scopes = array(), + string $access_token = null) + { + $authCode = $this->generateCode(); + + // Update an existing session with the new code + if ($access_token !== null) { + + $this->db->updateSession( + $clientId, + $type, + $typeId, + $authCode, + $accessToken, + 'request' + ); + + // Create a new oauth session + } else { + + // Delete any existing sessions just to be sure + $this->db->deleteSession($clientId, $type, $typeId); + + // Create a new session + $sessionId = $this->db->newSession( + $clientId, + $redirectUri, + $type, + $typeId, + $authCode, + null, + $stage = 'request' + ); + + // Add the scopes + foreach ($scopes as $scope) + { + $this->db->addSessionScope($sessionId, $scope); + } + + } + + return $authCode; + } + /** * Generates the redirect uri with appended params *