dj-ms-auth-router


Namedj-ms-auth-router JSON
Version 1.5.1 PyPI version JSON
download
home_pagehttps://github.com/dj-ms/dj-ms-auth-router
SummarySimple database router that helps to implement microservices architecture with Django.
upload_time2023-04-14 07:39:27
maintainer
docs_urlNone
authorAstafeev Rustam
requires_python~=3.8
licenseBSD-3-Clause
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Django microservice auth SDK

# Django auth DB router.

Simple database router that helps to split your main database and authentication database.
This may be necessary when splitting a project into microservices.
Let's say you have some Django project and want to split it into microservices.
But all of your microservices need to use the same authentication database.
This router will help you to do that.

---


## How it works
  
1. Django project that provides authentication also shares default database with other microservices.  
2. Other microservices may have their own databases, but they all use the same authentication database.  

Which apps are routed to `auth_db` database?
- `contenttypes`
- `sites`
- `auth`
- `admin`
- `flatpages`
- `redirects`
- `auditlog`
- `sessions`
  
Models of these apps are routed to `auth_db` database. 
  
These apps are hardcoded in `ms_auth_router.routers.DefaultRouter`.  
  
List can be extended by adding `ROUTE_APP_LABELS` setting.  
  
> If you know that some reusable Django apps should be routed to `auth_db` database, please create an issue or pull request.



## Quickstart  
  
Add `ms_auth_router` to your `INSTALLED_APPS` setting like this:
```python
INSTALLED_APPS = [
    ...,
    'ms_auth_router',
    ...
]
```

Add `DATABASE_ROUTERS` setting in `settings.py` file or append to existing list:
```python
DATABASE_ROUTERS = [
    'ms_auth_router.routers.DefaultRouter',
    ...
]
```

Add `auth_db` section to `DATABASES`:
```pycon
DATABASES = {
   ...
   'auth_db': {
       'ENGINE': 'django.db.backends.sqlite3',
       'NAME': BASE_DIR / 'auth.sqlite3',
   },
   ...
}
```

Finally, add `AUTH_DB` setting:
```python
AUTH_DB = 'auth_db'
```

Without this setting router will use `default` db connection.  
  
> Note: To get session authentication working between microservices, the `SECRET_KEY` setting must be the same 
> in all microservices.


## Use with custom auth app  
  
If you're using custom auth app and want it to be routed to `auth_db` database, 
you need to add `ROUTE_APP_LABELS` setting:
```python
ROUTE_APP_LABELS = ['my_custom_auth_app', ]
```
  
  

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/dj-ms/dj-ms-auth-router",
    "name": "dj-ms-auth-router",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "~=3.8",
    "maintainer_email": "",
    "keywords": "",
    "author": "Astafeev Rustam",
    "author_email": "astafeev0308@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/c7/2c/825fc9cf82d72ababc6e2114e6f85f3219cafd82aa251766a0a3b9ceaa8f/dj-ms-auth-router-1.5.1.tar.gz",
    "platform": null,
    "description": "# Django microservice auth SDK\n\n# Django auth DB router.\n\nSimple database router that helps to split your main database and authentication database.\nThis may be necessary when splitting a project into microservices.\nLet's say you have some Django project and want to split it into microservices.\nBut all of your microservices need to use the same authentication database.\nThis router will help you to do that.\n\n---\n\n\n## How it works\n  \n1. Django project that provides authentication also shares default database with other microservices.  \n2. Other microservices may have their own databases, but they all use the same authentication database.  \n\nWhich apps are routed to `auth_db` database?\n- `contenttypes`\n- `sites`\n- `auth`\n- `admin`\n- `flatpages`\n- `redirects`\n- `auditlog`\n- `sessions`\n  \nModels of these apps are routed to `auth_db` database. \n  \nThese apps are hardcoded in `ms_auth_router.routers.DefaultRouter`.  \n  \nList can be extended by adding `ROUTE_APP_LABELS` setting.  \n  \n> If you know that some reusable Django apps should be routed to `auth_db` database, please create an issue or pull request.\n\n\n\n## Quickstart  \n  \nAdd `ms_auth_router` to your `INSTALLED_APPS` setting like this:\n```python\nINSTALLED_APPS = [\n    ...,\n    'ms_auth_router',\n    ...\n]\n```\n\nAdd `DATABASE_ROUTERS` setting in `settings.py` file or append to existing list:\n```python\nDATABASE_ROUTERS = [\n    'ms_auth_router.routers.DefaultRouter',\n    ...\n]\n```\n\nAdd `auth_db` section to `DATABASES`:\n```pycon\nDATABASES = {\n   ...\n   'auth_db': {\n       'ENGINE': 'django.db.backends.sqlite3',\n       'NAME': BASE_DIR / 'auth.sqlite3',\n   },\n   ...\n}\n```\n\nFinally, add `AUTH_DB` setting:\n```python\nAUTH_DB = 'auth_db'\n```\n\nWithout this setting router will use `default` db connection.  \n  \n> Note: To get session authentication working between microservices, the `SECRET_KEY` setting must be the same \n> in all microservices.\n\n\n## Use with custom auth app  \n  \nIf you're using custom auth app and want it to be routed to `auth_db` database, \nyou need to add `ROUTE_APP_LABELS` setting:\n```python\nROUTE_APP_LABELS = ['my_custom_auth_app', ]\n```\n  \n  \n",
    "bugtrack_url": null,
    "license": "BSD-3-Clause",
    "summary": "Simple database router that helps to implement microservices architecture with Django.",
    "version": "1.5.1",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6a522162bea82012f35de7828540a7864dca176441051aa98d6f40d37e8e0582",
                "md5": "0e4b8236707aa3aa29aff61f02bd42a2",
                "sha256": "14e833dbdad6e5b1f00784aee2ec6f696d242eb463d9515c6d84d8250da5131a"
            },
            "downloads": -1,
            "filename": "dj_ms_auth_router-1.5.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0e4b8236707aa3aa29aff61f02bd42a2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "~=3.8",
            "size": 5059,
            "upload_time": "2023-04-14T07:39:25",
            "upload_time_iso_8601": "2023-04-14T07:39:25.881904Z",
            "url": "https://files.pythonhosted.org/packages/6a/52/2162bea82012f35de7828540a7864dca176441051aa98d6f40d37e8e0582/dj_ms_auth_router-1.5.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c72c825fc9cf82d72ababc6e2114e6f85f3219cafd82aa251766a0a3b9ceaa8f",
                "md5": "352c480bedce12ff89b8903c1387c199",
                "sha256": "2779f6ad11fd93182948204febd6e301c43f18b56c0c57ee9bb5ab8f40dd3c29"
            },
            "downloads": -1,
            "filename": "dj-ms-auth-router-1.5.1.tar.gz",
            "has_sig": false,
            "md5_digest": "352c480bedce12ff89b8903c1387c199",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "~=3.8",
            "size": 185024,
            "upload_time": "2023-04-14T07:39:27",
            "upload_time_iso_8601": "2023-04-14T07:39:27.595446Z",
            "url": "https://files.pythonhosted.org/packages/c7/2c/825fc9cf82d72ababc6e2114e6f85f3219cafd82aa251766a0a3b9ceaa8f/dj-ms-auth-router-1.5.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-14 07:39:27",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "dj-ms",
    "github_project": "dj-ms-auth-router",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "dj-ms-auth-router"
}
        
Elapsed time: 0.07304s