Skip to content

Commit

Permalink
fix(tb auth) (#4072) (patch)
Browse files Browse the repository at this point in the history
# Description

TB auth
  • Loading branch information
ChrOertlin authored Jan 13, 2025
1 parent 95d37e8 commit d0f311c
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions cg/apps/tb/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import logging
from typing import Any

from google.auth import jwt
from google.auth.crypt import RSASigner
from google.auth.transport.requests import Request
from google.oauth2 import service_account

from cg.apps.tb.dto.create_job_request import CreateJobRequest
from cg.apps.tb.dto.summary_response import AnalysisSummary, SummariesResponse
Expand Down Expand Up @@ -50,10 +50,12 @@ def __init__(self, config: dict):

@property
def auth_header(self) -> dict:
signer = RSASigner.from_service_account_file(self.service_account_auth_file)
payload = {"email": self.service_account}
jwt_token = jwt.encode(signer=signer, payload=payload).decode("ascii")
return {"Authorization": f"Bearer {jwt_token}"}
credentials = service_account.IDTokenCredentials.from_service_account_file(
filename=self.service_account_auth_file,
target_audience="trailblazer",
)
credentials.refresh(Request())
return {"Authorization": f"Bearer {credentials.token}"}

def query_trailblazer(
self, command: str, request_body: dict, method: str = APIMethods.POST
Expand Down

0 comments on commit d0f311c

Please sign in to comment.