+
    QV-jº  ã                   óÊ   € R t ^ RIt^ RIHt ^RIHt ^RIHt ^RIH	t	H
t
 RtRt ! R R	]]4      tR
 R ltR R ltRRRR/R R lltRR/R R lltRRRRRRRR/R R lltR# )u™  Keyless CI/CD authentication via OIDC token exchange ("Trusted Publishers").

A CI job proves its identity to the Hub with a short-lived OIDC id token minted by its CI
provider (e.g. GitHub Actions), then exchanges it at ``POST {ENDPOINT}/oauth/token`` (RFC 8693)
for a short-lived Hugging Face token â€” no long-lived ``HF_TOKEN`` secret to store.

This module is self-contained: it only handles minting the provider id token and the exchange.
It deliberately does not register a public API or a CLI verb; the integration point is the token
resolution in ``utils/_auth.py`` (see ``_get_token_from_oidc``).

Docs: https://huggingface.co/docs/hub/trusted-publishers
N)ÚEnum)Ú	constants)Ú	OIDCError)Úget_sessionÚhf_raise_for_statusz/urn:ietf:params:oauth:grant-type:token-exchangez)urn:ietf:params:oauth:token-type:id_tokenc                   ó   € ] tR t^(tRtRtRtR# )ÚProviderzRCI providers that can mint an OIDC id token natively. GitHub Actions only for now.Úgithub© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__ÚGITHUBÚ__static_attributes__r
   ó    Úf/Volumes/fast/ai/experiments/ui-tars-smoke/.venv/lib/python3.14/site-packages/huggingface_hub/_oidc.pyr   r   (   s
   † Ù\à„Fr   r   c                ó2   € V ^8„  d   QhR\         R,          /# )é   ÚreturnN)r   )Úformats   "r   Ú__annotate__r   .   s   € ÷ ñ œ D�ñ r   c                 ón   € \         P                  P                  R4      R8X  d   \        P                  # R# )zYDetect the CI provider able to mint an OIDC id token, or `None` if not in a supported CI.ÚGITHUB_ACTIONSÚtrueN)ÚosÚenvironÚgetr   r   r
   r   r   Údetect_providerr   .   s%   € ä	‡z�z‡~�~Ð&Ó'¨6Ô1Ü�‰ÐÙr   c                ó0   € V ^8„  d   QhR\         R\         /# )r   Úaudiencer   )Ústr)r   s   "r   r   r   5   s   € ÷ $ñ $¤Sð $¬Sñ $r   c                ó>  € \         P                  P                  R4      p\         P                  P                  R4      pV'       d	   V'       g   \        R4      h\	        4       P                  VRV /RRV 2/R7      p\        V4       VP                  4       R,          # )	zâMint an OIDC id token from the GitHub Actions runtime.

Relies on the `ACTIONS_ID_TOKEN_REQUEST_URL` / `ACTIONS_ID_TOKEN_REQUEST_TOKEN` env vars,
which GitHub only injects when the job declares `permissions: id-token: write`.
ÚACTIONS_ID_TOKEN_REQUEST_URLÚACTIONS_ID_TOKEN_REQUEST_TOKENz÷Cannot request an OIDC id token from GitHub Actions. Make sure the workflow job sets `permissions: id-token: write`. See https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connectr!   ÚAuthorizationzBearer )ÚparamsÚheadersÚvalue)r   r   r   r   r   r   Újson)r!   Úrequest_urlÚrequest_tokenÚresponses   &   r   Ú_get_github_oidc_tokenr.   5   s�   € ô —*‘*—.‘.Ð!?Ó@€KÜ—J‘J—N‘NÐ#CÓD€MßŸmÜðMó
ð 	
ô
 ‹}× Ñ ØØ˜HÐ%Ø  G¨M¨?Ð";Ð<ð !ó €Hô
 ˜Ô!Ø�=‰=‹?˜7Õ#Ð#r   Úproviderr!   c                ón   € V ^8„  d   QhR\         \        ,          R,          R\        R,          R\        /# )r   r/   Nr!   r   )r   r"   )r   s   "r   r   r   L   s4   € ÷ kñ k¤¬3¥°Õ 5ð kÌÈdÍ
ð kÔ^añ kr   c                ó   € T;'       g    \         P                  pT ;'       g    \        4       p RP                  R \         4       4      pV f   \        RV R24      hV \        P                  8X  d   \        V4      # \        RV  RV R24      h)aÁ  Mint a raw OIDC id token (JWT) from the current CI provider.

Args:
    provider (`str`, *optional*):
        CI provider to use. Auto-detected from the environment when omitted.
    audience (`str`, *optional*):
        The `aud` claim to request. Defaults to `constants.ENDPOINT` so it matches the endpoint
        that validates it (respects `HF_ENDPOINT`/staging).

Returns:
    `str`: The raw id token (JWT) to pass to [`exchange_oidc_token`].
z, c              3   ó8   "  € T F  qP                   x € K  	  R # 5i)N)r)   )Ú.0Úps   & r   Ú	<genexpr>Ú!get_oidc_token.<locals>.<genexpr>[   s   é € Ð4©8 aŸ'ž'«8ùs   ‚zONo supported CI OIDC provider detected. Trusted Publishers currently supports: Ú.zOIDC provider 'z#' is not supported yet. Supported: )	r   ÚENDPOINTr   Újoinr   r   r   r.   ÚNotImplementedError)r/   r!   Ú	supporteds   $$ r   Úget_oidc_tokenr<   L   sŽ   € ð ×-Ð-œ9×-Ñ-€HØ×,Ð,œ?Ó,€HØ—	‘	Ñ4­8Ó4Ó4€IØÒÜÐiÐjsÐitÐtuÐvÓwÐwØ”8—?‘?Ô"Ü% hÓ/Ð/Ü
 °¨zÐ9\Ð]fÐ\gÐghÐiÓ
jÐjr   Úendpointc                óV   € V ^8„  d   QhR\         R\         R\         R,          R\        /# )r   Úsubject_tokenÚresourcer=   Nr   )r"   Údict)r   s   "r   r   r   c   s-   € ÷ ñ ¬#ð ¼ð ÌÈdÍ
ð Ô^bñ r   c                óÄ   € \        4       P                  T;'       g    \        P                   R2R\        R\
        RV RV/R7      p\        V4       VP                  4       # )uÝ  Exchange a CI OIDC id token for a short-lived Hugging Face token (RFC 8693).

Args:
    subject_token (`str`):
        The raw OIDC id token (JWT) from the CI provider. Its `aud` claim must be the Hub URL.
    resource (`str`):
        What to scope the token to: a Hub repo (`namespace/name`, `datasets/namespace/name`,
        `spaces/namespace/name`, `kernels/namespace/name`) for a write token, or a bare Hub
        username for a read-only `gated-repos` token.
    endpoint (`str`, *optional*):
        Hub endpoint. Defaults to `constants.ENDPOINT` (respects `HF_ENDPOINT`/staging).

Returns:
    `dict`: The token-exchange response, e.g.
    `{"access_token": "hf_jwt_â€¦", "token_type": "bearer", "expires_in": 3600, ...}`.
z/oauth/tokenÚ
grant_typeÚsubject_token_typer?   r@   )r*   )r   Úpostr   r8   Ú_TOKEN_EXCHANGE_GRANT_TYPEÚ_ID_TOKEN_TYPEr   r*   )r?   r@   r=   r-   s   $$$ r   Úexchange_oidc_tokenrH   c   sd   € ô" ‹}×!Ñ!Ø×)Ð)”y×)Ñ)Ð
*¨,Ð7àÔ4Ø ¤.Ø˜]Ø˜ð	
ð "ó €Hô ˜Ô!Ø�=‰=‹?Ðr   r?   c                ó®   € V ^8„  d   QhR\         R\         R,          R\        \         ,          R,          R\         R,          R\         R,          R\        /# )r   r@   r?   Nr/   r!   r=   r   )r"   r   rA   )r   s   "r   r   r   �   sc   € ÷ "bñ "bäð"bô ˜•:ð"bô œ�n˜tÕ#ð	"bô
 �D�jð"bô �D�jð"bô 
ñ"br   c                ó„   € T;'       g    \         P                  pVf   \        Y#;'       g    TR7      p\        WVR7      # )uj  Mint a CI OIDC id token and exchange it for a Hugging Face token.

Convenience wrapper around [`get_oidc_token`] + [`exchange_oidc_token`]. Returns the raw
exchange response (it does not persist anything â€” the caller decides what to do with the token).

Args:
    resource (`str`):
        Repo or username to scope the token to. See [`exchange_oidc_token`].
    subject_token (`str`, *optional*):
        A pre-minted OIDC id token to exchange directly. Use this for CI providers not yet
        supported natively (e.g. GitLab): mint the id token in your job and pass it here. When
        omitted, the token is minted from the detected `provider`.
    provider (`str`, *optional*):
        CI provider. Auto-detected when omitted. Ignored when `subject_token` is provided.
    audience (`str`, *optional*):
        The `aud` claim to request. Defaults to the resolved `endpoint`, so it matches the
        endpoint that validates it.
    endpoint (`str`, *optional*):
        Hub endpoint. Defaults to `constants.ENDPOINT`.

Returns:
    `dict`: The token-exchange response (`access_token`, `token_type`, `expires_in`, ...).
)r/   r!   )r?   r@   r=   )r   r8   r<   rH   )r@   r?   r/   r!   r=   s   $$$$$r   Ú
oidc_loginrK   �   s=   € ð> ×-Ð-œ9×-Ñ-€HØÒÜ&°×CWÐCWÈxÔXˆÜ¨]ÐX`ÔaÐar   )r   r   Úenumr   Ú r   Úerrorsr   Úutilsr   r   rF   rG   r"   r   r   r.   r<   rH   rK   r
   r   r   Ú<module>rP      s�   ðñó 
Ý å Ý ß 3ð OÐ Ø<€ôˆs�Dô õõ$ð.k¸ð kÐUY÷ kð.ÐUY÷ ð<"bð !%ð"bð '+ð	"bð
  ð"bð  ÷"bñ "br   