spinen/laravel-discourse-sso

Bug: No SSO Route after Installation

JamieBradders opened this issue · 2 comments

Hi there, I have followed the instructions from the README and I'm afraid to say that I can't see the SSO route in the available list of routes - the same issue occurs if I clear the route cache too.

I am trying to install in a Laravel 11 Project with Laravel Jetstream.

After following the guide I get a 404 when attempting to navigate to /discourse/sso. The artisan route:list command lists the following:

  GET|HEAD  / ............................................................... generated::QezdvotXfOs0UY0c
  POST      _ignition/execute-solution ignition.executeSolution › Spatie\LaravelIgnition › ExecuteSoluti…
  GET|HEAD  _ignition/health-check ignition.healthCheck › Spatie\LaravelIgnition › HealthCheckController
  POST      _ignition/update-config ignition.updateConfig › Spatie\LaravelIgnition › UpdateConfigControl…
  GET|HEAD  api/user ........................................................ generated::cgdtJVmQdhBT5fsn
  GET|HEAD  dashboard ......................................................................... dashboard
  GET|HEAD  forgot-password ..... password.request › Laravel\Fortify › PasswordResetLinkController@create
  POST      forgot-password ........ password.email › Laravel\Fortify › PasswordResetLinkController@store
  GET|HEAD  livewire/livewire.js generated::GHPOcWxwNwj6TlXw › Livewire\Mechanisms › FrontendAssets@retu…
  GET|HEAD  livewire/livewire.min.js.map generated::9XHbpXHwm2JZ9I3I › Livewire\Mechanisms › FrontendAss…
  GET|HEAD  livewire/preview-file/{filename} livewire.preview-file › Livewire\Features › FilePreviewCont…
  POST      livewire/update ......... livewire.update › Livewire\Mechanisms › HandleRequests@handleUpdate
  POST      livewire/upload-file . livewire.upload-file › Livewire\Features › FileUploadController@handle
  GET|HEAD  login ....................... login › Laravel\Fortify › AuthenticatedSessionController@create
  POST      login .. generated::6LUmjUsTIEjp4m8a › Laravel\Fortify › AuthenticatedSessionController@store
  POST      logout .................... logout › Laravel\Fortify › AuthenticatedSessionController@destroy
  GET|HEAD  register ....................... register › Laravel\Fortify › RegisteredUserController@create
  POST      register ..... generated::LaoFnGgK22srynpP › Laravel\Fortify › RegisteredUserController@store
  POST      reset-password .............. password.update › Laravel\Fortify › NewPasswordController@store
  GET|HEAD  reset-password/{token} ...... password.reset › Laravel\Fortify › NewPasswordController@create
  GET|HEAD  sanctum/csrf-cookie ....... sanctum.csrf-cookie › Laravel\Sanctum › CsrfCookieController@show
  GET|HEAD  two-factor-challenge two-factor.login › Laravel\Fortify › TwoFactorAuthenticatedSessionContr…
  POST      two-factor-challenge generated::UNYPJXQyuzFLodV4 › Laravel\Fortify › TwoFactorAuthenticatedS…
  GET|HEAD  up .............................................................. generated::JBkvPZDfz1FSukoO
  GET|HEAD  user/confirm-password generated::4UsAH4mCykdiEGdt › Laravel\Fortify › ConfirmablePasswordCon…
  POST      user/confirm-password password.confirm › Laravel\Fortify › ConfirmablePasswordController@sto…
  GET|HEAD  user/confirmed-password-status password.confirmation › Laravel\Fortify › ConfirmedPasswordSt…
  POST      user/confirmed-two-factor-authentication two-factor.confirm › Laravel\Fortify › ConfirmedTwo…
  PUT       user/password ............ user-password.update › Laravel\Fortify › PasswordController@update
  GET|HEAD  user/profile .................. profile.show › Laravel\Jetstream › UserProfileController@show
  PUT       user/profile-information user-profile-information.update › Laravel\Fortify › ProfileInformat…
  POST      user/two-factor-authentication two-factor.enable › Laravel\Fortify › TwoFactorAuthentication…
  DELETE    user/two-factor-authentication two-factor.disable › Laravel\Fortify › TwoFactorAuthenticatio…
  GET|HEAD  user/two-factor-qr-code two-factor.qr-code › Laravel\Fortify › TwoFactorQrCodeController@show
  GET|HEAD  user/two-factor-recovery-codes two-factor.recovery-codes › Laravel\Fortify › RecoveryCodeCon…
  POST      user/two-factor-recovery-codes generated::8hvxXJmnC4rvolSR › Laravel\Fortify › RecoveryCodeC…
  GET|HEAD  user/two-factor-secret-key two-factor.secret-key › Laravel\Fortify › TwoFactorSecretKeyCont

I also see a 404 when attempting to open the Discourse instance after applying the settings to enable SSO. I'm being redirected to http://localhost/discourse/sso?sso=bm9uY2U9ZjI0MmIzZjUzNWNiM2QwN2FhN2ZmYTczZWFmNWZjNmEmcmV0dXJuX3Nzb191cmw9aHR0cCUzQSUyRiUyRmxvY2FsaG9zdCUzQTMwMDAlMkZzZXNzaW9uJTJGc3NvX2xvZ2lu&sig=374fbc2b279cf748779bc9f6bdc2a21f27f6d17b6be9bcff44dcc7e621241862 - the 404 here also suggesting the SSO route has not been registered.

Below is my services config, as far as I can tell I have configured this correctly:

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Third Party Services
    |--------------------------------------------------------------------------
    |
    | This file is for storing the credentials for third party services such
    | as Mailgun, Postmark, AWS and more. This file provides the de facto
    | location for this type of information, allowing packages to have
    | a conventional file to locate the various service credentials.
    |
    */

    'postmark' => [
        'token' => env('POSTMARK_TOKEN'),
    ],

    'ses' => [
        'key' => env('AWS_ACCESS_KEY_ID'),
        'secret' => env('AWS_SECRET_ACCESS_KEY'),
        'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
    ],

    'slack' => [
        'notifications' => [
            'bot_user_oauth_token' => env('SLACK_BOT_USER_OAUTH_TOKEN'),
            'channel' => env('SLACK_BOT_USER_DEFAULT_CHANNEL'),
        ],
    ],

    'discourse' => [
        // Middleware for the SSO login route to use
        'middleware' => ['web', 'auth'],

        // The route's URI that acts as the entry point for Discourse to start the SSO process.
        // Used by Discourse to route incoming logins.
        'route' => 'discourse/sso',

        // Optional domain to link sso route when using SSubdomain Routing
        'domain' => null,

        // Secret string used to encrypt/decrypt SSO information,
        // be sure that it is 10 chars or longer
        'secret' => env('DISCOURSE_SECRET'),

        // Disable Discourse from sending welcome message
        'suppress_welcome_message' => 'true',

        // Where the Discourse forum lives
        'url' => env('DISCOURSE_URL'),

        // Api-specific items
        // For logging out of Discourse directly, generate an API key as an "All user key" and put the key & user here.
        // @see https://meta.discourse.org/t/how-to-create-an-api-key-on-the-admin-panel/87383
        'api' => [
            'key' => env('DISCOURSE_API_KEY'),
            'user' => env('DISCOURSE_API_USER'),
        ],

        // User-specific items
        // NOTE: The 'email' & 'external_id' are the only 2 required fields
        'user' => [
            // Check to see if the user has forum access & should be logged in via SSO
            'access' => null,

            // Discourse Groups to make sure that the user is part of in a comma-separated string
            // NOTE: Groups cannot have spaces in their names & must already exist in Discourse
            'add_groups' => null,

            // Boolean for making the user a Discourse admin. Leave null to ignore
            'admin' => null,

            // Full path to user's avatar image
            'avatar_url' => null,

            // The avatar is cached, so this triggers an update
            'avatar_force_update' => false,

            // Content of the user's bio
            'bio' => null,

            // Verified email address (see "require_activation" if not verified)
            'email' => 'email',

            // Unique string for the user that will never change
            'external_id' => 'id',

            // Boolean for making user a Discourse moderator. Leave null to ignore
            'moderator' => null,

            // Full name on Discourse if the user is new or
            // if SiteSetting.sso_overrides_name is set
            'name' => 'name',

            // Discourse Groups to make sure that the user is *NOT* part of in a comma-separated string.
            // NOTE: Groups cannot have spaces in their names & must already exist in Discourse
            // There is not a way to specify the exact list of groups that a user is in, so
            // you may want to send the inverse of the 'add_groups'
            'remove_groups' => null,

            // If the email has not been verified, set this to true
            'require_activation' => false,

            // username on Discourse if the user is new or
            // if SiteSetting.sso_overrides_username is set
            'username' => 'email',
        ],
    ],
];

Based on the README, I'm assuming I don't need to publish anything from the package? I assumed the route would be automatically generated? I couldn't see anything relating to this in an existing issue, but apologies if this has been raised elsewhere and I've missed something.

I have just made a fresh L11 project & installed the packages. All I did was copy/paste the config into config/services.php, which works for me...

sso route

There is not anything else that you need to publish.

I even copied/pasted your Discord config above and pasted it into my services file, and I still see the route (second route list in the screen shoot).

I would suggest making a fresh L11 & only installing this package. Then, add customizations until you find the conflict.

If you can pin/point the issue, please feel free to reopen this issue or open a MR.

Thanks for taking a look and I appreciate the insight. I'll do as you've suggested 👍

Update just to confirm I tried the above and it's worked, route was still there after install Jetstream too. Apologies, in hindsight, I probably should have tried a fresh project before raising the issue.