Search code examples
azure-log-analytics

Valid authentication was not provided


I am stuck on step 2.4 of this wiki

In the previous step, I get a valid token.

Why do I get "Valid authentication was not provided"?

I added a header called Authorization - see picture.

What am i missing?

enter image description here


Solution

  • When we use Azure Log Analytics REST API to do a query, we need to use Authorization=Bearer eyJ.... as request Headers. For more details, please refer to here.

    For example

    1. Register Azure AD application

    2. Configure API permissions for the AD application enter image description here

    3. Give the AAD Application access to our Log Analytics Workspace. Please assign Log Analytics Reader role to the AD application

    4. Get access token

    POST /<your tenant id>/oauth2/token HTTP/1.1
    Host: login.microsoftonline.com
    Content-Type: application/x-www-form-urlencoded
    
    grant_type =client_credentials
    &client_id=<>
    &client_secret=<>
    &resource=https://westus2.api.loganalytics.io
    
    1. Call the api
    POST https://api.loganalytics.io/v1/workspaces/{workspaceId}/query
    Authorization: Bearer ey...
    Content-Type: application/json
    
    {
        "query": ""
    }
    
    

    enter image description here