-
Notifications
You must be signed in to change notification settings - Fork 103
feat(core): resolve auth schemes based on the preference list #1571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
packages/core/src/middleware-http-auth-scheme/httpAuthSchemeMiddleware.ts
Outdated
Show resolved
Hide resolved
This comment was marked as outdated.
This comment was marked as outdated.
} | ||
} | ||
|
||
return preferredAuthOptions; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because the lists are so small, I feel that this is optional, but you can do this without nested for loops like this:
// runnable in console
{
const candidates = [{ id: 'a', }, { id: 'b' }];
const preference = ['c', 'b'];
const candidateMap = candidates.reduce((map, item) => {
map.set(item.id, item);
return map;
}, new Map);
const preferredMap = new Map;
for (const pref of preference) {
if (candidateMap.has(pref)) {
preferredMap.set(pref, candidateMap.get(pref));
}
}
for (const [id, item] of candidateMap) {
preferredMap.set(id, item);
}
console.log([...preferredMap.values()])
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should retain the resolve function, as it's recommended in the internal cross SDK proposal.
Also, the JS SDK implementation uses map for authSchemes which do not have order preserved. The order is preserved in authOptions instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if you're referring to the Map in the example, but those retain insertion order like modern objects.
But let's keep the function as is since it is in the design.
Issue #, if available:
Internal JS-5811
Description of changes:
Resolves auth schemes based on the preference list
Testing is done by installing
@aws-sdk/client-s3
and@smithy/core
, and validating signatureTest code
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.