איך להשתמש ב-Oauth2 עם GitHub

סיכום מבוסס בינה מלאכותית

rommelfs provides a comprehensive guide to resolving OAuth2 integration issues with GitHub in Discourse, specifically addressing the 500 error caused by misconfigured fields. The post lists the required configuration parameters, including the Client ID, Client Secret, and specific URLs for authorization, token retrieval, and user JSON data. It also details the necessary steps to create a new OAuth App on GitHub, emphasizing the importance of setting the correct Authorization callback URL. rommelfs also requests that developers improve error handling for missing mandatory fields like the “OAuth2 user JSON URL,” which currently triggers a database constraint violation. vijayan_mmm adds that they resolved a similar issue by correctly setting the “OAuth2 callback user ID path” field.

לכל האנשים שמתמודדים עם בעיות בהפעלת oauth2 עם GitHub, הנה פתרון.

בעיה: תוסף oauth2 של Discourse מייצר שגיאת 500 כאשר הוא מופעל עם Github והשדות בהגדרות אינם מוגדרים כראוי. מאחר שהמסמכים אינם מפורטים מספיק לגבי מה וכיצד להגדיר, הנה השדות החשובים (וכמה אופציונליים):

OAuth2 client ID מזהה הלקוח מ-GitHub
OAuth2 client secret סוד הלקוח מ-GitHub
OAuth2 authorize URL https[:]//github[.]com/login/oauth/authorize
OAuth2 token URL https[:]//github[.]com/login/oauth/access_token
OAuth2 token URL method POST
OAuth2 user JSON URL https[:]//api.github[.]com/user
OAuth2 user JSON URL method GET
OAuth2 JSON user ID path id
OAuth2 JSON username path login
OAuth2 JSON name path name
OAuth2 JSON email path mail
OAuth2 JSON avatar path avatar_url
OAuth2 send auth header x
OAuth2 send auth body x
OAuth2 allow association change x

לניפוי באגים (רק לצורך בדיקה):
OAuth2 debug auth x

בצד GitHub, אם חסרים לך גם את הפרטים האלה, הנה מה שצריך:
גש ל-https[:]//github[.]com/settings/developers, לחץ על “New OAuth App”
הזן שם אפליקציה (למשל Discourse),
כתובת Home Page
ותוכיח את כתובת ההחזרת הרשאה (https[:]//YOUR.DISCOURSESERV[.]ER/auth/oauth2_basic/callback)
ואל תשכח ללחוץ על עדכון אפליקציה.

זהו. מקווה שזה עוזר!

האם אפשר לבקש מהמהנדסים לבדוק את ההחזרה (שאינה תקינה כי היא ריקה) כאשר ה"OAuth2 user JSON URL" החובה אינו מוגדר? זה גורם לשגיאה ומייצר שגיאת 500.

ActiveRecord::NotNullViolation (PG::NotNullViolation: שגיאה: שווה null בעמודה “provider_uid” בטבלה “user_associated_accounts” מפר את ההגבלה של ה-not-null

סליחה על ההסתרה של הקישורים, הודיעו לי שניתן להוסיף רק 2 קישורים בכל פוסט.

Today i also faced this issue, The error disappeared after i set the correct value for the the “OAuth2 callback user ID path” .

image

"