evenevan / export-ms-teams-chats

Export Microsoft Teams Chats to a local HTML file
MIT License
52 stars 6 forks source link

AADSTS50059: No tenant-identifying information found #7

Closed Martell17 closed 13 hours ago

Martell17 commented 6 days ago

Last week I successfully used this beautiful export-ms-teams-chats script to download my Teams chats without any issues. Now I need to download my chats again, but I can not do it because of the error:

.\Get-MicrosoftTeamsChat.ps1
Starting script...
Your chats will be exported to C:\export-ms-teams-chats-main\out.
Invoke-RestMethod : {"error":"invalid_request","error_description":"AADSTS50059: No tenant-identifying information
found in either the request or implied by any provided credentials. Trace ID: XXXX Correlation ID: XXXX Timestamp: 2024-09-12 08:05:40Z","error_codes":[50059],"timestamp":"2024-09-12 08:05:40Z","trace_id":"XXXX","correlation_id":"XXXX"}
At C:\export-ms-teams-chats-main\functions\util\Get-GraphAccessToken.psm1:45 char:30
+ ... deRequest = Invoke-RestMethod -Method POST -Uri "https://login.micros ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Invoke-RestMethod : {"error":"invalid_request","error_description":"AADSTS900144: The request body must contain the
following parameter: 'device_code'. Trace ID: XXXX Correlation ID:XXXX Timestamp: 2024-09-12 08:05:40Z","error_codes":[900144],"timestamp":"2024-09-12 08:05:40Z","trace_id":"XXXX","correlation_id":"XXXX","error_uri":"https://login.microsoftonline.com/error?code=900144"}
At C:\export-ms-teams-chats-main\functions\util\Get-GraphAccessToken.psm1:74 char:13
+             Invoke-RestMethod -Method POST -Uri "https://login.micros ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

I checked from the same PC I have successed to run it from, from different computers, different locations, and also asked my coworkers who use the same Teams organization. The error message is the same in all the cases.

Also, I tried to run it like this (found my Tenant ID in Azure Portal)

.\Get-MicrosoftTeamsChat.ps1 -tenantId my-tenant-id-guid -clientId ???

but I failed to find what Client ID should I put there. If I put random Azure app ID from the Azure Portal, I got the next error:

he provided value for the input parameter 'device_code' is not valid. This device code has expired.

Please help.

evenevan commented 5 days ago

Hey!

I believe this is caused by https://github.com/pnp/powershell/discussions/4249. The tenant this application was using was deleted. I'm looking into workarounds.

evenevan commented 5 days ago

Could you try .\Get-MicrosoftTeamsChat.ps1 -clientId 7f586887-37d3-4d1f-89cf-153c7d1bbe54?

That client Id is an app I've created in my tenant.

This seems to work within my tenant. Unfortunately I don't have multiple tenants so I can't test multitenant functionality.

Martell17 commented 23 hours ago

Resolved. I've created a new Azure App, copied all the necessary permissions from the old app (you still can find it under the Enterprise Apps, it's name is PnP management shell) to the new one, and then set the Allow public client flows switch to Yes (https://stackoverflow.com/questions/45609432/how-do-i-resolve-the-error-aadsts7000218-the-request-body-must-contain-the-foll).

Then change the following parameters in Get-MicrosoftTeamsChat.ps1 file: $clientId = "my_new_app_guid" $tenantId = "my_tenant_id"

It worked!

evenevan commented 13 hours ago

i've switched the default client id over to my application. if anyone has any related issues, this can be reopened.