Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
CmdGouda
New Member

Trino Custom Connector Using OAuth2 on Gateway

I've been working on increasing our Power BI foot print as we are migrating to Dynamics for our CRM.  We do have other data sources that we are connecting to through Trino but my organization requires us to use OAuth2 to authenticate.  I've been able to update the Trino Custom Connector to us OAuth2 and that works on my personal gateway and Enterprise gateway but I can't get the scheduled refreshes to work after the initial authentication token expires.  Any ideas on what I might be missing to get my refresh token to work or what to look for?

 

Here is my Token and Refresh Token Method:

//Updated to allow Refresh Tokens - KA1
TokenMethod = (code) =>
    let
        Response = Web.Contents(token_uri, [
            Content = Text.ToBinary(Uri.BuildQueryString([
                grant_type = "authorization_code",
                client_id = client_id,
                client_secret = client_secret,
                code = code,
                redirect_uri = redirect_uri
            ])),
            Headers = [
                #"Content-Type" = "application/x-www-form-urlencoded",
                #"Accept" = "application/json"
            ]
        ]),
        Tokens = Json.Document(Response),
        _ = Diagnostics.LogValue("Token Response", Tokens),
        RefreshToken = Record.FieldOrDefault(Tokens, "refresh_token", null),
        AccessToken = Record.FieldOrDefault(Tokens, "access_token", null),
        ExpiresIn = Record.FieldOrDefault(Tokens, "expires_in", null)
    in
        [
            access_token = AccessToken,
            refresh_token = RefreshToken,
            expires_in = ExpiresIn
        ];

//Added Refresh Token Method - KA1
RefreshTokenMethod = (resourceUrl, refresh_token) =>
    let
        Response = Web.Contents(token_uri, [
            Content = Text.ToBinary(Uri.BuildQueryString([
                grant_type = "refresh_token",
                client_id = client_id,
                client_secret = client_secret,
                refresh_token = refresh_token
            ])),
            Headers = [
                #"Content-Type" = "application/x-www-form-urlencoded",
                #"Accept" = "application/json"
            ]
        ]),
        Tokens = Json.Document(Response),
  _ = Diagnostics.LogValue("RefreshToken Response", Tokens)
    in
        [
            access_token = Tokens[access_token],
            refresh_token = Tokens[refresh_token],
            expires_in = Tokens[expires_in]
        ];
 
4 REPLIES 4
v-veshwara-msft
Community Support
Community Support

Hi @CmdGouda ,
We wanted to kindly follow up regarding your query. If you need any further assistance, please reach out.
Thank you.

v-veshwara-msft
Community Support
Community Support

Hi @CmdGouda ,

Just checking in to see if you query is resolved and if any responses were helpful.
Otherwise, feel free to reach out for further assistance.

Thank you.

v-veshwara-msft
Community Support
Community Support

Hi @CmdGouda ,

Thanks for posting in Microsoft Fabric Community and sharing the details of your scenario.

Based on the code you’ve added for token and refresh token handling, the behavior you’re describing is consistent with a known limitation in Power BI service refresh when using OAuth2.

According to Microsoft documentation, the Microsoft Entra ID OAuth token expires in about one hour. If your dataset refresh takes longer than that, the token can expire before the process completes, which results in a credentials error. The service can wait for up to two hours while loading data, so if the token is not renewed mid-process, refresh can fail. Microsoft is investigating a solution for this, but currently token refresh during long-running operations is not supported.
Troubleshoot refresh scenarios - Power BI | Microsoft Learn

Similar thread: Refresh not working for OAuth based Custom Connect... - Microsoft Fabric Community

 

There have also been similar discussions where users found the issue was caused by multiple refresh requests running in parallel against the same custom connector. When the refresh token was exchanged by the first request, subsequent requests tried to reuse it and failed because it was already consumed. Some of the approaches mentioned include adjusting refresh token usage settings or adding a grace period for token reuse to avoid the race condition.
Re: Custom Data Connector OAuth2 refresh token not... - Microsoft Fabric Community

 

Also, please make sure that the Test Connection logic in your custom connector is set up correctly, since this is required for scheduled refresh in the service to succeed. Microsoft has guidance on how to implement it here:
Use custom data connectors with the on-premises data gateway - Power BI | Microsoft Learn

 

In this discussion, changes to the refresh token handling using grant_type=refresh_token fixed the scheduled refresh: Custom Connector OAuth2 Scheduled Refresh Issue - Microsoft Fabric Community

 

Hope this helps. Please reach out for further assistance.

Thank you.

Hi @CmdGouda ,
Just wanted to check if the response provided was helpful. If further assistance is needed, please reach out.
Thank you.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.