
    k7i~0                        S r SSKJr  SSKrSSKJr  SSKJrJrJ	r	  SSK
JrJr  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJrJr  \" \5      r " S S\5      r " S S\5      r " S S\5      r g)aT  GitHub OAuth provider for FastMCP.

This module provides a complete GitHub OAuth integration that's ready to use
with just a client ID and client secret. It handles all the complexity of
GitHub's OAuth flow, token validation, and user management.

Example:
    ```python
    from fastmcp import FastMCP
    from fastmcp.server.auth.providers.github import GitHubProvider

    # Simple GitHub OAuth protection
    auth = GitHubProvider(
        client_id="your-github-client-id",
        client_secret="your-github-client-secret"
    )

    mcp = FastMCP("My Protected Server", auth=auth)
    ```
    )annotationsN)AsyncKeyValue)
AnyHttpUrl	SecretStrfield_validator)BaseSettingsSettingsConfigDict)TokenVerifier)AccessToken)
OAuthProxy)ENV_FILEparse_scopes)
get_logger)NotSetNotSetTc                      \ rS rSr% Sr\" S\SS9rSrS\	S'   Sr
S	\	S
'   SrS\	S'   SrS\	S'   SrS\	S'   SrS\	S'   SrS\	S'   SrS\	S'   SrS\	S'   \" SSS9\S 5       5       rSrg)GitHubProviderSettings(   z#Settings for GitHub OAuth provider.FASTMCP_SERVER_AUTH_GITHUB_ignore)
env_prefixenv_fileextraNz
str | None	client_idzSecretStr | Noneclient_secretzAnyHttpUrl | str | Nonebase_url
issuer_urlredirect_pathlist[str] | Nonerequired_scopesz
int | Nonetimeout_secondsallowed_client_redirect_urisjwt_signing_keybefore)modec                    [        U5      $ )Nr   )clsvs     ^/home/james-whalen/.local/lib/python3.13/site-packages/fastmcp/server/auth/providers/github.py_parse_scopes$GitHubProviderSettings._parse_scopes;   s     A     )__name__
__module____qualname____firstlineno____doc__r	   r   model_configr   __annotations__r   r   r   r   r!   r"   r#   r$   r   classmethodr+   __static_attributes__r.   r-   r*   r   r   (   s    -%0L !Iz &*M#*(,H%,*.J'. $M:$(,O%,"&OZ&59 "29"&OZ&&X6  7r-   r   c                  J   ^  \ rS rSrSrSSS.   S	U 4S jjjrS
S jrSrU =r$ )GitHubTokenVerifierA   zToken verifier for GitHub OAuth tokens.

GitHub OAuth tokens are opaque (not JWTs), so we verify them
by calling GitHub's API to check if they're valid and get user info.
N
   r!   r"   c               ,   > [         TU ]  US9  X l        g)zInitialize the GitHub token verifier.

Args:
    required_scopes: Required OAuth scopes (e.g., ['user:email'])
    timeout_seconds: HTTP request timeout
)r!   N)super__init__r"   )selfr!   r"   	__class__s      r*   r?   GitHubTokenVerifier.__init__H   s     	9.r-   c                  #     [         R                  " U R                  S9 ISh  vN nUR                  SSU 3SSS.S9I Sh  vN nUR                  S	:w  a@  [
        R                  S
UR                  UR                  SS	 5         SSS5      ISh  vN   gUR                  5       nUR                  SSU 3SSS.S9I Sh  vN nUR                  R                  SS5      nUR                  S5       Vs/ s H*  nUR                  5       (       d  M  UR                  5       PM,     nnU(       d  S/nU R                  (       aq  [        U5      n	[        U R                  5      n
U
R                  U	5      (       d;  [
        R                  S[        U	5      [        U
5      5         SSS5      ISh  vN   g[!        U[#        UR                  SS5      5      US[#        US   5      UR                  S5      UR                  S5      UR                  S5      UR                  S5      US.S9sSSS5      ISh  vN   $  GN GN GN GNs  snf  N N! , ISh  vN  (       d  f       g= f! [         R$                   a   n[
        R                  SU5         SnAgSnAf[&         a   n[
        R                  SU5         SnAgSnAff = f7f)z0Verify GitHub OAuth token by calling GitHub API.)timeoutNzhttps://api.github.com/userzBearer zapplication/vnd.github.v3+jsonzFastMCP-GitHub-OAuth)AuthorizationAcceptz
User-Agent)headers   z)GitHub token verification failed: %d - %sz!https://api.github.com/user/reposzx-oauth-scopes ,userz6GitHub token missing required scopes. Has %d, needs %didunknownloginnameemail
avatar_url)subrN   rO   rP   rQ   github_user_data)tokenr   scopes
expires_atclaimsz!Failed to verify GitHub token: %sz#GitHub token verification error: %s)httpxAsyncClientr"   getstatus_codeloggerdebugtextjsonrG   splitstripr!   setissubsetlenr   strRequestError	Exception)r@   rT   clientresponse	user_datascopes_responseoauth_scopes_headerscopetoken_scopestoken_scopes_setrequired_scopes_setes               r*   verify_token GitHubTokenVerifier.verify_tokenW   s    N	((1E1EFF&!'1+25'):"B&< ", "  ''3.LLC ,, ds+
  # GFF& %MMO	 )/

7+25'):"B&< )3 ) # '6&=&=&A&ABRTV&W# "5!:!:3!? !?{{} "EKKM!?    $$*8L '''*<'8$*-d.B.B*C'.778HIIT 01 34
  $m GFFr #!)--i"@A'#"9T?3!*w!7 )f 5!*w!7&/mmL&A,5s GFF G.# E GFFFP !! 	LL<a@ 	LL>B	s  K"I, H=I, II AI	I, II, K*II3I8I	I	)A=I&I, 1I2I, 6K7A4I+I, 7I8I, <K=I,  II, I	II, I, I)II)%I, (K)I, ,K JKK(K>KKK)r"   )r!   r    r"   int)rT   re   returnzAccessToken | None)	r/   r0   r1   r2   r3   r?   rr   r7   __classcell__rA   s   @r*   r9   r9   A   s:     -1!	/ */ 	/ /P Pr-   r9   c                  v   ^  \ rS rSrSr\\\\\\\\S\SS.                     SU 4S jjjrSrU =r$ )	GitHubProvider   a  Complete GitHub OAuth provider for FastMCP.

This provider makes it trivial to add GitHub OAuth protection to any
FastMCP server. Just provide your GitHub OAuth app credentials and
a base URL, and you're ready to go.

Features:
- Transparent OAuth proxy to GitHub
- Automatic token validation via GitHub API
- User information extraction
- Minimal configuration required

Example:
    ```python
    from fastmcp import FastMCP
    from fastmcp.server.auth.providers.github import GitHubProvider

    auth = GitHubProvider(
        client_id="Ov23li...",
        client_secret="abc123...",
        base_url="https://my-server.com"
    )

    mcp = FastMCP("My App", auth=auth)
    ```
NT)r   r   r   r   r   r!   r"   r#   client_storager$   require_authorization_consentc                 > [         R                  UUUUUUUUU
S.	R                  5        VVs0 s H  u  pU[        Ld  M  X_M     snn5      nUR                  (       d  [        S5      eUR                  (       d  [        S5      eUR                  =(       d    SnUR                  =(       d    S/nUR                  n[        UUS9nUR                  (       a  UR                  R                  5       OSn[        TU ]5  SS	UR                  UUUR                  UR                  UR                   =(       d    UR                  UU	UR"                  US
9  [$        R'                  SUR                  U5        gs  snnf )a  Initialize GitHub OAuth provider.

Args:
    client_id: GitHub OAuth app client ID (e.g., "Ov23li...")
    client_secret: GitHub OAuth app client secret
    base_url: Public URL where OAuth endpoints will be accessible (includes any mount path)
    issuer_url: Issuer URL for OAuth metadata (defaults to base_url). Use root-level URL
        to avoid 404s during discovery when mounting under a path.
    redirect_path: Redirect path configured in GitHub OAuth app (defaults to "/auth/callback")
    required_scopes: Required GitHub scopes (defaults to ["user"])
    timeout_seconds: HTTP request timeout for GitHub API calls
    allowed_client_redirect_uris: List of allowed redirect URI patterns for MCP clients.
        If None (default), all URIs are allowed. If empty list, no URIs are allowed.
    client_storage: Storage backend for OAuth state (client registrations, encrypted tokens).
        If None, a DiskStore will be created in the data directory (derived from `platformdirs`). The
        disk store will be encrypted using a key derived from the JWT Signing Key.
    jwt_signing_key: Secret for signing FastMCP JWT tokens (any string or bytes). If bytes are provided,
        they will be used as is. If a string is provided, it will be derived into a 32-byte key. If not
        provided, the upstream client secret will be used to derive a 32-byte key using PBKDF2.
    require_authorization_consent: Whether to require user consent before authorizing clients (default True).
        When True, users see a consent screen before being redirected to GitHub.
        When False, authorization proceeds directly without user confirmation.
        SECURITY WARNING: Only disable for local development or testing environments.
)	r   r   r   r   r   r!   r"   r#   r$   zQclient_id is required - set via parameter or FASTMCP_SERVER_AUTH_GITHUB_CLIENT_IDzYclient_secret is required - set via parameter or FASTMCP_SERVER_AUTH_GITHUB_CLIENT_SECRETr;   rK   r<   rI   z(https://github.com/login/oauth/authorizez+https://github.com/login/oauth/access_token)upstream_authorization_endpointupstream_token_endpointupstream_client_idupstream_client_secrettoken_verifierr   r   r   r#   r{   r$   r|   z?Initialized GitHub OAuth provider for client %s with scopes: %sN)r   model_validateitemsr   r   
ValueErrorr   r"   r!   r#   r9   get_secret_valuer>   r?   r   r   r   r$   r\   r]   )r@   r   r   r   r   r   r!   r"   r#   r{   r$   r|   kr)   settingstimeout_seconds_finalrequired_scopes_final"allowed_client_redirect_uris_finalr   client_secret_strrA   s                       r*   r?   GitHubProvider.__init__   s   P *88 "+%2 (",%2'6'64P'6
 %'

DA F? 

& !!c  %%k  !) 8 8 >B ( 8 8 DVH-5-R-R* -11
 :B9O9OH""335UW 	
 	,V$Q'11#4)&&"00** !  )K)$44*G 	 	
  	M!	
{s   E4
E4
r.   )r   str | NotSetTr   r   r   AnyHttpUrl | str | NotSetTr   r   r   r   r!   list[str] | NotSetTr"   zint | NotSetTr#   r   r{   zAsyncKeyValue | Noner$   zstr | bytes | NotSetTr|   bool)	r/   r0   r1   r2   r3   r   r?   r7   rv   rw   s   @r*   ry   ry      s    < $*'-/517'-/5)/<B/317.2j
 !j
 %	j

 -j
 /j
 %j
 -j
 'j
 ':j
 -j
 /j
 (,j
 j
r-   ry   )!r3   
__future__r   rX   key_value.aio.protocolsr   pydanticr   r   r   pydantic_settingsr   r	   fastmcp.server.authr
   fastmcp.server.auth.authr   fastmcp.server.auth.oauth_proxyr   fastmcp.settingsr   fastmcp.utilities.authr   fastmcp.utilities.loggingr   fastmcp.utilities.typesr   r   r/   r\   r   r9   ry   r.   r-   r*   <module>r      sf   * #  1 ; ; > - 0 6 % / 0 3	H	\ 2f- fRF
Z F
r-   