Skip to content

Commit 7d08e36

Browse files
committed
Allow to start authorization code flow with a given identifier
This complements the metadata feature, since it allows to create an identifier for use with the authorization code flow as well as setting metadata on the authorization being handled.
1 parent 7945c0f commit 7d08e36

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

Classes/OAuthClient.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,18 @@ public function requestAccessToken(string $serviceName, string $clientId, string
248248
$this->entityManager->flush();
249249
}
250250

251+
/**
252+
* Returns an authorization id taking the service type and service name into account.
253+
*
254+
* @param string $clientId
255+
* @return string
256+
* @throws OAuthClientException
257+
*/
258+
public function generateAuthorizationIdForAuthorizationCodeGrant(string $clientId)
259+
{
260+
return Authorization::generateAuthorizationIdForAuthorizationCodeGrant($this->getServiceType(), $this->getServiceName(), $clientId);
261+
}
262+
251263
/**
252264
* Start OAuth authorization with the Authorization Code flow
253265
*
@@ -260,7 +272,22 @@ public function requestAccessToken(string $serviceName, string $clientId, string
260272
*/
261273
public function startAuthorization(string $clientId, string $clientSecret, UriInterface $returnToUri, string $scope): UriInterface
262274
{
263-
$authorizationId = Authorization::generateAuthorizationIdForAuthorizationCodeGrant($this->getServiceType(), $this->getServiceName(), $clientId);
275+
$authorizationId = $this->generateAuthorizationIdForAuthorizationCodeGrant($clientId);
276+
return $this->startAuthorizationWithId($authorizationId, $clientId, $clientSecret, $returnToUri, $scope);
277+
}
278+
279+
/**
280+
* Start OAuth authorization with the Authorization Code flow
281+
*
282+
* @param string $clientId The client id, as provided by the OAuth server
283+
* @param string $clientSecret The client secret, provided by the OAuth server
284+
* @param UriInterface $returnToUri URI to return to when authorization is finished
285+
* @param string $scope Scope to request for authorization. Must be scope ids separated by space, e.g. "openid profile email"
286+
* @return UriInterface The URL the browser should redirect to, asking the user to authorize
287+
* @throws OAuthClientException
288+
*/
289+
public function startAuthorizationWithId(string $authorizationId, string $clientId, string $clientSecret, UriInterface $returnToUri, string $scope): UriInterface
290+
{
264291
$authorization = new Authorization($authorizationId, $this->getServiceType(), $clientId, Authorization::GRANT_AUTHORIZATION_CODE, $scope);
265292
$this->logger->info(sprintf('OAuth (%s): Starting authorization %s using client id "%s", a %s bytes long secret and scope "%s".', $this->getServiceType(), $authorization->getAuthorizationId(), $clientId, strlen($clientSecret), $scope));
266293

0 commit comments

Comments
 (0)