How download a sharepoint file with wget and a secret or a token

Philippe Nénert 20 Reputation points
2023-06-30T09:55:31.38+00:00

Hello,

I have a registred application with autorisation “Sites.Read.All” open for this app.

I can use curl for get a token :
curl -X POST -d 'grant_type=client_credentials&client_id=[client_id]&client_secret=[client_secret]&resource=https%3A%2F%2Fmanagement.azure.com%2F' https://login.microsoftonline.com/[tenant_id]/oauth2/token

How i can use this token with wget for download a sharepoint file with the share link

or how i can use wget with tenant, client and secret id for download a shapoint file with the share link ?

Many thank

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,808 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
11,074 questions
0 comments No comments
{count} votes

Accepted answer
  1. Priscilla Soares | Escola São Domingos 400 Reputation points
    2023-06-30T10:00:29.7933333+00:00

    Hello Philippe,

    To download a SharePoint file using the access token obtained from the curl command, you can use the wget command with the --header option to include the Authorization header with the token.

    Here's an example command using wget:

    bashCopy code
    wget --header="Authorization: Bearer [access_token]" "[share_link]"
    

    Replace [access_token] with the actual access token obtained from the curl command, and [share_link] with the direct link to the SharePoint file you want to download.

    Alternatively, if you want to use the tenant ID, client ID, and client secret directly with wget, you'll need to use them to acquire an access token first. Here's an example using curl to obtain the access token and then using wget to download the file:

    bashCopy code
    # Get the access token
    access_token=$(curl -X POST -d 'grant_type=client_credentials&client_id=[client_id]&client_secret=[client_secret]&resource=https%3A%2F%2Fmanagement.azure.com%2F' https://login.microsoftonline.com/[tenant_id]/oauth2/token | jq -r '.access_token')
    
    # Download the file using wget and the access token
    wget --header="Authorization: Bearer $access_token" "[share_link]"
    

    Replace [client_id], [client_secret], [tenant_id], and [share_link] with the appropriate values for your application and the SharePoint file you want to download.

    Note that the second example uses jq to extract the access token from the response of the curl command. Make sure you have jq installed on your system or adjust the command accordingly if you prefer to extract the token using other means.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.