Forum Discussion

jake_BIV's avatar
jake_BIV
Helper I
1 year ago
Solved

Timeout getting Auth Token from MS Graph or PBI API

I have an issue that I need some help on. I am working with Microsoft support, but they are striking out so far. I am hoping someone has some more info that I can provide them. Here is the situation:

BACKGROUND

  • I have multiple M-script Power Query that runs in Gen 1 and Gen 2 dataflows. It gets the Auth Token from Microsoft Graph and POwer BI APIs.
  • The code runs across multiple tenants and each has been running for 1+ years with no issue.
  • On 1/9/2024, all of the scheduled queries (across all tenants) failed on refresh and have been broken since.
  • The script below currently works fine in Power BI Desktop, and Postman will return a token using the same Client/Secret so I know that works.
  • When I go into the Power Query Editor in PBI service and try to refresh the query to generate the token, it just times out after 10 mins. 

 

ERROR MESSAGE:
Error Code: Mashup Exception Data Source Error, Error Details: Couldn't refresh the entity because of an issue with the mashup document MashupException.Error: DataSource.Error: The operation has timed out Details: Reason = DataSource.Error;Detail = https://login.microsoftonline.com/***************/oauth2/token;Microsoft.Data.Mashup.Error.Context = User (Request ID: 939c7c09-215d-4f87-afb2-f15f1655502f).

 

M-Script:

let
  TokenUri = "https://login.microsoftonline.com/" & TenantID & "/oauth2/token",
  ResourceId = "https://graph.microsoft.com",
  TokenResponse = Json.Document(Web.Contents(TokenUri,
  [
  Content = Text.ToBinary(Uri.BuildQueryString([client_id = AppID, resource = ResourceId, grant_type = "client_credentials", client_secret = Secret])),
  Headers = [Accept = "application/json"], ManualStatusHandling = {400}
        ]
    )),
  AzureAccessToken = TokenResponse[access_token]
in
  AzureAccessToken

 

  • jake_BIV's avatar
    jake_BIV
    1 year ago

    Yes. The issue seems to have gone away about 3 days ago across all tenants at the same time.  First level support doest seem to know much.  I'm happy it's fixed but a little disappointed in the lack of understanding and communication. 

18 Replies

  • Hi jake_BIV ,

     

    My recommendation will be getting tenant id, client id,client secret from your organisations AD team, with this details you can create one function to generate access token and you can pass it through your m-query.I'm doing the same to pull data from MS graph.

     

    I hope it will be helpful.

     

    Thanks,

    Sai Teja 

    • jake_BIV's avatar
      jake_BIV
      Helper I

      SaiTejaTalasila 

      That is what this query was doing. It was generating the token (from the Tenant, Client, Secret parameters), then passing to the next query. 

      The problem is that its not generating an access token.  Do you have an example of the m-code function you are using to generate the token? Is it working in Power BI Service? Is it different than the M-Script I provided?

      • SaiTejaTalasila's avatar
        SaiTejaTalasila
        Super User

        Hi jake_BIV ,

         

        Try this -

        -Disable load for all parameters (right click and disable load). Don't disable it for access token function query.

        -authentication type- anonymous and privacy -public.

         

        I hope it works. If it's not working you can reach out to me directly and I will be able share how I defined parameters and created the function to generate access token.

         

         

        Thanks,

        Sai Teja 

         

  • Hi jake_BIV ,

     

    This one’s been a pain point for a lot of folks, so here’s a condensed troubleshooting list that’s helped me (and others) get past MS Graph/PBI API token timeouts in Power BI Service:

     

    1. Use the latest v2.0 endpoint: Update your token request to https://login.microsoftonline.com/<tenant>/oauth2/v2.0/token (the v2 endpoint has fixed some recent issues for many people).

     

    2. Test outside Power BI Service: Try the exact same call in Postman or curl. If it works there but not in Power BI Service, the problem is likely with the Power BI Service environment or some tenant setting not your script.

     

    3. Double-check Azure permissions and secrets: Make sure your Azure AD app registration has the right permissions, and that your client secret hasn’t expired or been rotated. Also, review any Conditional Access Policies your org may have added.

     

    4. If using an On-prem Gateway, update it: Outdated gateways can break cloud authentication flows.


    5. In Power Query, disable load on helper queries: Right-click and disable load on your authentication/token steps, so they aren’t treated as tables.

     

    6. Enable diagnostics/logging: Turn on Power BI logging (under options > diagnostics). Sometimes the logs will
    give you a clue especially if there’s a subtle permissions or network issue.


    7. Escalate with Microsoft Support if needed: If you’re stuck, open a ticket and mention if others are seeing the same thing numbers matter with MS support. It sometimes resolves on its own if it’s on their side.

     

    If you’re doing scheduled refreshes, make sure you’re not trying to generate a new token for every row/query just once per refresh.

    • jake_BIV's avatar
      jake_BIV
      Helper I

      rohit1991  Thank you for your response. I changed the Token request to v2 (was: v1), however I get the same result in Power BI Service.  Do you have any other suggestions?

      I am following the instructions here.
      https://learn.microsoft.com/en-us/graph/auth-v2-service?tabs=curl

      Note: All works fine in Power BI Desktop to generate a token in 1-2 seconds.However, in Power BI Service it times out with no response.

      M-Code Sample: 
      let
      TokenUri = "https://login.microsoftonline.com/" & TenantID & "/oauth2/v2.0/token",
      ResourceId = "https://graph.microsoft.com/.default",
      TokenResponse = Json.Document(Web.Contents(TokenUri,
      [
      Content = Text.ToBinary(Uri.BuildQueryString([client_id = AppID, scope = ResourceId, grant_type = "client_credentials", client_secret = Secret])),
      Headers = [Accept = "application/json",#"Content-Type"= "application/x-www-form-urlencoded" ], ManualStatusHandling = {400}
      ]
      )),
      AzureAccessToken = TokenResponse[access_token]
      in
      AzureAccessToken

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi jake_BIV 
    Thank you for reaching out microsoft fabric community forum.
    we understand your frustration and concerns. Could you please provide an update on the status of your ticket? Has the issue been resolved or has the support team provided any solution ?
    Thank you.

    • jake_BIV's avatar
      jake_BIV
      Helper I

      Yes. The issue seems to have gone away about 3 days ago across all tenants at the same time.  First level support doest seem to know much.  I'm happy it's fixed but a little disappointed in the lack of understanding and communication. 

      • AlejandroOS's avatar
        AlejandroOS
        Regular Visitor

        Has been away, but my teammates noticed that the issue has been fixed..

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi jake_BIV 
    Great to hear that your issue has been resolved. Please let me know if you have any further questions or if you'd like to discuss this further. If this answers your question, please Accept it as a solution and give it a 'Kudos' so others can find it easily.
    Thank you.