https://login.microsoftonline.com/common/oauth2/v2.0/token When downloading the OneDrive file with the obtained token, it returns 401

dragon 0 Reputation points
2025-12-04T11:06:46.7766667+00:00

https://login.microsoftonline.com/common/oauth2/v2.0/token When downloading the OneDrive file with the obtained token, it returns 401

Microsoft 365 and Office | Development | Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Q&A Assist
    2025-12-04T11:06:57.5766667+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    If you are receiving a 401 Unauthorized error when trying to download a OneDrive file using an access token, it could be due to several reasons:

    1. Token Expiration: Ensure that the access token you are using has not expired. Access tokens typically have a limited lifespan (often around one hour). If it has expired, you will need to obtain a new access token using the refresh token or by re-authenticating.
    2. Insufficient Permissions: The token may not have the necessary permissions to access the OneDrive file. Make sure that the token was obtained with the correct scopes that allow access to the OneDrive API. You may need to check the permissions granted to your application in the Azure portal.
    3. Conditional Access Policies: If your organization has conditional access policies in place, such as requiring multi-factor authentication, this could also lead to a 401 error. Ensure that you meet any such requirements before attempting to access the resource.
    4. Location-Based Policies: If location-based policies are enabled, ensure that your request is coming from an approved network location. If the Graph API does not pass the user's IP address correctly, SharePoint may not recognize the request as coming from a trusted source, leading to a 401 error.

    To troubleshoot, you may want to verify the token's validity, check the permissions associated with it, and ensure compliance with any organizational policies that might affect access.


    References:

    0 comments No comments

  2. Flora-T 7,685 Reputation points Microsoft External Staff Moderator
    2025-12-04T13:51:42.71+00:00

    Hi dragon
    Thank you for reaching out to Microsoft Q&A Forum and sharing your experience.

    A 401 error when downloading a OneDrive file typically indicates an issue with the access token configuration. Please verify: Is your app single-tenant or multi-tenant?

    • For single-tenant apps, please consider using the tenant-specific authority: https://login.microsoftonline.com/{tenantID}/oauth2/v2.0/token
    • And set: scope = https://graph.microsoft.com/.default
    • Validate the JWT via https://jwt.ms: aud = https://graph.microsoft.com (Note: Microsoft is providing this information as a convenience to you. This site is not controlled by Microsoft, and Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please ensure that you fully understand the risks before using any suggestions from the above link).
    • For delegated permissions: scp includes Files.Read, Files.Read.All, or broader like Files.ReadWrite.All.
    • For app-only permissions: roles includes Files.Read.All or Sites.Selected (with granted site-level permission).
    • iss matches your tenant authority: https://sts.windows.net/{tenant-guid}/
    • exp is in the future (token not expired).

    Please let me know how you get on, as your feedback is valuable to the community. 


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.