Skip to content

Batch requests to URLs based on /me fail with 403 due to bad URL #179

Closed

Description

With msgraph-sdk-go-core 0.36.0 & msgraph-sdk-go 0.60.0

// Use the request builder to generate a regular
// request to /me
meRequest, err := client.Me().
	ToGetRequestInformation(context, nil)
if err != nil {
	log.Fatalf("Could not create me request: %v\n", err)
}

now := time.Now()
nowMidnight := time.Date(now.Year(), now.Month(), now.Day(),
	0, 0, 0, 0, time.Local)

startDateTime := nowMidnight.UTC().Format(time.RFC3339)
endDateTime := nowMidnight.AddDate(0, 0, 1).UTC().Format(time.RFC3339)

query := users.ItemCalendarViewRequestBuilderGetQueryParameters{
	StartDateTime: &startDateTime,
	EndDateTime:   &endDateTime,
	Select:        []string{"subject", "id"},
}

// Use the request builder to generate a regular
// request to /me/calendarview?startDateTime="start"&endDateTime="end"
eventsRequest, err := client.Me().
	CalendarView().
	ToGetRequestInformation(context,
		&users.ItemCalendarViewRequestBuilderGetRequestConfiguration{
			QueryParameters: &query,
		})
if err != nil {
	log.Fatalf("Could not create events request: %v\n", err)
}

// Build the batch
batch := msgraphcore.NewBatchRequestCollection(client.GetAdapter())

// Using AddBatchRequestStep adds each request as a step
// with no specified order of execution
meRequestItem, err := batch.AddBatchRequestStep(*meRequest)
if err != nil {
	log.Fatalf("Could not add me request to batch: %v\n", err)
}

eventsRequestItem, err := batch.AddBatchRequestStep(*eventsRequest)
if err != nil {
	log.Fatalf("Could not add event request to batch: %v\n", err)
}

batchResponse, err := batch.Send(context, client.GetAdapter())
if err != nil {
	log.Fatalf("Error sending batch: %v\n", err)
}

Here's what's sent on the wire, note the /users/me-token-to-replace:

{
    "requests": [
        {
            "id": "22fbdb26-e0a2-4f74-8c3a-93f00b08d3b4",
            "method": "GET",
            "url": "/users/me-token-to-replace",
            "headers": {
                "accept": "application/json"
            },
            "body": null,
            "dependsOn": []
        },
        {
            "id": "8c31a524-3588-4019-9ecf-30d3d2b97553",
            "method": "GET",
            "url": "/users/me-token-to-replace/calendarView?startDateTime=2023-03-30T04%3A00%3A00Z&endDateTime=2023-03-31T04%3A00%3A00Z&%24select=subject%2Cid",
            "headers": {
                "accept": "application/json"
            },
            "body": null,
            "dependsOn": []
        }
    ]
}

RESPONSE

{
    "responses": [
        {
            "id": "22fbdb26-e0a2-4f74-8c3a-93f00b08d3b4",
            "status": 403,
            "headers": {
                "Cache-Control": "no-cache",
                "x-ms-resource-unit": "1",
                "Content-Type": "application/json"
            },
            "body": {
                "error": {
                    "code": "Authorization_RequestDenied",
                    "message": "Insufficient privileges to complete the operation.",
                    "innerError": {
                        "date": "2023-03-30T17:47:29",
                        "request-id": "c57582d3-4b98-49e3-a7a9-c2223b92553e",
                        "client-request-id": "6e90bcd4-1b69-4f35-8437-ec4abc97e697"
                    }
                }
            }
        },
        {
            "id": "8c31a524-3588-4019-9ecf-30d3d2b97553",
            "status": 404,
            "headers": {
                "Cache-Control": "private",
                "Content-Type": "application/json"
            },
            "body": {
                "error": {
                    "code": "ResourceNotFound",
                    "message": "Resource could not be discovered.",
                    "innerError": {
                        "date": "2023-03-30T17:47:29",
                        "request-id": "c57582d3-4b98-49e3-a7a9-c2223b92553e",
                        "client-request-id": "6e90bcd4-1b69-4f35-8437-ec4abc97e697"
                    }
                }
            }
        }
    ]
}

Activity

  1. jasonjoh commented on Mar 30, 2023

    @jasonjoh
    MemberAuthor

    Also happens using NewBatchRequest.

  2. jasonjoh commented on Mar 30, 2023

    @jasonjoh
    MemberAuthor

    I see that the code that handles the token replacement happens in the HTTP layer, but it's only processing request URLs. Those URLs should go through token replacement before being serialized into a batch request body as well.

  3. added
    bug
    and removed on Mar 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Status: Fixedbug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions