I’m trying to integrate vertex AI search on to our docs site. The current integration options is widget with specific domains being allowed. But I’m not able to configure how the search results should look like, and what should be displayed and what the API query parameters should be depending on the query ( I want to turn off spell check for certain queries)
So I want to do a native JS REST API call to the search so that we control the display of the search results. But now the access token generated from a service account expires after 12 hours. I want to generate an access token that does not expire. How do I do that?
There are two main types: Short-lived service account credentials and Service account keys (I’m not sure which one you’re trying to use)
The short-lived credentials will expire after a set amount of time, so it would likely make sense to use Service Account Keys for your use case.
However, you can also configure your application to refresh tokens on a regular basis. Something like this:
const {google} = require('googleapis');
const {JWT} = require('google-auth-library');
async function getAccessToken() {
const client = new JWT({
keyFile: './path-to-your-service-account-key.json', // Path to your service account key JSON
scopes: ['https://www.googleapis.com/auth/cloud-platform'], // Your required scopes
});
const accessToken = await client.getAccessToken();
return accessToken;
}
Hi @holtskinner , I understand this. Our application is a simple static website that has JS. For other services we embed the access token onto the JS ( yes public). For testing purposes I generate the access token via a simple script as you had pointed out (using service account keys)
But I don’t want to generate these tokens often once the project goes live. If we feel the token is compromised then we can just delete the key , create a new one & generate the access token. But to generate the token once in a while is not feasible for us and actually does not make sense for read-only public site.
For a search on a static site, How do I do this? I want the JSON API call to work from the HTML page just like the widget. How do I accomplish this ?
Folks, is there any solution for me here without the need for another service to generate the token often ? Or else, we’ll have to consider other solutions ..
To integrate Vertex AI search functionality using JavaScript without the need to frequently generate new access tokens, you have a few options to streamline the authentication process. The goal is to handle authentication more efficiently without manual token generation. Here are some approaches:-