oauth.py


Overview

The oauth.py file provides a lightweight, reusable OAuth 2.0 client implementation designed to facilitate user authentication and authorization flows within the InfiniFlow system. It encapsulates the process of generating OAuth authorization URLs, exchanging authorization codes for access tokens, and fetching normalized user profile information from OAuth providers.

This file primarily contains two classes:

The module leverages the requests library for HTTP communication and urllib.parse for URL parameter encoding. It is intended to be integrated into authentication components of the larger application, enabling secure and standardized OAuth-based user login and data retrieval from external providers.


Classes and Methods

Class: UserInfo

Represents normalized user profile information retrieved from an OAuth provider.

Attributes

Attribute

Type

Description

email

str

User's email address

username

str

Username identifier

nickname

str

User's display nickname

avatar_url

str

URL to the user's avatar or profile picture

Methods


Class: OAuthClient

Handles OAuth 2.0 authorization flows and user info retrieval.

Initialization

oauth_client = OAuthClient(config)

Methods


Important Implementation Details


Interaction with Other System Components


Visual Diagram

classDiagram
    class UserInfo {
        +email: str
        +username: str
        +nickname: str
        +avatar_url: str
        +to_dict() dict
    }

    class OAuthClient {
        -client_id: str
        -client_secret: str
        -authorization_url: str
        -token_url: str
        -userinfo_url: str
        -redirect_uri: str
        -scope: str
        -http_request_timeout: int
        +get_authorization_url(state=None) str
        +exchange_code_for_token(code) dict
        +fetch_user_info(access_token, **kwargs) UserInfo
        +normalize_user_info(user_info) UserInfo
    }

    OAuthClient o-- UserInfo : uses

Summary

The oauth.py file is a core utility module that encapsulates OAuth 2.0 client functionality, simplifying the integration of third-party OAuth providers for user authentication and profile retrieval. Its design focuses on clean abstraction, error handling, and normalization to support robust and flexible authentication workflows within the InfiniFlow platform.