Hi , I wrote this SimpleSAMLphp authentication module to be able to use Discourse as an SSO provider within a SimpleSAMLphp installation. I.e. you can use Discourse as an SSO provider for any services that supports SAML or Shibboleth authentication, which is really nice.
That’s great! If you’d like to make the module more visible, you could create a topic about it in our extras category. That category is a directory of all extensions & integrations for Discourse which are not Discourse plugins,
I’m implementing this SSO on an existing web site and I just want to check how people are “presenting” their login method to users.
For example, let’s say my web site at www.example.com has a Login button in the top nav.
Should that login button instantly take people to my discourse login auth page? Or is it preferable to display a page / modal of information first, something like:
I’m just wondering if people will get confused if they’re not told what’s about to happen?
Does anyone have any user experiences or best practices to share?
And thanks too by the way to @techAPJ for the very detailed first post in this thread, I was able to successfully build this in to my ASP.NET web site from scratch following your steps
Is it possible to include a state parameter that gets returned unchanged, like as is done in OAuth? Asp.net core authentication middleware depends on generating a correlation id to prevent CSRF attacks, and I don’t currently have an easy way to include this.
@jessicah I tried this today and yes, it works fine.
' Create a Return URL
Dim strReturnURL As String = "https://www.example.com/authtestRETURNURL.aspx?myownparametershere=surewhynot"
' Generate a random nonce. Save it temporarily so that you can verify it with returned nonce value
Dim strNonce As String = Guid.NewGuid().ToString("N")
' Create a new payload with nonce and return url (where the Discourse will redirect user after verification)
' Payload should look like: nonce=NONCE&return_sso_url=RETURN_URL
Dim strPayload As String = "nonce=" & strNonce & "&return_sso_url=" & strReturnURL
Then on the page which is called back you’ll find this inside your decoded SSO query string:
Multi-site approaches to using discourse-auth-proxy?
Are there any examples or recommendations for using Discourse as SSO provider for multi-site authentication?
It seems like the there are two basic multisite approaches:
Use multiple instances of discourse-auth-proxy, one per site protected.
Use a single instance of discourse-auth-proxy so the payload containing return_sso_url changes based upon the source of the login request.
I think either of these could work, but the issue with these two approaches, is
that you still require logging into each different site.
There is also the risk that something is stored in Postgres that will get overwritten by each login from the different sites. ie: site1.com. site2.com
(I don’t know the details of Discourse auth/PG schema, so I don’t know)
What would be ideal is a way to have login performed once, which gets you logged into all the sites in the multi-site group. ie, site1.com, site2.com, site3.com
Apparently Stackoverflow does this using a combination of localSession storage and Iframes as the main enabler. tech description
But I’d really love to know if someone has implemented any approach to
multisite login using Discourse as the SSO provider.
approach 1: multiple instances of discourse-auth-proxy
approach 2: hacked discourse-auth-proxy affecting return_sso_url in payload.
approach 3: #1 or #2 implemented such that logging in once, means you do not have to login again when moving from site1.com to site2.com
I am tagging you @sam, since you originally authored the Go discourse-auth-proxy program.
The problem is that the return to url will be handle by the urldecode function in PHP(it’s the core workflow in MediaWiki Authentication), and the wpLoginToken value will be unexpected change from 123+\ to 123 \.
Since the provider and the non-provider settings are for opposite use cases—using Discourse to manage users for something else versus using something else to manage users for Discourse—displaying these settings mixed together invites misconfiguration. It would be less confusing if the two provider settings were consecutive and either entirely before or entirely after the non-provider settings.
@techAPJ Can this be used with AWS Cognito? I want to create an app in AWS Amplify for my discourse community and want my app to be authenticated through discourse.
@mdoggydog Obrigado pela atualização recente da extensão MediaWiki DiscourseSsoConsumer. Estávamos quebrando a cabeça sobre o que fazer em relação aos usuários sendo desconectados de nossa wiki sem terem se desconectado do Discourse, e $wgPluggableAuth_EnableAutoLogin definitivamente não era o que queríamos, pois impede o acesso anônimo à wiki. A configuração $wgDiscourseSsoConsumer_AutoRelogin que você adicionou é exatamente o que precisávamos.
Estou tentando usar o exemplo de PHP da postagem original, mas a forma como eles estão armazenando as coisas não faz sentido. Eles estão apenas armazenando valores em um banco de dados SQL com as chaves login e nonce. Se eu quiser usar SQL para armazenar os nonces, como exatamente seria meu banco de dados SQL?
Algumas outras informações que podem ajudar são para que estou usando isso - espero vincular um usuário do Discourse a uma conta do Minecraft gerando um link SSO que está vinculado à sua UUID. Após fazer login com sucesso no Discourse, vou armazenar a UUID e o ID do Discourse deles em uma tabela.
Até agora, consegui fazer o exemplo de PHP funcionar, mas acho que não estou entendendo completamente como eu teria que modificá-lo para funcionar para o meu caso de uso. Idealmente, quero gerar o link através de uma solicitação GET e enviá-lo ao usuário, para que a UUID já esteja associada ao nonce.
Obrigado por esta postagem, pois eu estaria ainda mais perdido sem ela!
Editar: Para nonces, seria melhor armazenar nonces na tabela e procurar por eles? Eu sei que preciso corresponder ao nonce, mas, a menos que eu possa passar informações adicionais na URL de redirecionamento (o que não consegui fazer com sucesso), não tenho certeza de como referenciar o nonce corretamente.
Eu editei parte do valor do parâmetro sso que você forneceu. A menos que alguém conhecesse sua chave secreta, não seria capaz de decodificar o valor, mas ainda assim parecia mais seguro não fornecer o valor completo. Não estará relacionado ao erro 502 que você está recebendo.
Parece um erro de banco de dados. Porque eu tentei o mesmo plugin e configuração em outro site do Discourse, e está funcionando. Como posso corrigir este problema?
Parece que tentar autenticar no discourse-auth-proxy com nomes de usuário ou grupos não ASCII (chinês no meu caso) leva a um erro porque os cookies não podem conter esses caracteres. Esta é a minha correção: (aviso: eu não sou muito familiarizado com golang)
diff --git a/main.go b/main.go
index 1b1dc28..18f8c9e 100644
--- a/main.go
+++ b/main.go
@@ -154,7 +154,12 @@ func redirectIfNoCookie(handler http.Handler, r *http.Request, w http.ResponseWr
var username, groups string
if err == nil && cookie != nil {
- username, groups, err = parseCookie(cookie.Value, config.CookieSecret)
+ var value string
+ value, err = url.QueryUnescape(cookie.Value)
+ if err != nil {
+ return
+ }
+ username, groups, err = parseCookie(value, config.CookieSecret)
}
if err == nil {
@@ -224,7 +229,7 @@ func redirectIfNoCookie(handler http.Handler, r *http.Request, w http.ResponseWr
cookieData := strings.Join([]string{username, strings.Join(groups, "|")}, ",")
http.SetCookie(w, &http.Cookie{
Name: cookieName,
- Value: signCookie(cookieData, config.CookieSecret),
+ Value: url.QueryEscape(signCookie(cookieData, config.CookieSecret)),
Expires: expiration,
HttpOnly: true,
Path: "/",