Skip to content

PR: Fix Onedrive Provider to Use Microsoft Graph API Properly #606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

urashidmalik
Copy link

πŸ“¦ Fix OneDrive Provider to Use Microsoft Graph API

✨ Summary

This PR updates the onedrive provider in goth to use the Microsoft Graph API (https://graph.microsoft.com/v1.0/me) instead of the deprecated Live Connect API (https://apis.live.net/v5.0/me).

It resolves issues where OneDrive OAuth succeeded but fetching user info returned 401 Unauthorized errors.

πŸ“‹ Motivation

  • Microsoft's Live Connect API is deprecated.
  • Microsoft Graph is the official and future-proof API for authentication and user data.
  • Users were unable to fetch their email and basic profile after OAuth login.
  • This change improves compatibility for both Personal Microsoft Accounts and Work/School accounts.

πŸ”₯ Changes

  • Updated endpointProfile to https://graph.microsoft.com/v1.0/me.
  • Modified FetchUser method:
    • Properly sets Authorization: Bearer <access_token> in headers.
    • Parses response fields:
      • id β†’ UserID
      • mail or fallback to userPrincipalName β†’ Email
      • displayName β†’ Name
    • Improved error handling to print HTTP status and body content when failing to fetch profile.
  • No changes required for the existing onedrive_test.go tests (as they test BeginAuth and Session loading only).

πŸ§ͺ Testing

  • βœ… Manually tested full OAuth flow:
    • Authentication redirect.
    • Consent screen.
    • Successful code exchange.
    • Fetching email and profile using Microsoft Graph API.
  • βœ… Tested with:
    • Microsoft personal accounts (e.g., Outlook, Hotmail).
    • Azure Active Directory accounts (Office 365/Work accounts).

πŸš€ Notes

  • No API breaking changes for existing users of the goth library.
  • Only affects onedrive provider.
  • Future unit tests can be added to cover the FetchUser parsing more deeply if needed.

πŸ›‘οΈ This ensures full compatibility with Microsoft's current API standards for authentication and user data access.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant