taolib.testing.oauth.providers.google#

Google OAuth 提供商实现模块。

实现 Google OAuth2 + OpenID Connect 流程。

Attributes#

Classes#

GoogleOAuthProvider

Google OAuth 提供商。

Module Contents#

taolib.testing.oauth.providers.google.GOOGLE_AUTH_URL = 'https://accounts.google.com/o/oauth2/v2/auth'#
taolib.testing.oauth.providers.google.GOOGLE_TOKEN_URL = 'https://oauth2.googleapis.com/token'#
taolib.testing.oauth.providers.google.GOOGLE_USERINFO_URL = 'https://www.googleapis.com/oauth2/v2/userinfo'#
taolib.testing.oauth.providers.google.GOOGLE_REVOKE_URL = 'https://oauth2.googleapis.com/revoke'#
taolib.testing.oauth.providers.google.GOOGLE_DEFAULT_SCOPES = ['openid', 'email', 'profile']#
taolib.testing.oauth.providers.google.HTTP_TIMEOUT = 10.0#
class taolib.testing.oauth.providers.google.GoogleOAuthProvider#

Google OAuth 提供商。

provider_name: str#
get_authorize_url(client_id: str, redirect_uri: str, state: str, scopes: list[str]) str#

生成 Google 授权 URL。

参数:
  • client_id -- Google Client ID

  • redirect_uri -- 回调 URI

  • state -- CSRF 防护 state 参数

  • scopes -- 请求的权限范围

返回:

完整的 Google 授权 URL

async exchange_code(code: str, client_id: str, client_secret: str, redirect_uri: str) dict[str, Any]#

用授权码交换 Google Token。

参数:
  • code -- 授权码

  • client_id -- Google Client ID

  • client_secret -- Google Client Secret

  • redirect_uri -- 回调 URI

返回:

Token 响应字典

抛出:

OAuthCodeExchangeError -- 交换失败

async fetch_user_info(access_token: str) taolib.testing.oauth.models.profile.OAuthUserInfo#

获取 Google 用户信息。

参数:

access_token -- Google Access Token

返回:

标准化的用户信息

抛出:

OAuthUserInfoError -- 获取失败

async refresh_access_token(refresh_token: str, client_id: str, client_secret: str) dict[str, Any]#

刷新 Google Access Token。

参数:
  • refresh_token -- Refresh Token

  • client_id -- Google Client ID

  • client_secret -- Google Client Secret

返回:

新的 Token 响应

抛出:

OAuthCodeExchangeError -- 刷新失败

async revoke_token(token: str, client_id: str, client_secret: str) bool#

撤销 Google Token。

参数:
  • token -- 要撤销的令牌

  • client_id -- Google Client ID(未使用)

  • client_secret -- Google Client Secret(未使用)

返回:

是否成功撤销