35 lines
1019 B
Python
35 lines
1019 B
Python
from typing import Any
|
|
|
|
from .base import OAuthProvider
|
|
|
|
|
|
class GoogleOAuthProvider(OAuthProvider):
|
|
"""Google OAuth provider implementation."""
|
|
|
|
@property
|
|
def name(self) -> str:
|
|
return "google"
|
|
|
|
@property
|
|
def display_name(self) -> str:
|
|
return "Google"
|
|
|
|
def get_client_config(self) -> dict[str, Any]:
|
|
"""Return Google OAuth client configuration."""
|
|
return {
|
|
"server_metadata_url": "https://accounts.google.com/.well-known/openid-configuration",
|
|
"client_kwargs": {"scope": "openid email profile"},
|
|
}
|
|
|
|
def get_user_info(self, token: dict[str, Any]) -> dict[str, Any]:
|
|
"""Extract user information from Google OAuth token response."""
|
|
client = self.get_client()
|
|
user_info = client.userinfo(token=token)
|
|
|
|
return {
|
|
"id": user_info.get("sub"),
|
|
"email": user_info.get("email"),
|
|
"name": user_info.get("name"),
|
|
"picture": user_info.get("picture"),
|
|
}
|