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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Anonymous
Not applicable

can we refresh access token while using Graph API in power query

Access token got expired after 60 minutes, need to refresh it to fetch the information from GRAPH API.

Below is the power query code  using :

 

let
token_uri = "https://login.windows.net/" & #"Azure AD Tenant ID" & "/oauth2/token",
resource = "https://graph.microsoft.com",
tokenResponse = Json.Document(Web.Contents(token_uri,
[
Content = Text.ToBinary(Uri.BuildQueryString(
[
client_id = #"Azure Application Client ID",
resource = resource,
grant_type = "client_credentials",
client_secret = #"Azure Application Client Secret"
]
)),
Headers = [Accept = "application/json"], ManualStatusHandling = {400}
])),
access_token = tokenResponse[access_token],
Source = OData.Feed("https://graph.microsoft.com/v1.0/devices?$select=id, accountEnabled, approximateLastSignInDateTime, deviceId, displayName, isCompliant, isManaged, mdmAppId, onPremisesLastSyncDateTime, onPremisesSyncEnabled, operatingSystem, operatingSystemVersion, trustType, registeredOwners, registeredUsers", [ Authorization = "Bearer " & access_token ], [ ExcludedFromCacheKey = {"Authorization"}, ODataVersion = 4, Implementation = "2.0" ]),
#"Expanded registeredOwners" = Table.ExpandTableColumn(Source, "registeredOwners", {"id"}, {"id.1"}),
#"Remove columns" = Table.RemoveColumns(#"Expanded registeredOwners", Table.ColumnsOfType(#"Expanded registeredOwners", {type table, type record, type list, type nullable binary, type binary, type function}))
in
#"Remove columns"

2 REPLIES 2
v-angzheng-msft
Community Support
Community Support

Hi, @Anonymous 

We can still customize the lifetime of the access token by configuring the token lifetime policy.

$policy = New-AzureADPolicy -Definition @('{"TokenLifetimePolicy":{"Version":1,"AccessTokenLifetime":"00:15:00"}}') -DisplayName "WebPolicyScenario" -IsOrganizationDefault $false -Type "TokenLifetimePolicy"

Hope this helps.

 

 

Best Regards,
Community Support Team _ Zeon Zheng


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

@v-angzheng-msft  Thanks of the reply, I will check this and confirm to you.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.