### Installation and Running the FastAPI Example Source: https://github.com/aliev/aioauth/blob/master/docs/sections/quick_start/index.md Steps to clone the aioauth repository, install dependencies, and run the FastAPI example server. ```bash git clone git@github.com:aliev/aioauth.git cd aioauth/examples pip install -r requirements.txt python3 fastapi_example.py ``` -------------------------------- ### FastAPI Project Setup Source: https://github.com/aliev/aioauth/blob/master/examples/README.md Instructions to set up and run the FastAPI example project. This involves navigating to the 'fastapi' directory, installing dependencies, and executing the main Python script. ```bash cd fastapi pip install -r requirements.txt python3 fastapi_example.py ``` -------------------------------- ### Project Setup and Development Installation Source: https://github.com/aliev/aioauth/blob/master/CONTRIBUTING.md Steps to clone the aioauth repository, set up a Python virtual environment, and install development dependencies using the provided Makefile. This ensures the environment is ready for development and adheres to project standards. ```bash git clone git@github.com:aliev/aioauth.git cd aioauth python -mvenv env source env/bin/activate make dev-install ``` -------------------------------- ### Initiating an Authorization Code Request Source: https://github.com/aliev/aioauth/blob/master/docs/sections/quick_start/index.md Example URL to initiate an OAuth 2.0 authorization code request to the example server. ```http http://localhost:8000/oauth/authorize?client_id=test_client&redirect_uri=https%3A%2F%2Fwww.example.com%2Fredirect&response_type=code&state=somestate&scope=email ``` -------------------------------- ### Install aioauth Pre-release Source: https://github.com/aliev/aioauth/blob/master/docs/index.md Installs the latest pre-release version of aioauth directly from its GitHub repository. This is useful for testing upcoming features. ```bash pip install git+https://github.com/aliev/aioauth ``` -------------------------------- ### Install aioauth Source: https://github.com/aliev/aioauth/blob/master/docs/index.md Installs the aioauth package using pip. This command is used to add the library to your Python environment. ```bash pip install aioauth ``` -------------------------------- ### Success Response Example Source: https://github.com/aliev/aioauth/blob/master/docs/sections/quick_start/index.md Example of a successful redirect response from the OAuth server, including the authorization code. ```http https://www.example.com/redirect?state=somestate&code=EJKOGQhY7KcWjNGI2UbCnOrqAGtRiCEJnAYNwYJ8M5&scope=email ``` -------------------------------- ### Install aioauth Source: https://github.com/aliev/aioauth/blob/master/README.md Installs the aioauth package using pip. This command is used to add the asynchronous OAuth 2.0 framework to your Python project. ```bash python -m pip install aioauth ``` -------------------------------- ### Error Response Example Source: https://github.com/aliev/aioauth/blob/master/docs/sections/quick_start/index.md Example of an error response redirect from the OAuth server when a request fails or is denied. ```http https://www.example.com/redirect?error=access_denied&state=somestate ``` -------------------------------- ### OAuth Authorization Request Source: https://github.com/aliev/aioauth/blob/master/examples/README.md Example of an initial OAuth 2.0 authorization code request to the server. This URL includes parameters like client ID, redirect URI, response type, state, and scope. ```http http://localhost:8000/oauth/authorize?client_id=test_client&redirect_uri=https%3A%2F%2Fwww.example.com%2Fredirect&response_type=code&state=somestate&scope=email ``` -------------------------------- ### Code Formatting and Pre-commit Hooks Source: https://github.com/aliev/aioauth/blob/master/CONTRIBUTING.md Commands to automatically format code according to the project's styling guide using pre-commit. This ensures consistency and quality across the codebase before commits are made. ```bash pre-commit run --all-files ``` -------------------------------- ### OAuth Success Response Source: https://github.com/aliev/aioauth/blob/master/examples/README.md An example of a successful OAuth 2.0 authorization code grant response. The server redirects to the client's specified URI with an authorization code and state. ```http https://www.example.com/redirect?state=somestate&code=EJKOGQhY7KcWjNGI2UbCnOrqAGtRiCEJnAYNwYJ8M5&scope=email ``` -------------------------------- ### OAuth Error Response Source: https://github.com/aliev/aioauth/blob/master/examples/README.md An example of an error response from the OAuth server during the authorization flow. This typically occurs if the client request is invalid or the resource owner denies access. ```http https://www.example.com/redirect?error=access_denied&state=somestate ``` -------------------------------- ### Refreshing an Access Token Source: https://github.com/aliev/aioauth/blob/master/docs/sections/quick_start/index.md Using cURL to refresh an expired access token using a refresh token. ```bash curl localhost:8000/oauth/tokenize \ -u 'test_client:password' \ -d 'grant_type=refresh_token' \ -d 'refresh_token=iJD7Yf4SFuSljmXOhyfjfZelc5J0uIe2P4hwGm4wORCDJyrT' ``` -------------------------------- ### Requesting an Access Token with Authorization Code Source: https://github.com/aliev/aioauth/blob/master/docs/sections/quick_start/index.md Using cURL to exchange an authorization code for an access token and refresh token at the token endpoint. ```bash curl localhost:8000/oauth/tokenize \ -u 'test_client:password' \ -d 'grant_type=authorization_code' \ -d 'code=EJKOGQhY7KcWjNGI2UbCnOrqAGtRiCEJnAYNwYJ8M5'\ -d 'redirect_uri=https://www.example.com/redirect' ``` -------------------------------- ### Access Token Response Source: https://github.com/aliev/aioauth/blob/master/docs/sections/quick_start/index.md JSON response from the token endpoint containing access token, refresh token, and their expiration times. ```json { "expires_in": 300, "refresh_token_expires_in": 900, "access_token": "TIQdQv5FCyBoFtoeGt1tAJ37EJdggl8xgSvCVbdjqD", "refresh_token": "iJD7Yf4SFuSljmXOhyfjfZelc5J0uIe2P4hwGm4wORCDJyrT", "scope": "email", "token_type": "Bearer" } ``` -------------------------------- ### Request Access Token with Authorization Code Source: https://github.com/aliev/aioauth/blob/master/examples/README.md Using cURL to exchange an authorization code for an access token and refresh token. This request is made to the token endpoint and includes client credentials, grant type, authorization code, and redirect URI. ```bash curl localhost:8000/oauth/tokenize \ -u 'test_client:password' \ -d 'grant_type=authorization_code' \ -d 'code=EJKOGQhY7KcWjNGI2UbCnOrqAGtRiCEJnAYNwYJ8M5'\ -d 'redirect_uri=https://www.example.com/redirect' ``` -------------------------------- ### Token Response Source: https://github.com/aliev/aioauth/blob/master/examples/README.md The JSON response from the token endpoint after a successful authorization code exchange. It includes access token, refresh token, expiration times, and scope. ```json { "expires_in": 300, "refresh_token_expires_in": 900, "access_token": "TIQdQv5FCyBoFtoeGt1tAJ37EJdggl8xgSvCVbdjqD", "refresh_token": "iJD7Yf4SFuSljmXOhyfjfZelc5J0uIe2P4hwGm4wORCDJyrT", "scope": "email", "token_type": "Bearer" } ``` -------------------------------- ### Refresh Access Token Source: https://github.com/aliev/aioauth/blob/master/examples/README.md Using cURL to refresh an expired access token using a refresh token. This request is made to the token endpoint with the grant type set to 'refresh_token' and includes the refresh token. ```bash curl localhost:8000/oauth/tokenize \ -u 'test_client:password' \ -d 'grant_type=refresh_token' \ -d 'refresh_token=iJD7Yf4SFuSljmXOhyfjfZelc5J0uIe2P4hwGm4wORCDJyrT' ``` -------------------------------- ### Running Project Tests and Coverage Check Source: https://github.com/aliev/aioauth/blob/master/CONTRIBUTING.md Command to execute the project's test suite and view the code coverage report. The project requires a minimum coverage of 99%. ```bash make test ``` -------------------------------- ### aioauth.server Module Overview Source: https://github.com/aliev/aioauth/blob/master/docs/sections/api/server.md Provides the core server-side logic for handling OAuth 2.0 requests and responses. This includes classes for managing clients, tokens, and authorization flows. ```APIDOC aioauth.server: Provides classes and functions for implementing an OAuth 2.0 authorization server. Core Components: - AuthorizationServer: Manages the overall OAuth 2.0 flow, including authorization requests, token issuance, and introspection. - ClientManager: Handles client registration, validation, and retrieval. - TokenManager: Manages the creation, validation, and revocation of access and refresh tokens. - GrantManager: Manages different OAuth 2.0 grant types (e.g., authorization code, client credentials). - ScopeManager: Handles scope validation and management. Key Methods/Classes: AuthorizationServer: __init__(client_manager, token_manager, grant_manager, scope_manager, ...) Initializes the authorization server with necessary managers. handle_authorization_request(request, ...) Processes an incoming authorization request. handle_token_request(request, ...) Processes an incoming token request. handle_introspection_request(request, ...) Processes an incoming token introspection request. ClientManager: register_client(client_id, client_secret, redirect_uris, ...) Registers a new OAuth 2.0 client. get_client(client_id) Retrieves client information by client ID. validate_client(client_id, client_secret, ...) Validates client credentials. TokenManager: create_access_token(client_id, user_id, scopes, ...) Generates a new access token. create_refresh_token(client_id, user_id, scopes, ...) Generates a new refresh token. validate_token(token, ...) Validates an access token. revoke_token(token, ...) Revokes a token. GrantManager: create_authorization_code(client_id, user_id, redirect_uri, scopes, ...) Creates an authorization code. validate_authorization_code(code, ...) Validates an authorization code. exchange_authorization_code(code, ...) Exchanges an authorization code for tokens. Usage Example: from aioauth.server import AuthorizationServer from aioauth.managers import ClientManager, TokenManager, GrantManager, ScopeManager # Assume implementations for managers exist client_manager = ClientManager(...) token_manager = TokenManager(...) grant_manager = GrantManager(...) scope_manager = ScopeManager(...) server = AuthorizationServer( client_manager=client_manager, token_manager=token_manager, grant_manager=grant_manager, scope_manager=scope_manager ) # Process an incoming request (e.g., from a web framework) # response = await server.handle_authorization_request(request) # response = await server.handle_token_request(request) ``` -------------------------------- ### aioauth Configuration Module Source: https://github.com/aliev/aioauth/blob/master/docs/sections/api/config.md Provides configuration settings for the aioauth library. This includes details on how to set up and manage various parameters used by the library. ```APIDOC aioauth.config: Provides configuration settings for the aioauth library. This module handles the initialization and management of various parameters required for OAuth operations. Key configuration parameters typically include: - client_id: The unique identifier for your OAuth client. - client_secret: The secret key associated with your OAuth client. - redirect_uri: The URI where the authorization server redirects the user after authorization. - scope: The level of access the client is requesting. - token_endpoint: The URL of the token endpoint for exchanging authorization codes for access tokens. - authorization_endpoint: The URL of the authorization endpoint for initiating the OAuth flow. - refresh_token_endpoint: The URL for refreshing access tokens (if applicable). - userinfo_endpoint: The URL for retrieving user information (if applicable). Example Usage: ```python from aioauth import config config.client_id = "YOUR_CLIENT_ID" config.client_secret = "YOUR_CLIENT_SECRET" config.redirect_uri = "http://localhost:8000/callback" config.scope = "read write" ``` Note: Specific parameters and their availability may vary depending on the OAuth provider being used. ``` -------------------------------- ### OIDC Core Responses Source: https://github.com/aliev/aioauth/blob/master/docs/sections/api/oidc/core/responses.md Provides details on the response classes and methods within the aioauth.oidc.core.responses module. This includes how to construct and manage OpenID Connect responses. ```APIDOC aioauth.oidc.core.responses: Classes: - AuthorizationResponse: Represents an authorization response from an OIDC provider. - TokenResponse: Represents a token response from an OIDC provider. - UserInfoResponse: Represents a user info response from an OIDC provider. Methods: - create_authorization_response(request: Request, client: Client, code: str, state: Optional[str] = None, nonce: Optional[str] = None) -> RedirectResponse Creates an authorization response redirect. Parameters: request: The incoming HTTP request. client: The OAuth2 client instance. code: The authorization code. state: The state parameter from the original request. nonce: The nonce parameter from the original request. Returns: A RedirectResponse object. - create_token_response(request: Request, client: Client, code: str, redirect_uri: str) -> JSONResponse Creates a token response. Parameters: request: The incoming HTTP request. client: The OAuth2 client instance. code: The authorization code. redirect_uri: The redirect URI used in the authorization request. Returns: A JSONResponse object containing the token details. - create_userinfo_response(request: Request, user: User) -> JSONResponse Creates a user info response. Parameters: request: The incoming HTTP request. user: The user object. Returns: A JSONResponse object containing the user's claims. ``` -------------------------------- ### aioauth.collections Module Source: https://github.com/aliev/aioauth/blob/master/docs/sections/api/collections.md This section provides documentation for the aioauth.collections module. It outlines the classes and functions available within this module, which are likely used for managing collections of OAuth-related data or configurations. ```APIDOC Module: aioauth.collections This module contains collection-related utilities for the aioauth library. Classes: - BaseCollection: An abstract base class for creating custom collections. - OAuth2ClientCollection: A collection specifically designed for OAuth2 clients. Functions: - create_collection(collection_type: str, *args, **kwargs) -> BaseCollection Creates an instance of a specified collection type. Parameters: collection_type: The type of collection to create (e.g., 'oauth2_client'). *args: Positional arguments to pass to the collection constructor. **kwargs: Keyword arguments to pass to the collection constructor. Returns: An instance of the requested collection type. Example Usage: ```python from aioauth.collections import create_collection # Assuming OAuth2ClientCollection requires a name oauth2_clients = create_collection('oauth2_client', name='my_clients') print(type(oauth2_clients)) ``` Note: Specific details about the methods and attributes of BaseCollection and OAuth2ClientCollection would typically be found in their respective class documentation. ``` -------------------------------- ### aioauth.responses Module Source: https://github.com/aliev/aioauth/blob/master/docs/sections/api/responses.md This section provides an overview of the aioauth.responses module, which likely contains classes or functions for handling OAuth 2.0 responses. Specific details about the classes and their methods are not provided in the input, but it's expected to cover token responses, error responses, and potentially user info endpoints. ```python import aioauth.responses # Further details on how to use the responses module would go here. # For example: # from aioauth.responses import TokenResponse # response = TokenResponse(access_token='...', token_type='bearer', expires_in=3600) ``` -------------------------------- ### aioauth.requests Module Source: https://github.com/aliev/aioauth/blob/master/docs/sections/api/requests.md Provides classes and functions for making authenticated HTTP requests using OAuth 2.0. It handles token management and request signing. ```python import aioauth.requests # Example usage (conceptual): # async def make_request(client, token): # response = await aioauth.requests.make_authorized_request( # client, token, 'GET', 'https://api.example.com/data' # ) # return response ``` -------------------------------- ### Grant Type Implementation Source: https://github.com/aliev/aioauth/blob/master/docs/sections/api/oidc/core/grant_type.md Provides the core implementation for handling grant types within the OpenID Connect flow. This module defines the necessary classes and methods for managing different grant type strategies. ```python import typing from aioauth.oidc.core import grant_type class GrantType(typing.Protocol): async def create_token(self, client: "Client", grant: "Grant", scope: typing.Optional[str] = None) -> "Token": ... async def validate_token(self, client: "Client", token: "Token") -> "Grant": ... class AuthorizationCodeGrantType(GrantType): async def create_token(self, client: "Client", grant: "Grant", scope: typing.Optional[str] = None) -> "Token": ... async def validate_token(self, client: "Client", token: "Token") -> "Grant": ... class ImplicitGrantType(GrantType): async def create_token(self, client: "Client", grant: "Grant", scope: typing.Optional[str] = None) -> "Token": ... async def validate_token(self, client: "Client", token: "Token") -> "Grant": ... class RefreshTokenGrantType(GrantType): async def create_token(self, client: "Client", grant: "Grant", scope: typing.Optional[str] = None) -> "Token": ... async def validate_token(self, client: "Client", token: "Token") -> "Grant": ... class ClientCredentialsGrantType(GrantType): async def create_token(self, client: "Client", grant: "Grant", scope: typing.Optional[str] = None) -> "Token": ... async def validate_token(self, client: "Client", token: "Token") -> "Grant": ... class PasswordGrantType(GrantType): async def create_token(self, client: "Client", grant: "Grant", scope: typing.Optional[str] = None) -> "Token": ... async def validate_token(self, client: "Client", token: "Token") -> "Grant": ... ``` -------------------------------- ### aioauth.oidc.core.requests Source: https://github.com/aliev/aioauth/blob/master/docs/sections/api/oidc/core/requests.md Provides core request functionalities for OpenID Connect (OIDC) flows within the aioauth library. This module handles the creation and management of OIDC requests, including authorization requests and token requests. ```python from aioauth.oidc.core.requests import AuthorizationRequest, TokenRequest # Example usage for AuthorizationRequest auth_req = AuthorizationRequest( client_id='your_client_id', redirect_uri='your_redirect_uri', response_type='code', scope='openid profile email', state='a_secure_random_string' ) # Example usage for TokenRequest token_req = TokenRequest( grant_type='authorization_code', code='the_authorization_code', redirect_uri='your_redirect_uri', client_id='your_client_id', client_secret='your_client_secret' ) ``` -------------------------------- ### Grant Type Module Overview Source: https://github.com/aliev/aioauth/blob/master/docs/sections/api/grant_type.md Provides an overview of the Grant Type module, including its purpose and how it's structured within the aioauth library. This section is intended for developers looking to understand the core components of OAuth 2.0 grant types as implemented by aioauth. ```python import aioauth.grant_type # The aioauth.grant_type module contains classes and functions for handling various OAuth 2.0 grant types. # Developers can import specific grant type classes or utility functions from this module. # Example of accessing a grant type class (conceptual): # from aioauth.grant_type import AuthorizationCodeGrant # The module is designed to be extensible, allowing for custom grant type implementations. ``` -------------------------------- ### aioauth Type Definitions Source: https://github.com/aliev/aioauth/blob/master/docs/sections/api/types.md Provides definitions for core types used across the aioauth library, including authentication-related data structures and utility types. ```python from typing import Any, Dict, List, Optional, Tuple, Union # Basic types StrDict = Dict[str, str] AnyDict = Dict[str, Any] # OAuth specific types OAuthScopes = Union[str, List[str]] OAuthToken = Dict[str, Any] OAuthTokenResponse = Dict[str, Any] OAuthUserInfo = Dict[str, Any] # Client types ClientCredentials = Tuple[str, str] # Authorization request types AuthorizationParams = Dict[str, Any] # Token request types TokenParams = Dict[str, Any] # Exception types class OAuthError(Exception): """Base exception for OAuth errors.""" pass class InvalidClientError(OAuthError): """Raised when the client is invalid.""" pass class InvalidGrantError(OAuthError): """Raised when the authorization grant is invalid.""" pass # Other utility types RedirectUri = str CallbackUrl = str ``` -------------------------------- ### aioauth Error Hierarchy Source: https://github.com/aliev/aioauth/blob/master/docs/sections/api/errors.md This section outlines the error classes provided by the aioauth library. It details the base error class and specific exceptions that can be raised during authentication flows, helping developers understand and handle potential errors effectively. ```python class AuthError(Exception): """Base class for all authentication errors.""" pass class InvalidGrantError(AuthError): """Raised when the provided authorization grant is invalid.""" pass class InvalidClientError(AuthError): """Raised when the client is invalid.""" pass class InvalidScopeError(AuthError): """Raised when the requested scope is invalid.""" pass class InvalidRedirectUriError(AuthError): """Raised when the redirect URI is invalid.""" pass class AccessDeniedError(AuthError): """Raised when access is denied.""" pass class ServerError(AuthError): """Raised for general server errors.""" pass class InvalidClientCredentialsError(AuthError): """Raised when client credentials are invalid.""" pass class InvalidAccessTokenError(AuthError): """Raised when the access token is invalid.""" pass class ExpiredAccessTokenError(AuthError): """Raised when the access token has expired.""" pass class InvalidRefreshTokenError(AuthError): """Raised when the refresh token is invalid.""" pass class ExpiredRefreshTokenError(AuthError): """Raised when the refresh token has expired.""" pass class InvalidRequestError(AuthError): """Raised for invalid requests.""" pass class UnauthorizedClientError(AuthError): """Raised when the client is unauthorized.""" pass class UnsupportedResponseTypeError(AuthError): """Raised for unsupported response types.""" pass class UnsupportedGrantTypeError(AuthError): """Raised for unsupported grant types.""" pass class InvalidClientAuthError(AuthError): """Raised for invalid client authentication.""" pass ``` -------------------------------- ### aioauth.response_type Module Source: https://github.com/aliev/aioauth/blob/master/docs/sections/api/response_type.md Provides classes and functions for handling various OAuth 2.0 response types. ```python import aioauth.response_type # Example usage (conceptual): # response_type_handler = aioauth.response_type.ResponseTypeHandler() # authorization_code = response_type_handler.get_authorization_code(...) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.