Disable manual login, and only allow Discord logon

Good evening!

I am currently expanding my development community with Discourse, everything has been setup and is running flawlessly. Now what I want to do might not be easy to accomplish, however I believe it should be possible.

I am currently running with Discord OAuth2 which allows user to register to the site (if they are not a member of my Discord guild their account will be put in pending approval, or otherwise allow instant login if they are.) This part works beautifully, but there’s something I’d like to change if it’s possible of course.

When a user clicks on Discord as logon, if they are not a member they’ll get this message:

Thanks for signing up. We will notify you when your account has been approved

Can this be changed to something custom?

Furthermore, I’d like to know if it’s possible to replace the Login button with a Discord login button.

image

So instead of “Log in” it’ll just be replaced by the Discord button?

Could someone be so kind to provide some guidance on this?

Yes, you can go to admin > customize > site texts and search for the text you’d like to change.

It’s possible with a theme component. This is kind of rough and untested (and I’m pretty sure there’s probably a better way to do it)… but something like this might work? (add to admin > customize > themes > edit CSS/HTML > header)

<script type="text/discourse-plugin" version="0.8.13">
  let currentLocale = I18n.currentLocale(); 
  I18n.translations[currentLocale].js.discord_button = "Log in with Discord";
  
api.reopenWidget("header-buttons", {

  html(attrs) {
    if (this.currentUser) {
      return;
    }
    const buttons = [];

    buttons.push(
        this.attach("link", {
          href: "/auth/discord",
          label: "discord_button",
          className: "btn btn-primary"
        })
    );
    return buttons;
  }
});
</script>
5 Likes

Thanks a lot for this, I will give it a spin once I get off work.

Unfortunately I messed up when I added OAuth2 from Discord, I cannot seem to login manually anymore, it just keeps loading without anything happening on the logon screen, and my company blocks social media so the Discord logon will just throw an bluecoat exception. (If anyone has tips on why it just keeps loading on the logon screen with normal logon please do advise).

I’ll report back once I’ve had the chance to play with this :slight_smile:

You can use the admin backdoor by going to https://example.com/u/admin-login :wink:

1 Like

Thanks for the suggestion, I have tried, and I receive the link.

However when using it I get: “Unknown email address” which is a bit strange since this is the e-mail on that registered admin account.

Funny thing is before I added the OAuth2 for Discord the text logon was working flawless, after I added OAuth2 it just keeps loading upon pressing “Login” after filling username and password.

But that’s a minor thing for now, I can access fine through OAuth2 when not behind a bluecoat proxy that is blocking things, this is just my companies policies unfortunately nothing I can do about that. :slight_smile:

I could for the time being while being restricted by proxies add Google auth as that isn’t blocked and I should be able to authenticate through that.

Hey, this works awesome!

However, if you click on it you’ll get: Oops! That page doesn’t exist or is private. - Then you can press F5 to refresh then it’ll go to the Discord authentication, any suggestions why that happens?

Hmm, I’m not sure. What I did above is a little bit hacky… it makes a link that visits the /auth/discord URL directly — I think there’s probably a better way to call Discourse’s auth functions instead (which would likely avoid the problem), but it’s a bit beyond my expertise.

2 Likes

No problem, thanks for your kind help on this :slight_smile:

I have noticed that if I disable any other login and only have the Discord oAuth2 logon when clicking on login it will open a popup with the authentication so it seems like it’s native to Discourse, I could adapt the script you provided to just use the normal login function, so it only changes the button text / icon, that should be fairly easy to to do.