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

[Tooling] OIDC sample code fetches a new ID token every time instead of checking exp date in req header #654

Closed
saraford opened this issue Jul 18, 2024 · 0 comments · Fixed by #918
Assignees
Labels
bug Something isn't working docs Improvements or additions to documentation tooling

Comments

@saraford
Copy link

Describe the bug
In the sample code: https://firebase.google.com/docs/genkit/plugins/ollama#authentication it shows

export async function getIdToken(url: string): Promise<string> {
  const auth = getAuthClient();
  const client = await auth.getIdTokenClient(url);
  return client.idTokenProvider.fetchIdToken(url);
}

But client.idTokenProvider.fetchIdToken(url); is fetching a new ID token each time.

Expected behavior

The sample code needs to check the exp date first, something similar to this (but in typescript)

const auth = new GoogleAuth();
  const client = await auth.getIdTokenClient(url);

  async function fetchWithAuthHeader(url, options = {}) {
    const headers = await client.getRequestHeaders(url)
    options.headers = { ...headers, ...(options.headers || {}) };
    return fetch(url, options);
  }

Then in the ollama plugin, instead of

 requestHeaders: async (params) => ({
    Authorization: `Bearer ${await getIdToken(params.serverAddress)}`,
  }),

use fetchWithAuthHeader instead.

@saraford saraford added bug Something isn't working tooling labels Jul 18, 2024
@chrisraygill chrisraygill moved this to Todo in Genkit Backlog Jul 18, 2024
@chrisraygill chrisraygill added P0 docs Improvements or additions to documentation and removed needs-triage labels Jul 18, 2024
@chrisraygill chrisraygill removed the status in Genkit Backlog Jul 18, 2024
@chrisraygill chrisraygill removed the P0 label Jul 18, 2024
@chrisraygill chrisraygill moved this to In Progress in Genkit Backlog Jul 18, 2024
@github-project-automation github-project-automation bot moved this from In Progress to Done in Genkit Backlog Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working docs Improvements or additions to documentation tooling
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants