Onedrive "Unauthenticated" when trying to copy/sync, but can use 'lsd'

Ultimately, the failure caused by the inclusion of the Authorization header on the PUT request is due to the upload operation hitting different backends. The POST to create the upload session is against OneDrive, but the PUT to upload the data is against Graph. Each of these has its own token, and they cannot be used interchangeably. For Graph, the required token is returned in the POST response in the tempauth field. When making the PUT request, both tokens are supplied, and the Authorization header is given precedence in the failing scenarios.

Here's a sample where I have replaced the actual tokens with ONEDRIVE_TOKEN and GRAPH_TOKEN for clarity.

2023/10/04 22:19:10 DEBUG : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2023/10/04 22:19:10 DEBUG : Copy-M365UserDrive.txt: Starting multipart upload
2023/10/04 22:19:10 DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2023/10/04 22:19:10 DEBUG : HTTP REQUEST (req 0xc000754900)
2023/10/04 22:19:10 DEBUG : POST /v1.0/drives/cd3c266076684197/items/CD3C266076684197!163:/Copy-M365UserDrive.txt:/createUploadSession HTTP/1.1
Host: graph.microsoft.com
User-Agent: ISV|Transend Corporation|TMCTools/1.0
Content-Length: 116
Authorization: Bearer ONEDRIVE_TOKEN
Content-Type: application/json
Accept-Encoding: gzip

{"item":{"fileSystemInfo":{"createdDateTime":"2023-06-30T14:05:12Z","lastModifiedDateTime":"2023-06-30T14:05:12Z"}}}
2023/10/04 22:19:10 DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2023/10/04 22:19:11 DEBUG : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2023/10/04 22:19:11 DEBUG : HTTP RESPONSE (req 0xc000754900)
2023/10/04 22:19:11 DEBUG : HTTP/1.1 200 OK
Transfer-Encoding: chunked
Cache-Control: no-store, no-cache
Client-Request-Id: f561e6ea-235e-450f-bb5b-ed434c7b97f7
Content-Type: application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8
Date: Thu, 05 Oct 2023 03:19:09 GMT
Location: https://graph.microsoft.com
Odata-Version: 4.0
Request-Id: f561e6ea-235e-450f-bb5b-ed434c7b97f7
Strict-Transport-Security: max-age=31536000
Vary: Accept-Encoding
X-Ms-Ags-Diagnostic: {"ServerInfo":{"DataCenter":"South Central US","Slice":"E","Ring":"5","ScaleUnit":"005","RoleInstance":"SN4PEPF000006F6"}}

614
{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#microsoft.graph.uploadSession","expirationDateTime":"2023-10-05T03:34:09.903Z","nextExpectedRanges":["0-"],"uploadUrl":"https://my.microsoftpersonalcontent.com/personal/cd3c266076684197/_api/v2.0/drives/b!FvAIvh0_20O_ObJZ91ioW810sFI9iN1CjQCdmf-IB-TwYMbbJO_BTZdmFk7EGcR9/items/01WIFDVRR7FXWDZQLMENG3IFGFOWYBL35W/uploadSession?guid='57535ede-8024-4c47-a5c9-02ddd4978c74'&overwrite=True&rename=False&dc=0&tempauth=GRAPH_TOKEN"}
0

2023/10/04 22:19:11 DEBUG : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2023/10/04 22:19:11 DEBUG : Copy-M365UserDrive.txt: Uploading segment 0/18 size 18
2023/10/04 22:19:11 DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2023/10/04 22:19:11 DEBUG : HTTP REQUEST (req 0xc000523000)
2023/10/04 22:19:11 DEBUG : PUT /personal/cd3c266076684197/_api/v2.0/drives/b!FvAIvh0_20O_ObJZ91ioW810sFI9iN1CjQCdmf-IB-TwYMbbJO_BTZdmFk7EGcR9/items/01WIFDVRR7FXWDZQLMENG3IFGFOWYBL35W/uploadSession?guid='57535ede-8024-4c47-a5c9-02ddd4978c74'&overwrite=True&rename=False&dc=0&tempauth=GRAPH_TOKEN HTTP/1.1
Host: my.microsoftpersonalcontent.com
User-Agent: ISV|Transend Corporation|TMCTools/1.0
Content-Length: 18
Authorization: Bearer ONEDRIVE_TOKEN