Forum Discussion
How to refresh access token with custom connector (OAuth2)?
Hi ArvindBhatt - Power BI does not automatically refresh access tokens for custom connectors. You must handle token refreshing manually within your custom connector.
Below is an example pattern for refreshing an access token:
RefreshToken = () =>
let
Response = Web.Contents("https://api.example.com/token", [
Content = Text.ToBinary("grant_type=refresh_token&refresh_token=" & RefreshToken),
Headers = [
#"Content-Type" = "application/x-www-form-urlencoded",
#"Authorization" = "Basic " & Base64EncodedClientCredentials
]
]),
ParsedResponse = Json.Document(Response),
NewAccessToken = ParsedResponse[access_token],
NewExpirationTime = DateTimeZone.UtcNow + #duration(0, 0, 0, ParsedResponse[expires_in])
in
[Token = NewAccessToken, Expiration = NewExpirationTime];
Handling authentication for Power Query connectors - Power Query | Microsoft Learn
Custom Connector with Token Refresh - Microsoft Fabric Community