Re-wire auth to use a provider pattern. Lots of tests remove cloud references#3230
Re-wire auth to use a provider pattern. Lots of tests remove cloud references#3230GiantRobots merged 11 commits intomainfrom
Conversation
…weirdness in control flow.
…ve single points of access
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| settings, | ||
| accessToken, | ||
| }); | ||
|
|
There was a problem hiding this comment.
⚠️ Argument of type 'EventAttribute | IFailure | PotentiallyDecodable' is not assignable to parameter of type 'Optional<WorkflowEvent | EventAttribute | PotentiallyDecodable>'.
| accessToken, | ||
| }); | ||
|
|
||
| const decodedAttributes = decodeAttributes( |
There was a problem hiding this comment.
⚠️ Argument of type 'EventAttribute | IFailure | PotentiallyDecodable' is not assignable to parameter of type 'Optional<WorkflowEvent | EventAttribute | PotentiallyDecodable>'.
| settings, | ||
| accessToken, | ||
| ); | ||
|
|
There was a problem hiding this comment.
⚠️ Object is possibly 'null' or 'undefined'.⚠️ Object is possibly 'null' or 'undefined'.
| accessToken, | ||
| ); | ||
|
|
||
| expect(decodedHeartbeatDetails[0].heartbeatDetails.payloads[0]).toBe(2); |
There was a problem hiding this comment.
⚠️ Object is possibly 'null' or 'undefined'.⚠️ Object is possibly 'null' or 'undefined'.
| headers['Authorization-Extras'] = accessTokenExtras; | ||
| const accessToken = await getAccessToken(); | ||
| const idToken = await getIdToken(); | ||
| if (accessToken) { |
There was a problem hiding this comment.
⚠️ Element implicitly has an 'any' type because expression of type '"Authorization"' can't be used to index type '{ 'Content-Type': string; 'X-Namespace': string; }'.
| if (accessToken) { | ||
| headers['Authorization'] = `Bearer ${accessToken}`; | ||
| } | ||
| if (idToken) { |
There was a problem hiding this comment.
⚠️ Element implicitly has an 'any' type because expression of type '"Authorization-Extras"' can't be used to index type '{ 'Content-Type': string; 'X-Namespace': string; }'.
|
| settings, | ||
| $authUser.accessToken, | ||
| ); | ||
| const decodedAttributes = decodePayloadAttributes( |
There was a problem hiding this comment.
⚠️ Argument of type 'WorkflowEvent | EventAttribute | IMemo | PotentiallyDecodable' is not assignable to parameter of type 'Optional<WorkflowEvent | EventAttribute | PotentiallyDecodable>'.
…Re-wire with-access-token to use pre/post hooks so code paths can be determined by the caller. Lots of tests
…tions as well as a few others
andrewzamojc
left a comment
There was a problem hiding this comment.
Code looks good. The new way makes sense and cleans up the calling code nicely. Tons of tests 👍 I can manually test next.
| } | ||
|
|
||
| export async function getAccessToken(): Promise<string> { | ||
| if (!BROWSER || !provider) return ''; |
There was a problem hiding this comment.
silent, but seems fine.
| ): Promise<string> { | ||
| const settings = page.data?.settings; | ||
| return getCodecEndpoint(settings); | ||
| } |
There was a problem hiding this comment.
This is approximately how we do it now. I very much dislike how we use a store and push it down by setting it in the page it's VERY VERY side effecty so this is step1 in changing it.
| let response = await executeRequest(context); | ||
|
|
||
| if (isBrowser) { | ||
| response = await runPostResponse(response, { |
rossnelson
left a comment
There was a problem hiding this comment.
LGTM! I tested using the local oidc server and all looks good.
Side Note: I've got a follow-up draft PR (#3248) that adds redirect-to-login when refreshTokens returns false in ossPostResponse — that behavior was missing for requests that bypass handleError (e.g. background workflow count polls).
Description
This PR updates the auth code in request-from-api to use dependency injection and middleware instead of the current if based approach for injecting different authentication strategies for other providers specifically temporal cloud.
This allows auth to be swapped wholesale without implementation leakage around the project and consolidating request/response wrappers also ensuring a single implementation is being used throughout (there were previously some edge cases where two sets of authnz code would be executed)