From 5fbdccde402e100b7e5fe66d878339a159d7d2b2 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Fri, 6 Jul 2012 19:22:10 +0100 Subject: [PATCH] Added newAuthoriseRequest function --- src/oauth2server/Server.php | 41 +++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/oauth2server/Server.php b/src/oauth2server/Server.php index 836145ba..31bed001 100644 --- a/src/oauth2server/Server.php +++ b/src/oauth2server/Server.php @@ -173,6 +173,47 @@ class Server return $params; } + function newAuthoriseRequest(string $typeId, array $authoriseParams) + { + // Check if the user already has an access token + $accessToken = $this->db->hasAccessToken($userId, + $authoriseParams['client_id']); + + if ($accessToken !== false) { + + // Validate the access token matches the scopes requested + $originalScopes = $this->db->accessTokenScopes($accessToken); + + foreach ($authoriseParams['scopes'] as $scope) { + + if ( ! in_array($scope, $originalScopes)) + { + throw new OAuthServerClientException('invalid_scope: ' . + $this->errors['invalid_scope']); + } + + } + + // The user has authorised the client so generate a new + // authorisation code and return it + + $authCode = $this->newAuthCode($authoriseParams['client_id'], + 'user', $typeId, $authoriseParams['redirect_uri'], + $authoriseParams['scopes'], $accessToken); + + return $authCode; + } + + else + { + $authCode = $this->newAuthCode($authoriseParams['client_id'], + 'user', $typeId, $authoriseParams['redirect_uri'], + $authoriseParams['scopes']); + + return $authCode; + } + } + /** * Generates a unique code *