Closed Zoly closed 4 months ago
The changes to the GithubOAuth
class significantly enhance its ability to retrieve user email addresses from the GitHub API. A new endpoint is introduced, allowing for the retrieval of user emails when not provided in the initial user info request. This ensures that the primary email is always accessible, improving the overall integration within the OAuth workflow.
File | Change Summary |
---|---|
src/Libraries/GithubOAuth.php |
Introduced $API_USER_EMAILS_URL for fetching user emails, modified fetchUserInfoWithToken() to call fetchUserEmailsWithToken() when emails are missing. Added fetchUserEmailsWithToken() to handle email retrieval and getUserPrimaryEmail() to determine the primary email from the list. |
sequenceDiagram
participant User
participant GithubOAuth
participant GitHubAPI
User->>GithubOAuth: Request User Info
GithubOAuth->>GitHubAPI: Fetch user info
GitHubAPI-->>GithubOAuth: Return user info (no email)
GithubOAuth->>GitHubAPI: Fetch user emails
GitHubAPI-->>GithubOAuth: Return user emails
GithubOAuth->>GithubOAuth: Determine primary email
GithubOAuth-->>User: Return user info with email
In the garden of code, where bunnies play,
A new path was forged, brightening the way.
Emails now dance from GitHub's embrace,
Fetching with joy, a swift, happy chase.
With every tweak made, our dreams take flight,
Hopping through data, all feels just right! 🐇✨
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
Is there some other steps I need to make so this PR can reach a resolution?
The /user API returns only the data the user explicitly set as public and null for those he didn't.
If the user did not set the email address public (me for example), the email address being mandatory for the process, the authentication fails returning an error message.
By using the /user/emails API in conjunction, it is possible to retrieve all the email addresses the user set in Github, regardless if they are set public or not, and select one of those (ex: primary one), for the login process to complete successfully.
Summary by CodeRabbit