-
Notifications
You must be signed in to change notification settings - Fork 222
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
Ability to set callback that return fresh API Key #1307
Comments
Before thinking further on if and how to implement this, I'd like to answer your questions:
import algoliasearch from 'algoliasearch/lite';
import { createBrowserLocalStorageCache } from '@algolia/cache-browser-local-storage';
import { createFallbackableCache } from '@algolia/cache-common';
import { createInMemoryCache } from '@algolia/cache-in-memory';
const appId = '...';
const caches = {
responsesCache: createInMemoryCache(),
requestsCache: createInMemoryCache({ serializable: false }),
hostsCache: createFallbackableCache({
caches: [
createBrowserLocalStorageCache({
key: `${algoliasearch.version}-${appId}`,
}),
createInMemoryCache(),
],
}),
};
const client = algoliasearch(appId, '...', { ...caches }); |
Hi @Haroenv, Nice, thanks for this answer which is really informative ! Yours faithfully, |
Hi @Haroenv, Is there any news about this feature request ? It could be good if we can give to the search client a method to generate an api key. It will work in combination of Yours faithfully, |
Unfortunately I think that you wouldn't want to generate a secured API key frontend, as when you generate it, you need access to the api key with higher permission to be able to generate the secured API key from. If that's available frontend, you could just as well not use secured API keys, but just a regular API key. |
In our context, we can generate a secured frontend API Key without javascript client accessing the "mother" API Key with higher permission. Context : When user want to contact Algolia, it request a secured API Key to our backend, using his JWT Access Token. As it have a limited lifespan, the Secured API Key need to be refreshed and we would like to execute this check on Algolia Query to avoid trigger useless API Key generation every X minutes even if user is not interacting with Algolia. In this context, the "Mother" api key can not be accessed directly in frontend (which would be a security flaw). The Secured API Key is temporary and can be generated only by logged in users. What we are doing at the moment : This is hard to maintain as we can miss some methods doing network request to Algolia API and we can have new ones or renaming on library version update. |
In our case, we are running into the same problems as @AntoineDuComptoirDesPharmacies described above. The lack of the ability to set the search api key during requests, or any other way to change the api key of the Context: A diagram of the situation we would like to accomplish: We've implemented this autocomplete similarly to this article of the algolia docs https://www.algolia.com/doc/ui-libraries/autocomplete/integrations/with-react-instantsearch/ Problem: const searchClient = algoliasearch("<appId>", "<searchApiKey>"); The instantiation of the The problem is that the What we are doing at the moment: While this is a good workaround for the time being, it's not perfect. This is a solution that works for the |
Context :
Following the issue #772, we can now check remaining validity of API Key.
Problem :
In our application, we are generating very short term API Keys (5 minutes) to always be compliant with filters and visibility that are set in the Key (from our backend according to user access rights).
It could be very cool to add a callback while creating the
searchclient
which will be called when API Key is near expiration and which should return a fresh API Key.Workaround :
Currently, we are wrapping the search methods from
searchclient
into some of our wrappers that do the check before every request.If we detect that API Key is expired, we generate a new
searchclient
with the updated API Key and use it to execute the query.However there is two bad concerns about this workaround :
InstantSearch
node seems to detect it and relaunch a new query (which is now duplicated).Yours faithfully,
LCDP
The text was updated successfully, but these errors were encountered: