Skip to main content

IDP Authentication - Hexagonal Architecture Implementation

Project description

FastAPI

IDP Authentication hexagonal architecture implementation


Purpose

This project handles the authentication process of the Cardo platform. It is a hexagonal architecture implementation, which means that the business logic is independent of the framework used to implement the API.

Architecture

The architecture is based on the Hexagonal Architecture.

The main idea is to separate the business logic from the framework and the infrastructure.

The business logic is implemented in the domain module. This module is independent of the infrastructure.

The infrastructure is implemented infrastructure module.

The app which uses this package itself is the entry point of the application. It is the only module that depends on the framework.

Project layout

idp_authentication/
├── infrastructure
│   ├── custom_orm_column_types.py
│   ├── database.py
│   ├── orm.py
├── users
│   ├── adapters
│   │   ├── orm.py
│   │   ├── unit_of_work.py
│   │   ├── events
│   │   ├── repositories
│   ├── base_classes
│   │   ├── base_entity.py
│   │   ├── base_repository.py
│   ├── di
│   │   ├── containers.py
│   ├── domain
│   │   ├── entities
│   │   ├── ports
│   │   ├── use_cases
│   ├── infrastructure
│   │   ├── database
│   │   │   ├── sqlalchemy
│   │   ├── faust
│   │   │   ├── faust_app.py
│   ├── tests
│   │   ├── domain
│   │   │   ├── __init__.py

Requirements

Python 3.9+

IDP Authentication requires the following to be implemented:

Installation

Since this is a private repository, you need to install the package with the following command:

pip install git+ssh://git@github.com/CardoAI/idp-authentication.git@main

Example

Usage

Inside your application container:

from dependency_injector import providers
from idp_authentication.users.di.containers import UsersModuleDIContainer

    users_module = providers.Container(
        UsersModuleDIContainer,
        config=config,
        database=database,
    )

Extending default config

from idp_authentication.config import Config

class TestConfig(Config):
    APP_IDENTIFIER = "test"
    TENANTS = ["default"]
    ROLES = [TEST_ROLE_1, TEST_ROLE_2]
    APP_ENTITY_TYPES = ["app_entity_1", "app_entity_2"]

    class Config:
        env_file_encoding = "utf-8"
        use_enum_values = True

Configuration example

from dependency_injector import containers, providers
from idp_authentication.users.di.containers import UsersModuleDIContainer


class YourTestContainer(containers.DeclarativeContainer):
    config = providers.Configuration(pydantic_settings=[TestConfig()])
    url = get_test_memory_db_uri()
    database = providers.Singleton(
        Database,
    )
    users_module = providers.Container(
        UsersModuleDIContainer,
        config=config,
        database=database,
    )

Usage example

    def container():
        container = YourTestContainer()
        container.wire(packages=["idp_authentication"]) # Wire IDPAuthentication
        container.users_module.start_mappers() # Start Users Module mapper
        yield container

App Entity

To declare a new AppEntity, the Entity class should:

  • Inherit from the class AppEntity
  • Declare the properties idp_identifier, idp_label and optionally entity_type
  • Example:
    from idp_authentication.users.domain.entities.app_entity import AppEntity
      
    class TestEntity(AppEntity):
          @property
          def idp_identifier(self):
              return self.id
            
          @property
          def idp_label(self):
              return self.name
      
          @property
          def entity_type(self):
              return "test"
    

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

idp_authentication-0.2.0.tar.gz (23.3 kB view details)

Uploaded Source

Built Distribution

idp_authentication-0.2.0-py3-none-any.whl (40.1 kB view details)

Uploaded Python 3

File details

Details for the file idp_authentication-0.2.0.tar.gz.

File metadata

  • Download URL: idp_authentication-0.2.0.tar.gz
  • Upload date:
  • Size: 23.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for idp_authentication-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b6663c2e9d462be8b56f1d2e1c1bd24bfe4778a535678ff1b50d1a20bb5c1839
MD5 5c3d22791c63f95e94a7f6ce7f30ac68
BLAKE2b-256 797ff5ad1583c196e83b4192e00b58e8032be80d0bfecdc5abb083049439252e

See more details on using hashes here.

File details

Details for the file idp_authentication-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for idp_authentication-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0a59222d33b4957c8d0a5edc4b6a4679fddb9a6f4d1969fa4edecb2bd2d60238
MD5 6502462a834d5c57d2f5e2ce87e76902
BLAKE2b-256 f035acbce786e6e9db7e004f6d44083438e8bcb7035e4eed45a351bebb194314

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page