Skip to content

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:
      • idUserID
      • mail or fallback to userPrincipalNameEmail
      • displayNameName
    • 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