44
55use Doctrine \Common \Persistence \ObjectManager as DoctrineObjectManager ;
66use Doctrine \ORM \EntityManager as DoctrineEntityManager ;
7+ use Doctrine \ORM \OptimisticLockException ;
8+ use Doctrine \ORM \ORMException ;
9+ use Doctrine \ORM \TransactionRequiredException ;
710use GuzzleHttp \Client ;
11+ use GuzzleHttp \Exception \GuzzleException ;
812use GuzzleHttp \Psr7 \Response ;
913use League \OAuth2 \Client \Provider \Exception \IdentityProviderException ;
1014use League \OAuth2 \Client \Provider \GenericProvider ;
1721use Neos \Flow \Http \Uri ;
1822use Neos \Flow \Log \SystemLoggerInterface ;
1923use Neos \Flow \Mvc \ActionRequest ;
24+ use Neos \Flow \Mvc \Routing \Exception \MissingActionNameException ;
2025use Neos \Flow \Mvc \Routing \UriBuilder ;
21- use Neos \Flow \Persistence \ Doctrine \ Query ;
26+ use Neos \Flow \Session \ Exception \ SessionNotStartedException ;
2227use Neos \Flow \Session \SessionInterface ;
2328
2429abstract class OAuthClient
@@ -67,7 +72,7 @@ abstract class OAuthClient
6772 * @param DoctrineObjectManager $entityManager
6873 * @return void
6974 */
70- public function injectEntityManager (DoctrineObjectManager $ entityManager )
75+ public function injectEntityManager (DoctrineObjectManager $ entityManager ): void
7176 {
7277 $ this ->entityManager = $ entityManager ;
7378 }
@@ -77,7 +82,7 @@ public function injectEntityManager(DoctrineObjectManager $entityManager)
7782 *
7883 * @return string For example, "FlownativeBeach", "Paypal", "Stripe", "Twitter"
7984 */
80- abstract static public function getServiceName (): string ;
85+ abstract public static function getServiceName (): string ;
8186
8287 /**
8388 * Returns the OAuth server's base URI
@@ -145,9 +150,12 @@ public function getRequestFactory(): RequestFactory
145150 * @param string $clientId
146151 * @param string $clientSecret
147152 * @param string $scope
153+ * @return void
148154 * @throws IdentityProviderException
155+ * @throws ORMException
156+ * @throws OptimisticLockException
149157 */
150- public function addClientCredentials (string $ clientId , string $ clientSecret , string $ scope = '' )
158+ public function addClientCredentials (string $ clientId , string $ clientSecret , string $ scope = '' ): void
151159 {
152160 $ oAuthProvider = $ this ->createOAuthProvider ($ clientId , $ clientSecret );
153161
@@ -181,8 +189,11 @@ public function addClientCredentials(string $clientId, string $clientSecret, str
181189 * @param string $clientSecret The client secret, provided by the OAuth server
182190 * @param string $returnToUri URI to return to when authorization is finished
183191 * @return string The URL the browser should redirect to, asking the user to authorize
192+ * @throws ORMException
193+ * @throws OptimisticLockException
194+ * @throws SessionNotStartedException
184195 */
185- public function startAuthorization (string $ clientId , string $ clientSecret , string $ returnToUri )
196+ public function startAuthorization (string $ clientId , string $ clientSecret , string $ returnToUri ): string
186197 {
187198 $ oAuthProvider = $ this ->createOAuthProvider ($ clientId , $ clientSecret );
188199 $ authorizationUri = $ oAuthProvider ->getAuthorizationUrl ();
@@ -213,8 +224,12 @@ public function startAuthorization(string $clientId, string $clientSecret, strin
213224 * @param string $scope The scope for the granted authorization (syntax varies depending on the service)
214225 * @return string The URI to return to
215226 * @throws OAuthClientException
227+ * @throws ORMException
228+ * @throws OptimisticLockException
229+ * @throws SessionNotStartedException
230+ * @throws TransactionRequiredException
216231 */
217- public function finishAuthorization (string $ code , string $ state , string $ scope )
232+ public function finishAuthorization (string $ code , string $ state , string $ scope ): string
218233 {
219234 $ stateFromSession = $ this ->session ->getData (static ::getServiceName () . '.oAuthState ' );
220235 if (empty ($ state ) || $ stateFromSession !== $ state ) {
@@ -256,8 +271,10 @@ public function finishAuthorization(string $code, string $state, string $scope)
256271 * @param string $clientId
257272 * @param string $returnToUri
258273 * @return string
259- * @throws IdentityProviderException
260274 * @throws OAuthClientException
275+ * @throws ORMException
276+ * @throws OptimisticLockException
277+ * @throws TransactionRequiredException
261278 */
262279 public function refreshAuthorization (string $ clientId , string $ returnToUri ): string
263280 {
@@ -287,6 +304,9 @@ public function refreshAuthorization(string $clientId, string $returnToUri): str
287304
288305 /**
289306 * @return OAuthToken|null
307+ * @throws ORMException
308+ * @throws OptimisticLockException
309+ * @throws TransactionRequiredException
290310 */
291311 public function getOAuthToken (): ?OAuthToken
292312 {
@@ -301,9 +321,13 @@ public function getOAuthToken(): ?OAuthToken
301321 * @param string $method The HTTP method, for example "GET" or "POST"
302322 * @param array $bodyFields Associative array of body fields to send (optional)
303323 * @return \Psr\Http\Message\RequestInterface
324+ * @throws IdentityProviderException
304325 * @throws OAuthClientException
326+ * @throws ORMException
327+ * @throws OptimisticLockException
328+ * @throws TransactionRequiredException
305329 */
306- public function getAuthenticatedRequest (string $ relativeUri , string $ method = 'GET ' , array $ bodyFields = [])
330+ public function getAuthenticatedRequest (string $ relativeUri , string $ method = 'GET ' , array $ bodyFields = []): \ Psr \ Http \ Message \ RequestInterface
307331 {
308332 $ oAuthToken = $ this ->getOAuthToken ();
309333 if (!$ oAuthToken instanceof OAuthToken) {
@@ -357,6 +381,12 @@ public function getAuthenticatedRequest(string $relativeUri, string $method = 'G
357381 * @param string $method
358382 * @param array $bodyFields
359383 * @return Response
384+ * @throws IdentityProviderException
385+ * @throws OAuthClientException
386+ * @throws ORMException
387+ * @throws OptimisticLockException
388+ * @throws TransactionRequiredException
389+ * @throws GuzzleException
360390 */
361391 public function sendAuthenticatedRequest (string $ relativeUri , string $ method = 'GET ' , array $ bodyFields = []): Response
362392 {
@@ -385,7 +415,11 @@ public function renderRedirectUri(): string
385415 $ this ->uriBuilder ->setRequest ($ actionRequest );
386416 $ this ->uriBuilder ->setCreateAbsoluteUri (true );
387417
388- return $ this ->uriBuilder ->uriFor ('finishAuthorization ' , ['serviceName ' => static ::getServiceName ()], 'OAuth ' , 'Flownative.OAuth2.Client ' );
418+ try {
419+ return $ this ->uriBuilder ->uriFor ('finishAuthorization ' , ['serviceName ' => static ::getServiceName ()], 'OAuth ' , 'Flownative.OAuth2.Client ' );
420+ } catch (MissingActionNameException $ e ) {
421+ return '' ;
422+ }
389423 }
390424
391425 /**
0 commit comments