Authentication using 3rd Party (custom) Logic

AI-generated summary

Jose_C_Gomez is developing a Discourse plugin to enable authentication via custom logic—such as PINs or one-time tokens—rather than traditional username/password. As a Discourse development beginner, they seek examples or guidance on implementing this, ideally mirroring the experience of adding third-party accounts (e.g., Google, Facebook), with a 1:1 mapping between Discourse users and their custom tokens. polarathene suggests considering external identity services like Keycloak, which supports OTP and integrates with Discourse via standard protocols like OpenID Connect. They ask whether the custom auth should link to existing accounts or support anonymous access, noting Keycloak’s flexibility—even if it may not simplify development.

I’m trying to write a plugin that will allow you to login to discourse with some “custom” logic
No username and password, maybe a Pin Number or a One Time Token you generate.
I am willing to write the logic etc, but I’m new to Discourse Development so I’m trying to understand if that’s possible.

I’ve looked at all/most of the Authentication plugins available and most of them just use some off the shelf Gem and 10-20 lines of code to make ti work.
Which is great, however in my case I need completely custom logic.

Just wondering if there’s anything out there I can use as an example say username / password auth or something of the sort.
Or of anyone can point me in the right direction.

The goal was to leverage the same functionality as you get when you add other accounts (Google, Facebook etc)
Just add another “related” account that you can Auth Against. 1 to 1 relationship between Discourse user and my “Token” (If that helps)

This is a learning exercise I have a very active discourse community and I would love to be able to contribute

Thanks!

Perhaps you can use a service that provides the type of authentication you’re after, but talks to Discourse with a standard protocol?(Like OpenID Connect?)

Is this alternative method meant to be related to existing user accounts, or is it some form of anonymous authorized login? If it’s linked to an existing account, then you might like to use an external identity service like Keycloak? AFAIK it can support OTP(One Time Password) and a variety of other methods. Might not be easier though.