إعداد مصادقة Salesforce باستخدام مكون OAuth2 الأساسي

باستخدام إضافة دعم OAuth2 الأساسي (المضمنة في نواة Discourse منذ الإصدار v2025.11.0)، يمكنك إعداد مصادقة Salesforce.

للقيام بذلك، قم بإنشاء تطبيق OAuth2 متصل على Salesforce:

  • إنشاء → Apps → New connected app

  • تأكد من السماح بالوصول إلى “الوصول إلى المعلومات الأساسية”

  • اضبط “عنوان URL للاستدعاء” على https://YOURFORUM.COM/auth/oauth2_basic/callback : ملاحظة: يجب أن تعمل منتدى Discourse الخاص بك عبر HTTPS.

  • دوّن معرف العميل (client id) والسر (secret)

على جانب Discourse، قم بتكوين الإعدادات التالية (الموجودة تحت Admin > Login > OAuth2.0):

  • oauth2 enabled: true
  • oauth2 client id and secret، كما هو موضح في القسم السابق
  • 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 (هذا هو الإعداد الافتراضي، لكن تأكد من تفعيله)
  • 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

إذا كنت تواجه مشكلة، فتأكد من تفعيل oauth2 debug auth وتفحص ملفات السجل في /logs.

9 إعجابات

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)

شكرًا لكم على الإرشادات، وقد تمكنا من المصادقة بنجاح باستخدام Salesforce، لكننا واجهنا مشكلة. يبدو أن كائنات/حقول Salesforce لا تُمرَّر بنجاح إلى Discourse. فبعد تسجيل الدخول الناجح إلى Salesforce على Discourse، يبدو أن Discourse يعامل المستخدم كجديد ويطلب منه اسم المستخدم والبريد الإلكتروني والاسم، رغم أنه ينبغي أن تأتي هذه البيانات من حقول الاسم والبريد الإلكتروني واسم المستخدم في استجابة JSON الخاصة بـ OAuth2.

هل يمكنكم مساعدتنا في معرفة تنسيق JSON المطلوب لكائنات/حقول Salesforce المستخدمة في إضافة OAuth2؟ لقد جربنا الصيغ object.field و object_field و field فقط. ولا يبدو أن هناك أي خطأ يُبلغ عنه، لكن لا شيء يُمرَّر من Salesforce إلى Discourse عبر JSON للتعرف على تسجيل الدخول على أنه ليس مستخدمًا جديدًا في Discourse.

تحديث بسيط هنا: لقد وجدنا حلاً لمشكلتنا، وهذه الإعدادات من جانبنا لربط حقول Salesforce.

يجب إعداد الإعدادات التالية:

### oauth2 fetch user details - **checked**
### 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**

نأمل أن يساعد هذا الآخرين الذين يبحثون عن حل لمشكلة الاتصال بـ OAuth2 مع Salesforce.

إعجابَين (2)

شكرًا لك على المعلومات @sonny.mendoza - لقد دمجتُها في التعليمات في أعلى هذا الموضوع، حتى تساعد الآخرين في المستقبل :slight_smile:

3 إعجابات