محاولة إنشاء حسابات تلقائيًا عند استخدام مكون إضافي SAML

مواصلة النقاش من إضافة SAML في المستودع. متعدد المواقع:

أحاول استخدام الكود التالي في إضافة SAML لإنشاء حساب تلقائيًا بعد مصادقة المستخدم بنجاح، بحيث لا يُعرض على المستخدمين نافذة تسجيل الدخول التي قد يُغيرون فيها بريدهم الإلكتروني أو اسم المستخدم أو اسمهم. أفضل أن لا يكون للمستخدمين سيطرة على هذه الإعدادات، بل يتم تعيينها تلقائيًا بناءً على مصادقة SAML.

يحتوي ملف app.yml الخاص بي على:

  ...
  # فرض سمة fullName من تأكيد SAML لتجاوز سمة name بحيث
  # يتم تعيين الاسم الكامل للمستخدم إلى حقل الاسم في Discourse، مما يساعد
  # على تعزيز حقل اسم المستخدم الرقمي في المنشورات.
  DISCOURSE_SAML_ATTRIBUTE_STATEMENTS: "name:fullName"

  DISCOURSE_SAML_AUTO_CREATE_ACCOUNT: true
  ...

عند اختبار هذه الميزة، أرى الخطأ التالي في السجلات:

Completed 500 Internal Server Error in 175ms (ActiveRecord: 0.0ms)
ActiveRecord::NotNullViolation (PG::NotNullViolation: ERROR:  null value in column "uid" violates not-null constraint
DETAIL:  Failing row contains (2, 3, null, saml, user@company.com, Smith, John, 2019-06-03 21:40:55.44066, 2019-06-03 21:40:55.44066).
: INSERT INTO "oauth2_user_infos" ("user_id", "provider", "email", "name", "created_at", "updated_at") VALUES (3, 'saml', 'user@company.com', 'Smith, John', '2019-06-03 21:40:55.440660', '2019-06-03 21:40:55.440660') RETURNING "id")
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rack-mini-profiler-1.0.2/lib/patches/db/pg.rb:69:in `async_exec_params'
Failed to handle exception in exception app middleware : PG::NotNullViolation: ERROR:  null value in column "uid" violates not-null constraint
DETAIL:  Failing row contains (2, 3, null, saml, user@company.com, Smith, John, 2019-06-03 21:40:55.44066, 2019-06-03 21:40:55.44066).
: INSERT INTO "oauth2_user_infos" ("user_id", "provider", "email", "name", "created_at", "updated_at") VALUES (3, 'saml','user@company.com', 'Smith, John', '2019-06-03 21:40:55.440660', '2019-06-03 21:40:55.440660') RETURNING "id"

هل لديك أي فكرة عما إذا كنت بحاجة إلى تكوين الإضافة لفرض تعيين “uid” عبر إحدى السمات من تأكيد SAML؟

عندما يكون DISCOURSE_SAML_AUTO_CREATE_ACCOUNT مضبوطًا على false أو غير موجود، تعمل المصادقة القائمة على SAML، لكن المستخدم يرى النافذة التي يمكنه من خلالها تعديل بريده الإلكتروني واسم المستخدم واسمه.

Problem has been solved. We had inadvertently had removed from the ADFS IdP configuration the “nameid” from the SAML response. Once we added that back in, the auto create account feature worked fine!

With both the create account option set to true and the other settings shown below in our app.yml, we’re able to avoid having both login dialog windows being displayed. Now new users just click “Login”, authenticate via the IdP and then are put into their new Discourse account all without being able to override username, name and email address in an intervening dialog.

Once a user gets into Discourse, they cannot edit their email address, but we are allowing them to change their username so that they can have a more recognizable “nickname” in @ mentions and such.

  ...
  # Force fullName attribute from SAML assertion to override name attribute so that
  # the user's full name will be mapped to Discourse's Name field and will help
  # augment the numeric User Name field on posts.
  DISCOURSE_SAML_ATTRIBUTE_STATEMENTS: "name:fullName"

  DISCOURSE_SAML_AUTO_CREATE_ACCOUNT: true
  ...
  - exec: rails r "SiteSetting.login_required=true"
  - exec: rails r "SiteSetting.enable_local_logins=false"

  - exec: rails r "SiteSetting.email_editable=false"

  - exec: rails r "SiteSetting.display_name_on_posts=true"
  - exec: rails r "SiteSetting.prioritize_username_in_ux=true"
  ...