Skip to content

Stateless authorization on preload requests #117

@SherinBloemendaal

Description

@SherinBloemendaal

Hello,

I could not find any documentation about stateless authorization, for example when using the lexik-jwt-authentication-bundle in combination with API-platform. We are getting a 401 Unauthorized on the preload responses, is this expected behaviour or not?

My code:

const bookResp = await fetch("/api/books", {
        "headers": {
            "accept": "application/ld+json",
            "accept-language": "en,nl;q=0.9",
            "authorization": "Bearer " + token,
            "preload": "\"/hydra:member/*/author\"",
            "fields": "\"/hydra:member/*/author/name\"",
        },
        "referrer": "https://localhost/api",
        "referrerPolicy": "strict-origin-when-cross-origin",
        "method": "GET",
        "credentials": "include"
    });
    const bookJSON = await bookResp.json();
    console.log(bookJSON)

    for (const book of bookJSON['hydra:member']) {
        const author = await fetch(book.author, {
            "headers": {
                "accept": "application/ld+json",
                "authorization": "Bearer " + token,
            },
            "method": "GET",
            "referrer": "https://localhost/api",
            "referrerPolicy": "strict-origin-when-cross-origin",
            "method": "GET",
            "credentials": "include"
        });
        console.log(await author.json());
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions