Skip to content
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

New method: GetSecuredApiKeyRemainingValidity #772

Closed
Ant-hem opened this issue Jul 25, 2019 · 2 comments · Fixed by #778
Closed

New method: GetSecuredApiKeyRemainingValidity #772

Ant-hem opened this issue Jul 25, 2019 · 2 comments · Fixed by #778

Comments

@Ant-hem
Copy link
Member

Ant-hem commented Jul 25, 2019

Summary

When a secured API keys expire, search breaks. The current workaround is more complex
than it needs to be.

The options for developers using Algolia require, at every place where a search
operation is performed, catching an operation error, identify it as a
"ValidUntil" error, then regenerate the API key, and perform the search
operation again.

The idea is to define a method which tells if a SecuredAPIKey
is expired or not without making a single call to Algolia's API.

References

@Haroenv
Copy link
Contributor

Haroenv commented Jul 25, 2019

Is it an option to have a method getSecuredApiKeyValidity(key), so a person can do their own calculation, and this method can be side-effect free?

@Haroenv
Copy link
Contributor

Haroenv commented Jul 25, 2019

Note that decoding from base64 is different in browser (atob) than in Node (using Buffer)

Browser:

const decoded = atob(key);

Node:

const decoded = Buffer.from(key, 'base64').toString();

Buffer.from will have to be polyfilled for Node.js < 6 https://yarnpkg.com/en/package/buffer-from

Buffer.from can be "progressively enhanced":

const decoded =
  Buffer.from && Buffer.from !== Uint8Array.from
    ? Buffer.from(key, 'base64').toString()
    : new Buffer(key, 'base64').toString();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants