@@ -438,37 +438,6 @@ async def _upsert_alert_configuration(org_id: int, config: str):
438438
439439
440440async def _get_or_create_drycc_token (username , token : dict ):
441- async def _check_or_create_drycc_token (drycc_token , token ):
442- async with httpx .AsyncClient () as client :
443- created = False if drycc_token else True
444- if drycc_token :
445- headers = {"Authorization" : f"Token { drycc_token } " }
446- resp = await client .get (
447- f"{ DRYCC_CONTROLLER_URL } /v2/auth/whoami" , headers = headers )
448- if resp .status_code in [401 , 403 ]:
449- created = True
450- if created :
451- headers = {"Authorization" : f"Bearer { token ['access_token' ]} " }
452- data = (await client .post (
453- f"{ DRYCC_CONTROLLER_URL } /v2/auth/token/?alias=grafana-datasource" ,
454- headers = headers , json = token )).json ()
455- drycc_token = data ["token" ]
456- return created , drycc_token
457-
458- async with await AsyncConnection .connect (os .environ .get ("GF_DATABASE_URL" )) as conn :
459- async with conn .cursor () as cursor :
460- await cursor .execute (
461- "SELECT o_auth_id_token FROM user_auth WHERE auth_module=%s AND auth_id=%s" ,
462- ("authproxy" , username )
463- )
464- row = await cursor .fetchone ()
465- drycc_token = row [0 ] if row else None
466- created , drycc_token = await _check_or_create_drycc_token (drycc_token , token )
467- if created :
468- async with conn .cursor () as cursor :
469- await cursor .execute (
470- "UPDATE user_auth SET o_auth_id_token=%s WHERE auth_module=%s AND auth_id=%s" ,
471- (drycc_token , "authproxy" , username )
472- )
473- await conn .commit ()
474- return created , drycc_token
441+ # Pass through the Passport access_token directly, no need for DRF token conversion
442+ drycc_token = token .get ("access_token" )
443+ return True , drycc_token
0 commit comments