Invalid argument for ScopeRepository::scopeFactory()

Created on 12 February 2019, almost 6 years ago
Updated 18 November 2024, 3 days ago

The \Drupal::entityTypeManager()->getStorage('user_role')->load() may return null that will result in error when trying to pass this as the argument to Drupal\simple_oauth\Repositories\ScopeRepository::scopeFactory().

This happens when a user has no roles and the consumer has no scopes selected.

<em class="placeholder">TypeError</em>: Argument 1 passed to Drupal\simple_oauth\Repositories\ScopeRepository::scopeFactory() must implement interface Drupal\user\RoleInterface, null given, called in /var/www/docroot/modules/contrib/simple_oauth/src/Repositories/ScopeRepository.php on line 118 in <em class="placeholder">Drupal\simple_oauth\Repositories\ScopeRepository-&gt;scopeFactory()</em> (line <em class="placeholder">94</em> of <em class="placeholder">modules/contrib/simple_oauth/src/Repositories/ScopeRepository.php</em>). <pre class="backtrace">Drupal\simple_oauth\Repositories\ScopeRepository-&gt;scopeFactory(NULL) (Line: 118)
Drupal\simple_oauth\Repositories\ScopeRepository-&gt;addRoleToScopes(Array, &#039;authenticated&#039;) (Line: 74)
Drupal\simple_oauth\Repositories\ScopeRepository-&gt;finalizeScopes(Array, &#039;password&#039;, Object, &#039;1&#039;) (Line: 56)
League\OAuth2\Server\Grant\PasswordGrant-&gt;respondToAccessTokenRequest(Object, Object, Object) (Line: 187)
League\OAuth2\Server\AuthorizationServer-&gt;respondToAccessTokenRequest(Object, Object) (Line: 67)
Drupal\simple_oauth\Controller\Oauth2Token-&gt;handleToken(Object, Object) (Line: 49)
Drupal\simple_oauth\Controller\Oauth2Token-&gt;token(Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;Drupal\Core\EventSubscriber\{closure}() (Line: 582)
Drupal\Core\Render\Renderer-&gt;executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;Drupal\Core\EventSubscriber\{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel-&gt;handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel-&gt;handle(Object, 1, 1) (Line: 67)
Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap-&gt;handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session-&gt;handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle-&gt;handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache-&gt;pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache-&gt;handle(Object, 1, 1) (Line: 41)
Drupal\jsonapi\StackMiddleware\FormatSetter-&gt;handle(Object, 1, 1) (Line: 49)
Asm89\Stack\Cors-&gt;handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware-&gt;handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware-&gt;handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel-&gt;handle(Object, 1, 1) (Line: 693)
Drupal\Core\DrupalKernel-&gt;handle(Object) (Line: 19)
πŸ› Bug report
Status

Closed: outdated

Version

5.2

Component

Code

Created by

πŸ‡ΊπŸ‡¦Ukraine BR0kEN Dnipro

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024