When an existing Drupal user tries to access the discourse site which is connected with SSO, and a discourse login is not yet created for that user, he is redirected to drupal which shows an unexpected error:

The website encountered an unexpected error. Please try again later.

Drupal\Core\Entity\Exception\UndefinedLinkTemplateException: No link template 'canonical' found for the 'file' entity type in Drupal\Core\Entity\EntityBase->toUrl() (line 196 of core/lib/Drupal/Core/Entity/EntityBase.php).
Drupal\discourse_sso\Controller\DiscourseSsoController->validate() (Line: 85)
Drupal\discourse_sso\Controller\DiscourseSsoController->discourse_sso()
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 158)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 705)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
CommentFileSizeAuthor
#5 3172634-user-picture-url.patch854 bytesdaggerhart

Comments

Yuri created an issue. See original summary.

jurgenhaas’s picture

Are you really testing with the rc5 release? You should rather test with the latest dev to make sure the issue hasn't already been fixed by another issue.

The, the reported problem is around this code in line 115 of DiscourseSsoController.php:

    $picture = ($account->hasField('user_picture') && !$account->get('user_picture')->isEmpty()) ?
      $account->get('user_picture')->entity->toUrl()->toString(TRUE) :
      '';

Looks like the file entity doesn't have a canonical url anymore and we need another way to determine the url which will be passed over to Discourse for the user image.

As I'M not running a Discourse instance myself anymore, this needs to be worked on by someone who does and I'm happy to review patches which are going to resolve the issue.

Yuri’s picture

@jurgenhaas you are right, the error only appears if drupal user account has a profile image. When I remove the profile image from the drupal account, discourse gives the page which says the account is pending approval.

Thats at least a bit of good progress, thanks!

jurgenhaas’s picture

The pending approval is certainly related to #3172534: Login error when SSO is activated

The user image issue needs local debug and a patch, can you provide something for this?

daggerhart’s picture

Status: Active » Needs review
StatusFileSize
new854 bytes

Attached patch should resolve the issue.

daggerhart’s picture

Title: Unexpected error when existing Drupal user tries to access the dicourse site » User picture URL creation fails causing fatal error
Issue summary: View changes
shenron_segamag’s picture

Hi,

The patch works fine for me.

Thanks !

  • jurgenhaas committed 1f2ff2f on 2.0.x
    Issue #3172634 by daggerhart, Yuri, jurgenhaas, Shenron_segamag: User...
jurgenhaas’s picture

Version: 2.0.0-rc5 » 2.0.x-dev
Status: Needs review » Fixed

Thanks everybody, committed the patch to the dev branch.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.