Skip to content

Commit

Permalink
fast: Fix configurable saveToken and fetchToken
Browse files Browse the repository at this point in the history
  • Loading branch information
sonnyp committed Jan 8, 2025
1 parent 8337bcc commit f3b3888
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
28 changes: 13 additions & 15 deletions packages/client-core/src/fast/fast.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@ export default function fast({ sasl2 }, { saveToken, fetchToken } = {}) {
Object.assign(fast, {
mechanism: null,
mechanisms: [],
async saveToken() {
saveToken,
fetchToken,
async save(token) {
try {
await saveToken();
await this.saveToken(token);
} catch (err) {
fast.emit("error", err);
}
},
async fetchToken() {
async fetch() {
try {
return await fetchToken();
return await this.fetchToken();
} catch (err) {
fast.emit("error", err);
}
Expand Down Expand Up @@ -107,17 +109,13 @@ export default function fast({ sasl2 }, { saveToken, fetchToken } = {}) {
},
async (element) => {
if (element.is("token", NS)) {
try {
await saveToken({
// The token is bound by the mechanism
// > Servers MUST bind tokens to the mechanism selected by the client in its original request, and reject attempts to use them with other mechanisms.
mechanism: fast.mechanism,
token: element.attrs.token,
expiry: element.attrs.expiry,
});
} catch (err) {
fast.emit("error", err);
}
await fast.save({
// The token is bound by the mechanism
// > Servers MUST bind tokens to the mechanism selected by the client in its original request, and reject attempts to use them with other mechanisms.
mechanism: fast.mechanism,
token: element.attrs.token,
expiry: element.attrs.expiry,
});
}
},
);
Expand Down
2 changes: 1 addition & 1 deletion packages/client/lib/createOnAuthenticate.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function createOnAuthenticate(credentials, userAgent) {
return;
}

credentials.token = await fast?.fetchToken?.();
credentials.token = await fast?.fetch?.();

await authenticate(credentials, mechanisms[0], userAgent);
};
Expand Down

0 comments on commit f3b3888

Please sign in to comment.