Schema Analyzer calls don't have the refreshed token which causes 401 error
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- react, typescript
- Domain
- api, authentication, frontend
Research direction
Start in Admin.jsx and trace how apiDocumentationParser, hydraDataProvider, and the Guesser components obtain the session token for schema requests. Compare those requests with the main data call and verify that schema calls use the refreshed JWT and no longer return 401 after token expiry.
Written by the indexing model from the issue text.
Description
API Platform version(s) affected: api: 3.3, admin: 3.4.6
Description
When accessing a resource from the admin, several extra calls seem to be made on top of the main call fetching the data:
These calls seem to be initiated by the Guesser Components to fetch the schema:
These calls do include a JWT but this token is not refreshed if expired. The JWT in the "main" call is correctly updated.
How to reproduce
- Clone Api Platform Demo repository
- Remove components so that the Guesser components do their job
Possible Solution
n/a
Additional Context
- Code is very close to the Demo:
// Admin.jsx
const apiDocumentationParser = (session) => async () => {
try {
return await parseHydraDocumentationWithEnums(ENTRYPOINT, {
headers: {
Authorization: `Bearer ${session?.accessToken}`,
},
});
} catch (result) {
// @ts-ignore
const { api, response, status } = result;
if (status !== 401 || !response) {
throw result;
}
return {
api,
response,
status,
};
}
};
const AdminUI = ({ children, session }) => {
const dataProvider = useRef();
const { docType } = useContext(DocContext);
dataProvider.current = hydraDataProvider({
entrypoint: ENTRYPOINT,
httpClient: (url, options = {}) => fetchHydra(url, {
...options,
headers: {
Authorization: `Bearer ${session?.accessToken}`,
},
}),
apiDocumentationParser: apiDocumentationParser(session),
});
return docType === "hydra" ? (
<HydraAdmin
requireAuth
authProvider={authProvider}
// @ts-ignore
dataProvider={dataProvider.current}
entrypoint={window.origin}
i18nProvider={i18nProvider}
layout={MyLayout}
>
{!!children && children}
</HydraAdmin>
) : (
<OpenApiAdmin
requireAuth
authProvider={authProvider}
// @ts-ignore
dataProvider={dataProvider.current}
entrypoint={window.origin}
docEntrypoint={`${window.origin}/docs.json`}
i18nProvider={i18nProvider}
layout={MyLayout}
>
{!!children && children}
</OpenApiAdmin>
);
};
const AdminWithContext = ({ session }) => {
const [docType, setDocType] = useState(
store.getItem("docType", "hydra"),
);
return (
<DocContext.Provider
value={{
docType,
setDocType,
}}>
<AdminUI session={session}>
// No Resources defined here unlike in the demo repo
</AdminUI>
</DocContext.Provider>
);
};
- parseHydraDocumentationWithEnums is based on https://github.com/api-platform/admin/issues/494#issuecomment-1427746210 doesn't seem to be the source as when using the normal
parseHydraDocumentationproblem remains. - Calls are made every time we access the resource from the admin if no ApiFilter is defined in the API
- If ApiFilter is defined in the API then calls are only made the first time we try to access the resource. If the resource is not accessed at least once before the initial token expires the problem remains
- Dominant language
- TypeScript
- Stars
- 516
- Forks
- 134
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from api-platform/admin
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
api-platform/admin#616 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 64/100
api-platform/admin#660 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 50/100
api-platform/admin#659 · 1 reaction ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
api-platform/admin#631 · 6 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
api-platform/admin#626 · 1 comment · 1 reaction ·
All issues in api-platform/admin
Similar issues
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
dennys-bd/agent-hive#184 ·
-
Add: hunch Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
AbdelStark/awesome-typesafe#104 ·
-
ai-observability bug team/ai-observability
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
vicharanashala/fln#563 ·