Configura l'autenticazione Salesforce usando il plugin di supporto base OAuth2

Utilizzando il plugin OAuth2 Basic Support (incluso nel nucleo di Discourse dalla versione v2025.11.0), è possibile configurare l’autenticazione Salesforce.

Per farlo, crea un’app OAuth2 connessa su Salesforce:

  • Crea → App → Nuova app connessa

  • Assicurati di consentire l’accesso a “accesso alle informazioni di base”

  • Imposta l’URL di callback su https://TUOFORUM.COM/auth/oauth2_basic/callback: Nota che il forum Discourse deve essere eseguito con HTTPS.

  • Prendi nota dell’ID client e della chiave segreta

Sul lato Discourse, configura le seguenti impostazioni (trovabili in Amministratore > Accesso > OAuth2.0):

  • oauth2 abilitato: true
  • oauth2 client id e secret, come indicato nella sezione precedente
  • oauth2 authorize url: https://login.salesforce.com/services/oauth2/authorize
  • oauth2 token url: https://login.salesforce.com/services/oauth2/token
  • oauth2 fetch user details: true (questo è il valore predefinito, ma assicurati che sia abilitato)
  • oauth2 user json url: https://login.salesforce.com/services/oauth2/userinfo
  • oauth2 json user id path: user_id
  • oauth2 json username path: preferred_username
  • oauth2 json name path: name
  • oauth2 json email path: email
  • oauth2 email verified: true
  • oauth2 authorize options: scope, display, immediate, state

Se riscontri problemi, assicurati di abilitare oauth2 debug auth e controlla i tuoi /logs.

9 Mi Piace

Thanks for this post, which was invaluable in setting up a recent project, which required Salesforce login.

In our case, the Salesforce app was a Community, which meant we had to change some of the details above. I’m posting on this old thread in case it helps anyone else. It nearly broke my brain for a whole day.

  • oauth2 authorize url: https://[COMMUNITY_NAME].force.com/services/oauth2/authorize
  • oauth2 token url: https://[COMMUNITY_NAME].force.com/services/oauth2/token
  • oauth2 callback user id path: id

The path changes were worked out gradually (and painfully) from Salesforce and other documentation:
https://auth0.com/docs/connections/social/salesforce
Help And Training Community

However we still had problems with 403 Forbidden errors, which were plain unstyled HTML and didn’t look very much like a Discourse error to me, which led to much debugging of Salesforce and gnashing of teeth. But the problem was in Discourse.

Forbidden

You don’t have permission to access this resource.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

Although the redirect to Callback URL seemed to be working, the browser console registered authentication failures. In the end it was the unset oauth2 callback user id path which was the cause of the authentication failure. Setting it to id fixed everything.

All other settings as in previous post.

2 Mi Piace

Grazie per le linee guida. Siamo riusciti ad autenticarci con successo tramite Salesforce, ma abbiamo riscontrato un problema. Sembra che i nostri oggetti/campi di SF non vengano trasmessi correttamente a Discourse. Immediatamente dopo un login riuscito in SF su Discourse, quest’ultimo sembra trattarlo come un nuovo utente e richiede nome utente, email e nome, anche se questi dovrebbero provenire dai campi name, email e username del JSON OAuth2.

Possiamo chiedere aiuto per conoscere il formato JSON degli oggetti/campi di SF utilizzati nel plugin OAuth2? Abbiamo provato object.field, object_field e semplicemente field. Non sembra generare errori, ma nulla viene comunque trasmesso da SF a Discourse tramite JSON per riconoscere il login come non un nuovo utente di Discourse.

Solo un aggiornamento: abbiamo trovato una soluzione al nostro problema, configurando queste impostazioni sul nostro lato per mappare i campi di Salesforce.

È necessario impostare quanto segue:

### oauth2 fetch user details - **spuntato**
### oauth2 user json url - **https://<yoursfsite.com>/services/oauth2/userinfo**
### oauth2 user json url method - **get**
### oauth2 json user id path - **user_id**
### oauth2 json username path - **preferred_username**
### oauth2 json name path - **name**
### oauth2 json email path - **email**

Speriamo che questo aiuti altri che cercano una soluzione per la connessione oauth2 a Salesforce.

2 Mi Piace

Grazie per le informazioni @sonny.mendoza - l’ho integrata nelle istruzioni in cima a questo argomento, così potrà aiutare altre persone in futuro :slight_smile:

3 Mi Piace