Skip to content

Commit 291a30f

Browse files
committed
Clean up OAuthController and finishAuthorization
1 parent b651573 commit 291a30f

File tree

2 files changed

+17
-40
lines changed

2 files changed

+17
-40
lines changed

Classes/Controller/OAuthController.php

Lines changed: 15 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,8 @@ public function initializeObject(): void
3232
* @param Uri $returnToUri
3333
* @param string $serviceType
3434
* @param string $serviceName
35-
* @throws OAuthClientException
36-
* @throws \Doctrine\ORM\ORMException
37-
* @throws \Doctrine\ORM\OptimisticLockException
38-
* @throws \Doctrine\ORM\TransactionRequiredException
39-
* @throws \Neos\Flow\Mvc\Exception\StopActionException
40-
* @throws \Neos\Flow\Mvc\Exception\UnsupportedRequestTypeException
35+
* @throws
36+
* FIXME: Re-Implement
4137
*/
4238
public function startAuthorizationAction(string $clientId, string $clientSecret, Uri $returnToUri, string $serviceType, string $serviceName): void
4339
{
@@ -54,44 +50,26 @@ public function startAuthorizationAction(string $clientId, string $clientSecret,
5450
/**
5551
* Finish OAuth2 authorization
5652
*
57-
* @param string $code
58-
* @param string $state
59-
* @param string $serviceType
60-
* @param string $serviceName
61-
* @param string $scope
53+
* This action passes the given state and code to the OAuth client in order to finish an authorization in progress.
54+
* If the authorization could be finished successfully, the action will redirect to the return URI which was specified
55+
* while starting the authorization.
56+
*
57+
* @param string $serviceType The OAuth service type, ie. the type identifying the package / class implementing OAuth
58+
* @param string $serviceName The OAuth service name, ie. the identifier of the concrete configuration of the given OAuth service implementation
59+
* @param string $state The state by which the OAuth client can find the authorization in progress
60+
* @param string $code The code issued by the OAuth server
6261
* @throws
6362
*/
64-
public function finishAuthorizationAction(string $code, string $state, string $serviceType, string $serviceName, string $scope = ''): void
63+
public function finishAuthorizationAction(string $serviceType, string $serviceName, string $state, string $code): void
6564
{
6665
if (!isset($this->serviceTypes[$serviceType])) {
6766
throw new OAuthClientException(sprintf('OAuth: Failed finishing OAuth2 authorization because the given service type "%s" is unknown.', $serviceName), 1511193117184);
6867
}
69-
7068
$client = new $this->serviceTypes[$serviceType]($serviceName);
71-
assert($client instanceof OAuthClient);
72-
73-
$returnToUri = $client->finishAuthorization($code, $state, $scope);
74-
$this->redirectToUri($returnToUri);
75-
}
76-
77-
/**
78-
* Refresh OAuth2 authorization
79-
*
80-
* @param string $clientId
81-
* @param string $returnToUri
82-
* @param string $serviceName
83-
* @throws
84-
*/
85-
public function refreshAuthorizationAction(string $clientId, string $returnToUri, string $serviceName): void
86-
{
87-
// if (!isset($this->serviceTypes[$serviceName])) {
88-
// throw new OAuthClientException('Unknown client service.', 1511193121713);
89-
// }
90-
//
91-
// /** @var $client OAuthClient * */
92-
// $client = new $this->serviceTypes[$serviceName];
93-
// $authorizeUri = $client->refreshAuthorization($clientId, $returnToUri);
94-
// $this->redirectToUri($authorizeUri);
69+
if (!$client instanceof OAuthClient) {
70+
throw new OAuthClientException(sprintf('OAuth: Failed finishing authorization because of unexpected class type: "%s" must implement %s.', get_class($client), OAuthClient::class), 1568735389);
71+
}
72+
$this->redirectToUri($client->finishAuthorization($state, $code));
9573
}
9674

9775
/**

Classes/OAuthClient.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,16 +284,15 @@ public function startAuthorization(string $clientId, string $clientSecret, Uri $
284284
/**
285285
* Finish an OAuth authorization with the Authorization Code flow
286286
*
287-
* @param string $code The authorization code given by the OAuth server
288287
* @param string $stateIdentifier The state identifier, passed back by the OAuth server as the "state" parameter
289-
* @param string $scope The scope for the granted authorization (syntax varies depending on the service)
288+
* @param string $code The authorization code given by the OAuth server
290289
* @return Uri The URI to return to
291290
* @throws OAuthClientException
292291
* @throws ORMException
293292
* @throws OptimisticLockException
294293
* @throws TransactionRequiredException
295294
*/
296-
public function finishAuthorization(string $code, string $stateIdentifier, string $scope): Uri
295+
public function finishAuthorization(string $stateIdentifier, string $code): Uri
297296
{
298297
$stateFromCache = $this->stateCache->get($stateIdentifier);
299298
if (empty($stateFromCache)) {

0 commit comments

Comments
 (0)