Free and open source ticket system written in python
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at 5edd527aaba4e33b526f04f58d0db2b8a4ef278e 46 lines 1.6 kB view raw
1from dataclasses import dataclass 2from typing import Any, Optional 3 4from django.utils.translation import gettext_lazy as _ 5from google.oauth2.credentials import Credentials 6from google_auth_oauthlib.flow import Flow 7from django.conf import settings 8 9 10@dataclass 11class GoogleSSO: 12 _flow: Optional[Flow] = None 13 _userinfo: Optional[dict[Any, Any]] = None 14 15 @staticmethod 16 def get_client_config() -> Credentials: 17 return { 18 "web": { 19 "client_id": settings.GOOGLE_OAUTH_CLIENT_ID, 20 "project_id": settings.GOOGLE_OAUTH_PROJECT_ID, 21 "auth_uri": "https://accounts.google.com/o/oauth2/auth", 22 "token_uri": "https://oauth2.googleapis.com/token", 23 "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", 24 "client_secret": settings.GOOGLE_OAUTH_CLIENT_SECRET, 25 "redirect_uris": [settings.GOOGLE_OAUTH_REDIRECT_URI], 26 } 27 } 28 29 @property 30 def flow(self) -> Flow: 31 if not self._flow: 32 self._flow = Flow.from_client_config( 33 self.get_client_config(), 34 scopes=settings.GOOGLE_OAUTH_SCOPES, 35 redirect_uri=settings.GOOGLE_OAUTH_REDIRECT_URI 36 ) 37 return self._flow 38 39 def get_user_info(self) -> dict: 40 session = self.flow.authorized_session() 41 user_info = session.get( 42 "https://www.googleapis.com/oauth2/v2/userinfo").json() 43 return user_info 44 45 def get_user_token(self): 46 return self.flow.credentials.token