Forum Discussion
MS Teams bot - how to download file that was uploaded in teams
const params = {
"grant_type": "client_credentials",
"client_id": botId,
"client_secret": secret,
"scope": 'what should be here?'
}
chisr -Prerequisites for uploading file-
Upload file in Teams using bot - Teams | Microsoft Docs
For Bearer Token Call:
POST https://login.microsoftonline.com/your_tenant.onmicrosoft.com/oauth2/v2.0/token
Body: (in form-data or x-www-form-urlencoded format):
- client_id: Application ID copied earlier
- scope: profile-search (May vary based on the scopes exposed in the resource API)
- client_assertion_type: urn:ietf:params:oauth:client-assertion-type:jwt-bearer (Must be same)
- client_assertion: Read about certificate credentials to learn how to register your certificate and Signed assertions for encoded assertion to be used here.
- grant_type: client_credentials (to acquire token in application context where no human interaction is needed)
Notice that there are no user credentials specified in the request. The token will be acquired in the Application/servicePrincipal context.
OAuth 2.0 client credentials flow on the Microsoft identity platform - Microsoft Entra | Microsoft Docs
.
- Sayali-MSFTAug 04, 2022
Microsoft
chisr-Glad to hear that your issue is resolved. - chisrAug 04, 2022Copper Contributor
I found the problem!!!
The DownloadUrl really has to be public, the problem is that our nodejs code use sanitazion on each input for security -
expressSanitized.middleware({encoder: 'XSSEncode'})The sanitazion added "&amd;" to the downloadUrl -
https://***.sharepoint.com/personal/****/_layouts/15/download.aspx?UniqueId=5c****c344&Translate=false&tempauth=eyJ0e........AwMDAwMDAv
That's why I got 403....
I added unescape function to remove the & and now it works.
Thanks!
- chisrAug 02, 2022Copper Contributor
So it is not as written in the Docs. The downloadUrl should be public - pre-authenticated and valid for a few minutes. Else, what is the tempAuth parameter (and it's value..) that exists in the downloadUrl? (maybe only the contentUrl requires an access token)
In another doc there is an explaination about the 'pre-authenticated downloadUrl' :
"Pre-authenticated download URLs are only valid for a short period of time (a few minutes) and do not require an Authorization header to download"
Maybe I missed some steps to make it public for a few minutes ? (we created the bot here: https://dev.botframework.com/bots/new)
The bot has to access the files that users upload in the conversation (users can be from many tenants, not from the tenant where the bot was created), without the need to ask and save the user's credentials to sharepoint (maybe bot credentials can also be good, but not user's ones)...
Thanks in advance!