Files
google-mcp/auth/__pycache__/google_auth.cpython-312.pyc

80 lines
13 KiB
Plaintext
Raw Normal View History

<EFBFBD>
<00>uhX;<00><00>D<00>ddlZddlZddlZddlmZmZmZmZmZm Z ddl
m Z ddl m Z mZddlmZddlmZddlmZddlmZej.ej0<00> <09>ej2e<1A>Zd
Zd Zd Zefd ededefd<10>Z efd ede defd<12>Z!efd ededee fd<13>Z"dedeeeffd<15>Z#eddefdedeedede$dee de%deeeffd<1C>Z&eefdedeededededeee ff d<1F>Z'defd ed eedeededee f
d!<21>Z(de deeeeffd"<22>Z)ed#k(r d$Z*d%d&gZ+d'Z,yy)(<28>N)<06>List<73>Optional<61>Tuple<6C>Dict<63>Any<6E>Callable)<01> Credentials)<02>Flow<6F>InstalledAppFlow)<01>Request)<01>build)<01> HttpError)<01>OAuthCallbackServer)<01>levelz .credentialszhttp://localhost:8080/callbacki<6B><00>user_id<69>base_dir<69>returnc<00><><00>tjj|<01>s-tj|<01>tj d|<01><00><02>tjj ||<00>d<02><02>S)z0Constructs the path to a user's credential file.zCreated credentials directory: z.json)<07>os<6F>path<74>exists<74>makedirs<72>logger<65>info<66>join)rrs <20>A/Users/taylorwilsdon/git/google_workspace_mcp/auth/google_auth.py<70>_get_user_credential_pathrsN<00><00> <0A>7<EFBFBD>7<EFBFBD>><3E>><3E>(<28> #<23>
<EFBFBD> <0B> <0B>H<EFBFBD><1D><0E> <0B> <0B>5<>h<EFBFBD>Z<EFBFBD>@<40>A<> <0A>7<EFBFBD>7<EFBFBD><<3C><<3C><08>W<EFBFBD>I<EFBFBD>U<EFBFBD>"3<> 4<>4<><00> credentialsc <00><><00>t||<02>}|j|j|j|j|j
|j d<01>} t|d<02>5}tj||<05>ddd<03>tjd|<00>d|<03><00><04>y#1swY<00>%xYw#t$r$}tjd|<00>d|<03>d|<06><00><06><00>d}~wwxYw)z!Saves user credentials to a file.<2E><06>token<65> refresh_token<65> token_uri<72> client_id<69> client_secret<65>scopes<65>wNzCredentials saved for user z to z"Error saving credentials for user <20>: )rr"r#r$r%r&r'<00>open<65>json<6F>dumprr<00>IOError<6F>error)rrr<00>
creds_path<EFBFBD>
creds_data<EFBFBD>f<>es r<00>_save_credentialsr3"s<><00><00>*<2A>7<EFBFBD>H<EFBFBD>=<3D>J<EFBFBD><1C>"<22>"<22>$<24>2<>2<> <20>*<2A>*<2A> <20>*<2A>*<2A>$<24>2<>2<><1D>$<24>$<24> <06>J<EFBFBD><0E> <11>*<2A>c<EFBFBD> "<22>a<EFBFBD> <10>I<EFBFBD>I<EFBFBD>j<EFBFBD>!<21> $<24>#<23><0E> <0B> <0B>1<>'<27><19>$<24>z<EFBFBD>l<EFBFBD>K<>L<>#<23> "<22><> <13><0E><0E> <0C> <0C>9<>'<27><19>$<24>z<EFBFBD>l<EFBFBD>RT<52>UV<55>TW<54>X<>Y<> <0A><><0E>s0<00> B&<00>B<03>6#B&<00>B#<07>B&<00>& C<03>/C<03>Cc
<00><><00>t||<01>}tjj|<02>stj d|<00>d|<02><00><04>y t |d<04>5}tj|<03>}ddd<03>tjd<05>|jd<06>|jd<07>|jd<08>|jd <09>|jd
<EFBFBD><00> <0B>}tj d |<00>d |<02><00><04>|S#1swY<00><>xYw#ttjtf$r(}tjd|<00>d |<02>d|<06><00><06>Yd}~yd}~wwxYw)z#Loads user credentials from a file.z#No credentials file found for user z at N<>rr"r#r$r%r&r'r!zCredentials loaded for user z from z.Error loading or parsing credentials for user r))rrrrrrr*r+<00>loadr <00>getr-<00>JSONDecodeError<6F>KeyErrorr.)rrr/r1r0rr2s r<00>_load_credentialsr:5s#<00><00>*<2A>7<EFBFBD>H<EFBFBD>=<3D>J<EFBFBD> <0A>7<EFBFBD>7<EFBFBD>><3E>><3E>*<2A> %<25><0E> <0B> <0B>9<>'<27><19>$<24>z<EFBFBD>l<EFBFBD>S<>T<><13><14> <11>*<2A>c<EFBFBD> "<22>a<EFBFBD><1D><19><19>1<EFBFBD><1C>J<EFBFBD>#<23>"<22><1C>.<2E>.<2E><17>)<29>$<24>.<2E>.<2E><1F>9<> <20>n<EFBFBD>n<EFBFBD>[<5B>1<> <20>n<EFBFBD>n<EFBFBD>[<5B>1<>$<24>.<2E>.<2E><1F>9<><1D>><3E>><3E>(<28>+<2B> 
<EFBFBD> <0B> <0F> <0B> <0B>2<>7<EFBFBD>)<29>6<EFBFBD>*<2A><1C>N<>O<><1A><1A>#<23> "<22><> <14>T<EFBFBD>)<29>)<29>8<EFBFBD> 4<><14><0E> <0C> <0C>E<>g<EFBFBD>Y<EFBFBD>f<EFBFBD>U_<55>T`<60>`b<>cd<63>be<62>f<>g<><13><><14>s1<00> D<00>C;<03>+BD<00>;D<07>D<00>E <03>%E<03>E <03>client_secrets_pathc<00>j<00> t|d<01>5}tj|<01>}d|vr|dcddd<03>Sd|vr|dcddd<03>Stj d|<00>d<06><03>t d<07><00>#1swYyxYw#t tjf$r!}tj d|<00>d |<03><00><04><00>d}~wwxYw)
zLoads the client secrets file.r5<00>webN<62> installedzClient secrets file z has unexpected format.z"Invalid client secrets file formatz"Error loading client secrets file r))r*r+r6rr.<00>
ValueErrorr-r8)r;r1<00> client_configr2s r<00>load_client_secretsrAOs<><00><00> <0E> <11>%<25>s<EFBFBD> +<2B>q<EFBFBD> <20>I<EFBFBD>I<EFBFBD>a<EFBFBD>L<EFBFBD>M<EFBFBD><14> <0A>%<25>$<24>U<EFBFBD>+<2B> ,<2C> +<2B>
<1D> <0A>-<2D>%<25>k<EFBFBD>2<> ,<2C> +<2B><18><1C><1C> 4<>5H<35>4I<34>I`<60>a<>b<>!<21>"F<>G<>G<>,<2C> +<2B><> <14>T<EFBFBD>)<29>)<29> *<2A><0E><0E> <0C> <0C>9<>:M<>9N<39>b<EFBFBD>QR<51>PS<50>T<>U<> <0A><><0E>sC<00> A8<00>A,<03> A8<00>A,<03> A8<00>$A,<03>,A5<07>1A8<00>5A8<00>8B2<03>B-<03>-B2Fr'<00> redirect_uri<72>auto_handle_callback<63>callback_function<6F>portc<00><><00> d}|r3tjd<02>t||d<03><04>}|j<00>t j
|||<02><05>}|j dd<07><08>\}} tjd | <09><00><02>|r|r|j|<08>|| fS#t$r2}
tjd
|
<EFBFBD><00><02>|rr|j<00><00>d}
~
wwxYw) a<>
Initiates the OAuth 2.0 flow and returns the authorization URL and state.
Args:
client_secrets_path: Path to the Google client secrets JSON file.
scopes: List of OAuth scopes required.
redirect_uri: The URI Google will redirect to after authorization.
auto_handle_callback: Whether to automatically handle the callback by
starting a local server on the specified port.
callback_function: Function to call with the code and state when received.
port: Port to run the callback server on, if auto_handle_callback is True.
Returns:
A tuple containing the authorization URL and the state parameter.
NzStarting OAuth callback serverF)rE<00>callback<63>auto_open_browser<65>r'rB<00>offline<6E>consent)<02> access_type<70>promptz$Generated authorization URL. State: zError starting OAuth flow: ) rrr<00>startr
<00>from_client_secrets_file<6C>authorization_url<72> open_browser<65> Exceptionr.<00>stop) r;r'rBrCrDrE<00>server<65>flowrP<00>stater2s r<00>start_auth_flowrWbs<><00><00>.$<0E><15><06> <1F> <12>K<EFBFBD>K<EFBFBD>8<> 9<>(<28>d<EFBFBD>=N<>bg<62>h<>F<EFBFBD> <12>L<EFBFBD>L<EFBFBD>N<EFBFBD><14>,<2C>,<2C> <1F><19>%<25>
<EFBFBD><04>$(<28>#9<>#9<>!<21><1C>$:<3A>$
<EFBFBD> <20><19>5<EFBFBD> <0F> <0B> <0B>:<3A>5<EFBFBD>'<27>B<>C<> <20>F<EFBFBD> <12> <1F> <1F> 1<> 2<> <20>%<25>'<27>'<27><> <14><0E><0E> <0C> <0C>2<>1<EFBFBD>#<23>6<>7<> <1F>F<EFBFBD> <12>K<EFBFBD>K<EFBFBD>M<EFBFBD> <0A><> <0E>s<00>BB<00> C<03>!-C<03>C<03>authorization_response<73>credentials_base_dirc<00><><00> tj|||<03><01>}|j|<02><02>|j}tj d<03>t |<06>}|rd|vr tjd<05>td<06><00>|d}tj d|<08><00><02>t|||<04>||fS#t$r} tjd| <09><00><02><00>d } ~ wwxYw)
aX
Handles the callback from Google, exchanges the code for credentials,
fetches user info, determines user_id, saves credentials, and returns them.
Args:
client_secrets_path: Path to the Google client secrets JSON file.
scopes: List of OAuth scopes requested (should match `start_auth_flow`).
authorization_response: The full callback URL received from Google.
redirect_uri: The redirect URI configured in the Google Cloud Console and used in start_auth_flow.
credentials_base_dir: Base directory to store credential files.
Returns:
A tuple containing the user_id (email) and the obtained Credentials object.
Raises:
ValueError: If the state is missing or doesn't match.
FlowExchangeError: If the code exchange fails.
HttpError: If fetching user info fails.
rI)rXz5Successfully exchanged authorization code for tokens.<2E>emailz*Could not retrieve user email from Google.z,Failed to get user email for identification.zIdentified user ID: zError handling auth callback: N) r
rO<00> fetch_tokenrrr<00> get_user_infor.r?r3rR)
r;r'rXrBrYrUr<00> user_inforr2s
r<00>handle_auth_callbackr_<00>s<><00><00>4<0E><13>,<2C>,<2C> <1F><19>%<25>
<EFBFBD><04> <0A><18><18>0F<30><18>G<><1A>&<26>&<26> <0B><0E> <0B> <0B>K<>L<>"<22>+<2B>.<2E> <09><18>G<EFBFBD>9<EFBFBD>4<> <13>\<5C>\<5C>F<> G<><1D>L<>M<> M<><1B>G<EFBFBD>$<24><07><0E> <0B> <0B>*<2A>7<EFBFBD>)<29>4<>5<> <1A>'<27>;<3B>0D<30>E<><16> <0B>#<23>#<23><> <14><0E><0E> <0C> <0C>5<>a<EFBFBD>S<EFBFBD>9<>:<3A> <0A><><0E>s<00>B)B,<00>, C<03>5C<03>C<03>required_scopesc<00><><00><06>t||<03><00><06>stjd|<00>d<02><03>yt<00>fd<04>|D<00><00>s)tj d|<00>d|<01>d<07>j
<00><00><06>y<03>j rtjd|<00>d<08><03><00>S<00>jr<><72>jr~tjd |<00>d
<EFBFBD><03>|stjd <0B>y t|<02>}<04>jt<00><00>tjd |<00>d <0C><03>t|<00>|<03><00>Stj d |<00>d<0F><03>y#t$r%}tjd |<00>d|<05><00><04>Yd}~yd}~wwxYw)a<>
Retrieves stored credentials for a user, refreshes if necessary.
Args:
user_id: The unique identifier for the user (e.g., email).
required_scopes: List of scopes the credentials must have.
client_secrets_path: Path to client secrets, required *only* if refresh might be needed.
credentials_base_dir: Base directory where credential files are stored.
Returns:
Valid Credentials object if found and valid/refreshed, otherwise None.
z%No stored credentials found for user <20>.Nc3<00>:<00>K<00>|]}|<01>jv<00><01><00>y<00>w)N)r')<03>.0<EFBFBD>scopers <20>r<00> <genexpr>z"get_credentials.<locals>.<genexpr><3E>s<00><><00><><00>H<><0F>u<EFBFBD>u<EFBFBD> <0B>*<2A>*<2A>*<2A><0F>s<00>zStored credentials for user z lack required scopes. Need: z, Have: z are valid.zCredentials for user z expired. Attempting refresh.zLClient secrets path is required to refresh credentials but was not provided.z refreshed successfully.z&Error refreshing credentials for user r)z& are invalid or missing refresh token.)r:rr<00>all<6C>warningr'<00>valid<69>expiredr#r.rA<00>refreshr r3rR)rr`r;rYr@r2rs @r<00>get_credentialsrl<00>s|<00><><00>$$<24>G<EFBFBD>-A<>B<>K<EFBFBD> <16><0E> <0B> <0B>;<3B>G<EFBFBD>9<EFBFBD>A<EFBFBD>F<>G<><13> <0F>H<><0F>H<> H<><0E><0E><0E>5<>g<EFBFBD>Y<EFBFBD>>[<5B>\k<>[l<>lt<6C>vA<02>vH<02>vH<02>uI<02>J<02> K<02><13><13><18><18><0E> <0B> <0B>2<>7<EFBFBD>)<29>;<3B>G<>H<><1A><1A> <14> <1C> <1C><1B>!:<3A>!:<3A><0E> <0B> <0B>+<2B>G<EFBFBD>9<EFBFBD>4Q<34>R<>S<>"<22> <13>\<5C>\<5C>h<> i<><18> <18>0<>0C<30>D<>M<EFBFBD> <17> <1F> <1F><07> <09> *<2A> <12>K<EFBFBD>K<EFBFBD>/<2F><07>y<EFBFBD>8P<38>Q<> R<> <1D>g<EFBFBD>{<7B>4H<34> I<><1E> <1E> <0F><0E><0E>.<2E>w<EFBFBD>i<EFBFBD>7]<5D>^<5E>_<><13><><19> <18> <12>L<EFBFBD>L<EFBFBD>A<>'<27><19>"<22>Q<EFBFBD>C<EFBFBD>P<> Q<><17><> <18>s<00>A D><00>> E,<03>E'<03>'E,c<00><><00>|r |jstjd<01>y tdd|<00><05>}|j <00>j <00>j <00>}tjd|j d<07><00><00><02>|S#t$r9}tjd|j<00>d |j<00><00><04>Yd}~yd}~wt$r"}tjd
|<03><00><02>Yd}~yd}~wwxYw) zGFetches basic user profile information (requires userinfo.email scope).z5Cannot get user info: Invalid or missing credentials.N<>oauth2<68>v2)rz Successfully fetched user info: r[zHttpError fetching user info: <20> z%Unexpected error fetching user info: ) rirr.r <00>userinfor7<00>executerr<00> status_code<64>reasonrR)r<00>servicer^r2s rr]r]s<><00><00> <16>k<EFBFBD>/<2F>/<2F><0E> <0C> <0C>L<>M<><13> <14><18><08>$<24>K<EFBFBD>@<40><07><1B>$<24>$<24>&<26>*<2A>*<2A>,<2C>4<>4<>6<> <09><0E> <0B> <0B>6<>y<EFBFBD>}<7D>}<7D>W<EFBFBD>7M<37>6N<36>O<>P<><18><18><> <14><14><0E> <0C> <0C>5<>a<EFBFBD>m<EFBFBD>m<EFBFBD>_<EFBFBD>A<EFBFBD>a<EFBFBD>h<EFBFBD>h<EFBFBD>Z<EFBFBD>P<>Q<><13><> <14><14><0E> <0C> <0C><<3C>Q<EFBFBD>C<EFBFBD>@<40>A<><13><><14>s$<00>A"B <00> C4<03>/C<03> C4<03>C/<03>/C4<03>__main__z path/to/your/client_secrets.jsonz.https://www.googleapis.com/auth/userinfo.emailz1https://www.googleapis.com/auth/calendar.readonlyztest.user@example.com)-rr+<00>logging<6E>typingrrrrrr<00>google.oauth2.credentialsr <00>google_auth_oauthlib.flowr
r <00>google.auth.transport.requestsr <00>googleapiclient.discoveryr <00>googleapiclient.errorsr<00>auth.callback_serverr<00> basicConfig<69>INFO<46> getLogger<65>__name__r<00>DEFAULT_CREDENTIALS_DIR<49>DEFAULT_REDIRECT_URI<52>DEFAULT_SERVER_PORT<52>strrr3r:rA<00>bool<6F>intrWr_rlr]<00>_CLIENT_SECRETS_FILE<4C>_SCOPES<45> _TEST_USER_ID<49>rr<00><module>r<>s:<00><01>
<EFBFBD> <0B><0E>=<3D>=<3D>1<><<3C>2<>+<2B>,<2C>4<><14><07><13><13>'<27>,<2C>,<2C>'<27> <1A><17> <1A> <1A>8<EFBFBD> $<24><06>)<29><17>7<><14><1A><13>=T<01>5<>s<EFBFBD>5<>c<EFBFBD>5<>X[<5B>5<>Of<01><0E>s<EFBFBD><0E><1B><0E><03><0E>&5L<01><14>s<EFBFBD><14>c<EFBFBD><14>PX<50>Yd<59>Pe<50><14>4<0E>S<EFBFBD><0E>T<EFBFBD>#<23>s<EFBFBD>(<28>^<5E><0E>,-<2D>!&<26>,0<>#<23> ;<0E><1C>;<0E> <10><13>I<EFBFBD>;<0E><16>;<0E><1F> ;<0E>
 <20><08>)<29> ;<0E> <0E> ;<0E> <0B>3<EFBFBD><03>8<EFBFBD>_<EFBFBD>;<0E>B-<2D> 7<> 7<0E><1C>7<0E> <10><13>I<EFBFBD>7<0E> <20>7<0E><16> 7<0E>
<1E> 7<0E>  <0B>3<EFBFBD> <0B> <1B><1C> 7<0E>x*.<2E> 7<> 9<14> <10>9<14><19>#<23>Y<EFBFBD>9<14>"<22>#<23><1D>9<14><1E> 9<14>
<0E>k<EFBFBD><1A> 9<14>x<14>{<7B><14>x<EFBFBD><04>S<EFBFBD>#<23>X<EFBFBD><0E>/G<><14>* <0C>z<EFBFBD><19>><3E><18>?<3F>At<41>u<>G<EFBFBD>+<2B>M<EFBFBD>R <09>]r