django-simple-third-party-jwt-dev-dashboard


Namedjango-simple-third-party-jwt-dev-dashboard JSON
Version 0.2.3 PyPI version JSON
download
home_pagehttps://github.com/NatLee/Django-Simple-3rd-Party-JWT-Dev-Dashboard
SummaryDashboard for using JWT with 3rd party login.
upload_time2024-08-06 06:35:22
maintainerNone
docs_urlNone
authorNat Lee
requires_python>=3.8
licenseNone
keywords django jwt 3rd party login dashboard toolbox
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Django Simple 3rd Party JWT Dev Dashboard

![dashboard](https://i.imgur.com/qrGkUZM.png)

This is a simple dashboard for showing multi login(JWT, session and 3rd party).

Dashboard is used with [Django-Simple-3rd-Party-JWT](https://github.com/NatLee/Django-Simple-3rd-Party-JWT).

## Installation

```bash
pip install django-simple-third-party-jwt-dev-dashboard
```

Check it in [Pypi](https://pypi.org/project/django-simple-third-party-jwt-dev-dashboard/).

## Quick Start

- `settings.py`

  Add the followings to your settings of project.

  - (MUST) Install app

  ```python
  INSTALLED_APPS += [
      # ---------------------------
      # debug relative package
      "rest_framework", # <------ MUST
      #"drf_yasg", # (OPTIONAL) for swagger
      'bootstrap3', # <------ MUST
      # 3rd party login
      'django_simple_third_party_jwt' # <------ MUST
      # debug dashboard
      'django_simple_third_party_jwt_dev_dashboard', # <------ MUST
      # ---------------------------
  ]
  ```

  - (MUST) Dashboard settings

  ```python
  # -------------- START - Dashboard Setting --------------
  DEV_DASHBOARD_SETTINGS = {
      'jwt_token_url': 'api/auth/token',
      'jwt_refresh_url': 'api/auth/token/refresh',
      'jwt_verify_url': 'api/auth/token/verify',
      'dashboard_url': 'api/__hidden_dev_dashboard',
      'admin_url': 'api/__hidden_admin',
      #'swagger_url': 'api/__hidden_swagger', # OPTIONAL
      #'redoc_url': 'api/__hidden_redoc', # OPTIONAL
  }
  # --------------- END - Dashboard Setting -----------------

  # -------------- START - 3rd party login Setting --------------
  LOGIN_REDIRECT_URL = '/' + DEV_DASHBOARD_SETTINGS['dashboard_url'] # <- (OPTIONAL) for redirect after login
  JWT_3RD_PREFIX = 'api' # <- (OPTIONAL) for 3rd party login
  # --------------- END - 3rd party login Setting -----------------
  ```

  - (MUST) Policy for Google API

  ```python
  # -------------- START - Policy Setting --------------
  SECURE_REFERRER_POLICY = "no-referrer-when-downgrade"
  # SECURE_CROSS_ORIGIN_OPENER_POLICY = "same-origin-allow-popups"
  SECURE_CROSS_ORIGIN_OPENER_POLICY = None
  # -------------- END - Policy Setting -----------------
  ```

  - (OPTIONAL) Configuration for 3rd party login

  ```python
  VALID_REGISTER_DOMAINS = ["gmail.com", "hotmail.com"]

  # -------------- START - Google Auth Setting --------------
  SOCIAL_GOOGLE_CLIENT_ID = "376808175534-d6mefo6b1kqih3grjjose2euree2g3cs.apps.googleusercontent.com"
  # --------------- END - Google Auth Setting -----------------

  # -------------- START - Microsoft Auth Setting --------------
  SOCIAL_MICROSOFT_CLIENT_ID = '32346173-22bc-43b2-b6ed-f88f6a76e38c'
  SOCIAL_MICROSOFT_CLIENT_SECRET = 'K5z8Q~dIXDiFN5qjMjRjIx34cZOJ3Glkrg.dxcG9'
  # --------------- END - Microsoft Auth Setting -----------------

  ```

> You can regist `SOCIAL_GOOGLE_CLIENT_ID` on Google Cloud Platform.

  [Google Colud | API和服務 | 憑證](https://console.cloud.google.com/apis/credentials)

  1. Create a new project and create a new OAuth 2.0 Client ID.
    ![](https://i.imgur.com/7UKP3I7.png)

  2. Add `http://localhost:8000` to `Authorized JavaScript origins` and `Authorized redirect URIs`.
    ![](https://i.imgur.com/IoTRs4j.png)

> You can regist `SOCIAL_MICROSOFT_CLIENT_ID` on Microsoft Azure.

[Microsoft Entra 識別碼 | 應用程式註冊](https://portal.azure.com/#view/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/~/RegisteredApps)

  1. Create a new application.
    ![](https://i.imgur.com/my5UtXv.png)
  2. Add `http://localhost:8000/api/auth/microsoft/callback` to `Redirect URIs`
    ![](https://i.imgur.com/lsaZgMM.png)
  3. Get `Client ID` from `Overview` page.
    ![](https://i.imgur.com/5oo3xnI.png)
  4. Get `Client Secret` from `Certificates & secrets` page.
    ![](https://i.imgur.com/3F5ge7l.png)


- `urls.py`

  URL path for dashboard. (MUST)

  ```python
  # --------------- 3rd party login
  # app route
  urlpatterns += [
      path("", include("django_simple_third_party_jwt.urls")),
  ]
  # ------------------------------

  # --------------- Dashboard
  urlpatterns += [
      # debug dashboard
      path(settings.DEV_DASHBOARD_SETTINGS['dashboard_url'] + "/", include("django_simple_third_party_jwt_dev_dashboard.urls")),
  ]
  # ------------------------------

  # --------------- Admin
  urlpatterns += [
      # admin
      path(settings.DEV_DASHBOARD_SETTINGS['admin_url'] + "/", admin.site.urls),
  ]
  # ------------------------------

  # --------------- JWT
  from rest_framework_simplejwt.views import (
      TokenVerifyView, TokenObtainPairView, TokenRefreshView
  )
  urlpatterns += [
      path(settings.DEV_DASHBOARD_SETTINGS['jwt_token_url'], TokenObtainPairView.as_view(), name="token_get"),
      path(settings.DEV_DASHBOARD_SETTINGS['jwt_refresh_url'], TokenRefreshView.as_view(), name="token_refresh"),
      path(settings.DEV_DASHBOARD_SETTINGS['jwt_verify_url'], TokenVerifyView.as_view(), name="token_verify"),
  ]
  # ---------------------------------
  ```

When you added all settings, just run:

```bash
python manage.py runserver 0.0.0.0:8000
```

And visit `http://localhost:8000/api/__hidden_dev_dashboard`

## Example

Check `./example/django_simple_third_party_jwt_dev_dashboard_example/`.

## More

There are several different settings can be added with this dashboard if you need.

- CORS Setting

```python
ALLOWED_HOSTS = ["*"]
LOGIN_REDIRECT_URL = "/"

# -------------- START - CORS Setting --------------
CORS_ALLOW_ALL_ORIGINS = True
CORS_ALLOW_CREDENTIALS = True
CSRF_TRUSTED_ORIGINS = [
    "http://127.0.0.1",
    "http://localhost",
]
# -------------- END - CORS Setting -----------------
```

- Swagger setting

```python
# -------------- Swagger Setting --------------
SWAGGER_SETTINGS = {
    "SECURITY_DEFINITIONS": {
        "Token(add prefix `Bearer` yourself)": {
            "type": "apiKey",
            "name": "Authorization",
            "in": "header",
        }
    },
    "LOGIN_URL": "/api/__hiddenadmin/login/",
    "LOGOUT_URL": "/api/__hiddenadmin/logout/",
}

# --------------------------------------------
```

- SimpleJWT setting

```python

# -------------- Start - SimpleJWT Setting --------------
from datetime import timedelta
SIMPLE_JWT = {
    "ACCESS_TOKEN_LIFETIME": timedelta(minutes=3600),
    "REFRESH_TOKEN_LIFETIME": timedelta(days=1),
    "ROTATE_REFRESH_TOKENS": False,
    "BLACKLIST_AFTER_ROTATION": False,
    "UPDATE_LAST_LOGIN": False,
    "ALGORITHM": "HS256",
    "SIGNING_KEY": SECRET_KEY,
    "VERIFYING_KEY": None,
    "AUDIENCE": None,
    "ISSUER": None,
    "JWK_URL": None,
    "LEEWAY": 0,
    "AUTH_HEADER_TYPES": ("Bearer",),
    "AUTH_HEADER_NAME": "HTTP_AUTHORIZATION",
    "USER_ID_FIELD": "id",
    "USER_ID_CLAIM": "user_id",
    "USER_AUTHENTICATION_RULE": "rest_framework_simplejwt.authentication.default_user_authentication_rule",
    "AUTH_TOKEN_CLASSES": ("rest_framework_simplejwt.tokens.AccessToken",),
    "TOKEN_TYPE_CLAIM": "token_type",
    "TOKEN_USER_CLASS": "rest_framework_simplejwt.models.TokenUser",
    "JTI_CLAIM": "jti",
    "SLIDING_TOKEN_REFRESH_EXP_CLAIM": "refresh_exp",
    "SLIDING_TOKEN_LIFETIME": timedelta(minutes=5),
    "SLIDING_TOKEN_REFRESH_LIFETIME": timedelta(days=1),
}
# -------------- END - SimpleJWT Setting --------------

```

## Misc tools

### Install & re-install package

* Linux

```bash
bash dev-reinstall.sh
```

* Windows

```powershell
./dev-reinstall.ps1
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/NatLee/Django-Simple-3rd-Party-JWT-Dev-Dashboard",
    "name": "django-simple-third-party-jwt-dev-dashboard",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "django, jwt, 3rd party login, dashboard, toolbox",
    "author": "Nat Lee",
    "author_email": "natlee.work@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/9e/c8/c2d67d2fe6d3954779d461c142b10ef2a99bf0f32efc136683ac05deef3d/django_simple_third_party_jwt_dev_dashboard-0.2.3.tar.gz",
    "platform": null,
    "description": "# Django Simple 3rd Party JWT Dev Dashboard\n\n![dashboard](https://i.imgur.com/qrGkUZM.png)\n\nThis is a simple dashboard for showing multi login(JWT, session and 3rd party).\n\nDashboard is used with [Django-Simple-3rd-Party-JWT](https://github.com/NatLee/Django-Simple-3rd-Party-JWT).\n\n## Installation\n\n```bash\npip install django-simple-third-party-jwt-dev-dashboard\n```\n\nCheck it in [Pypi](https://pypi.org/project/django-simple-third-party-jwt-dev-dashboard/).\n\n## Quick Start\n\n- `settings.py`\n\n  Add the followings to your settings of project.\n\n  - (MUST) Install app\n\n  ```python\n  INSTALLED_APPS += [\n      # ---------------------------\n      # debug relative package\n      \"rest_framework\", # <------ MUST\n      #\"drf_yasg\", # (OPTIONAL) for swagger\n      'bootstrap3', # <------ MUST\n      # 3rd party login\n      'django_simple_third_party_jwt' # <------ MUST\n      # debug dashboard\n      'django_simple_third_party_jwt_dev_dashboard', # <------ MUST\n      # ---------------------------\n  ]\n  ```\n\n  - (MUST) Dashboard settings\n\n  ```python\n  # -------------- START - Dashboard Setting --------------\n  DEV_DASHBOARD_SETTINGS = {\n      'jwt_token_url': 'api/auth/token',\n      'jwt_refresh_url': 'api/auth/token/refresh',\n      'jwt_verify_url': 'api/auth/token/verify',\n      'dashboard_url': 'api/__hidden_dev_dashboard',\n      'admin_url': 'api/__hidden_admin',\n      #'swagger_url': 'api/__hidden_swagger', # OPTIONAL\n      #'redoc_url': 'api/__hidden_redoc', # OPTIONAL\n  }\n  # --------------- END - Dashboard Setting -----------------\n\n  # -------------- START - 3rd party login Setting --------------\n  LOGIN_REDIRECT_URL = '/' + DEV_DASHBOARD_SETTINGS['dashboard_url'] # <- (OPTIONAL) for redirect after login\n  JWT_3RD_PREFIX = 'api' # <- (OPTIONAL) for 3rd party login\n  # --------------- END - 3rd party login Setting -----------------\n  ```\n\n  - (MUST) Policy for Google API\n\n  ```python\n  # -------------- START - Policy Setting --------------\n  SECURE_REFERRER_POLICY = \"no-referrer-when-downgrade\"\n  # SECURE_CROSS_ORIGIN_OPENER_POLICY = \"same-origin-allow-popups\"\n  SECURE_CROSS_ORIGIN_OPENER_POLICY = None\n  # -------------- END - Policy Setting -----------------\n  ```\n\n  - (OPTIONAL) Configuration for 3rd party login\n\n  ```python\n  VALID_REGISTER_DOMAINS = [\"gmail.com\", \"hotmail.com\"]\n\n  # -------------- START - Google Auth Setting --------------\n  SOCIAL_GOOGLE_CLIENT_ID = \"376808175534-d6mefo6b1kqih3grjjose2euree2g3cs.apps.googleusercontent.com\"\n  # --------------- END - Google Auth Setting -----------------\n\n  # -------------- START - Microsoft Auth Setting --------------\n  SOCIAL_MICROSOFT_CLIENT_ID = '32346173-22bc-43b2-b6ed-f88f6a76e38c'\n  SOCIAL_MICROSOFT_CLIENT_SECRET = 'K5z8Q~dIXDiFN5qjMjRjIx34cZOJ3Glkrg.dxcG9'\n  # --------------- END - Microsoft Auth Setting -----------------\n\n  ```\n\n> You can regist `SOCIAL_GOOGLE_CLIENT_ID` on Google Cloud Platform.\n\n  [Google Colud | API\u548c\u670d\u52d9 | \u6191\u8b49](https://console.cloud.google.com/apis/credentials)\n\n  1. Create a new project and create a new OAuth 2.0 Client ID.\n    ![](https://i.imgur.com/7UKP3I7.png)\n\n  2. Add `http://localhost:8000` to `Authorized JavaScript origins` and `Authorized redirect URIs`.\n    ![](https://i.imgur.com/IoTRs4j.png)\n\n> You can regist `SOCIAL_MICROSOFT_CLIENT_ID` on Microsoft Azure.\n\n[Microsoft Entra \u8b58\u5225\u78bc | \u61c9\u7528\u7a0b\u5f0f\u8a3b\u518a](https://portal.azure.com/#view/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/~/RegisteredApps)\n\n  1. Create a new application.\n    ![](https://i.imgur.com/my5UtXv.png)\n  2. Add `http://localhost:8000/api/auth/microsoft/callback` to `Redirect URIs`\n    ![](https://i.imgur.com/lsaZgMM.png)\n  3. Get `Client ID` from `Overview` page.\n    ![](https://i.imgur.com/5oo3xnI.png)\n  4. Get `Client Secret` from `Certificates & secrets` page.\n    ![](https://i.imgur.com/3F5ge7l.png)\n\n\n- `urls.py`\n\n  URL path for dashboard. (MUST)\n\n  ```python\n  # --------------- 3rd party login\n  # app route\n  urlpatterns += [\n      path(\"\", include(\"django_simple_third_party_jwt.urls\")),\n  ]\n  # ------------------------------\n\n  # --------------- Dashboard\n  urlpatterns += [\n      # debug dashboard\n      path(settings.DEV_DASHBOARD_SETTINGS['dashboard_url'] + \"/\", include(\"django_simple_third_party_jwt_dev_dashboard.urls\")),\n  ]\n  # ------------------------------\n\n  # --------------- Admin\n  urlpatterns += [\n      # admin\n      path(settings.DEV_DASHBOARD_SETTINGS['admin_url'] + \"/\", admin.site.urls),\n  ]\n  # ------------------------------\n\n  # --------------- JWT\n  from rest_framework_simplejwt.views import (\n      TokenVerifyView, TokenObtainPairView, TokenRefreshView\n  )\n  urlpatterns += [\n      path(settings.DEV_DASHBOARD_SETTINGS['jwt_token_url'], TokenObtainPairView.as_view(), name=\"token_get\"),\n      path(settings.DEV_DASHBOARD_SETTINGS['jwt_refresh_url'], TokenRefreshView.as_view(), name=\"token_refresh\"),\n      path(settings.DEV_DASHBOARD_SETTINGS['jwt_verify_url'], TokenVerifyView.as_view(), name=\"token_verify\"),\n  ]\n  # ---------------------------------\n  ```\n\nWhen you added all settings, just run:\n\n```bash\npython manage.py runserver 0.0.0.0:8000\n```\n\nAnd visit `http://localhost:8000/api/__hidden_dev_dashboard`\n\n## Example\n\nCheck `./example/django_simple_third_party_jwt_dev_dashboard_example/`.\n\n## More\n\nThere are several different settings can be added with this dashboard if you need.\n\n- CORS Setting\n\n```python\nALLOWED_HOSTS = [\"*\"]\nLOGIN_REDIRECT_URL = \"/\"\n\n# -------------- START - CORS Setting --------------\nCORS_ALLOW_ALL_ORIGINS = True\nCORS_ALLOW_CREDENTIALS = True\nCSRF_TRUSTED_ORIGINS = [\n    \"http://127.0.0.1\",\n    \"http://localhost\",\n]\n# -------------- END - CORS Setting -----------------\n```\n\n- Swagger setting\n\n```python\n# -------------- Swagger Setting --------------\nSWAGGER_SETTINGS = {\n    \"SECURITY_DEFINITIONS\": {\n        \"Token(add prefix `Bearer` yourself)\": {\n            \"type\": \"apiKey\",\n            \"name\": \"Authorization\",\n            \"in\": \"header\",\n        }\n    },\n    \"LOGIN_URL\": \"/api/__hiddenadmin/login/\",\n    \"LOGOUT_URL\": \"/api/__hiddenadmin/logout/\",\n}\n\n# --------------------------------------------\n```\n\n- SimpleJWT setting\n\n```python\n\n# -------------- Start - SimpleJWT Setting --------------\nfrom datetime import timedelta\nSIMPLE_JWT = {\n    \"ACCESS_TOKEN_LIFETIME\": timedelta(minutes=3600),\n    \"REFRESH_TOKEN_LIFETIME\": timedelta(days=1),\n    \"ROTATE_REFRESH_TOKENS\": False,\n    \"BLACKLIST_AFTER_ROTATION\": False,\n    \"UPDATE_LAST_LOGIN\": False,\n    \"ALGORITHM\": \"HS256\",\n    \"SIGNING_KEY\": SECRET_KEY,\n    \"VERIFYING_KEY\": None,\n    \"AUDIENCE\": None,\n    \"ISSUER\": None,\n    \"JWK_URL\": None,\n    \"LEEWAY\": 0,\n    \"AUTH_HEADER_TYPES\": (\"Bearer\",),\n    \"AUTH_HEADER_NAME\": \"HTTP_AUTHORIZATION\",\n    \"USER_ID_FIELD\": \"id\",\n    \"USER_ID_CLAIM\": \"user_id\",\n    \"USER_AUTHENTICATION_RULE\": \"rest_framework_simplejwt.authentication.default_user_authentication_rule\",\n    \"AUTH_TOKEN_CLASSES\": (\"rest_framework_simplejwt.tokens.AccessToken\",),\n    \"TOKEN_TYPE_CLAIM\": \"token_type\",\n    \"TOKEN_USER_CLASS\": \"rest_framework_simplejwt.models.TokenUser\",\n    \"JTI_CLAIM\": \"jti\",\n    \"SLIDING_TOKEN_REFRESH_EXP_CLAIM\": \"refresh_exp\",\n    \"SLIDING_TOKEN_LIFETIME\": timedelta(minutes=5),\n    \"SLIDING_TOKEN_REFRESH_LIFETIME\": timedelta(days=1),\n}\n# -------------- END - SimpleJWT Setting --------------\n\n```\n\n## Misc tools\n\n### Install & re-install package\n\n* Linux\n\n```bash\nbash dev-reinstall.sh\n```\n\n* Windows\n\n```powershell\n./dev-reinstall.ps1\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Dashboard for using JWT with 3rd party login.",
    "version": "0.2.3",
    "project_urls": {
        "Bug Reports": "https://github.com/natlee/Django-Simple-3rd-Party-JWT-Dev-Dashboard/issues",
        "Documentation": "https://github.com/natlee/Django-Simple-3rd-Party-JWT-Dev-Dashboard",
        "Homepage": "https://github.com/NatLee/Django-Simple-3rd-Party-JWT-Dev-Dashboard",
        "Source Code": "https://github.com/natlee/Django-Simple-3rd-Party-JWT-Dev-Dashboard"
    },
    "split_keywords": [
        "django",
        " jwt",
        " 3rd party login",
        " dashboard",
        " toolbox"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3ff48ea7f77aaa523b245a066f3eba3c01a7d4ecd11f41adb26e4cb439aedc33",
                "md5": "e8c3c1b26462da6566c8d7a89650fab3",
                "sha256": "f652aba8ab2af8206d4cd192cb944830c7e7ceb27ea45657fccfb1dae3d438a2"
            },
            "downloads": -1,
            "filename": "django_simple_third_party_jwt_dev_dashboard-0.2.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e8c3c1b26462da6566c8d7a89650fab3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 13123,
            "upload_time": "2024-08-06T06:35:21",
            "upload_time_iso_8601": "2024-08-06T06:35:21.045462Z",
            "url": "https://files.pythonhosted.org/packages/3f/f4/8ea7f77aaa523b245a066f3eba3c01a7d4ecd11f41adb26e4cb439aedc33/django_simple_third_party_jwt_dev_dashboard-0.2.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9ec8c2d67d2fe6d3954779d461c142b10ef2a99bf0f32efc136683ac05deef3d",
                "md5": "2c33df2cb2eaddaa6703d9f85b857bdc",
                "sha256": "c443424e9400c5631a85cb40a5c20f6d75c2fc86a1d05f3ddc2d0d43b60cac80"
            },
            "downloads": -1,
            "filename": "django_simple_third_party_jwt_dev_dashboard-0.2.3.tar.gz",
            "has_sig": false,
            "md5_digest": "2c33df2cb2eaddaa6703d9f85b857bdc",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 17168,
            "upload_time": "2024-08-06T06:35:22",
            "upload_time_iso_8601": "2024-08-06T06:35:22.425180Z",
            "url": "https://files.pythonhosted.org/packages/9e/c8/c2d67d2fe6d3954779d461c142b10ef2a99bf0f32efc136683ac05deef3d/django_simple_third_party_jwt_dev_dashboard-0.2.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-06 06:35:22",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "NatLee",
    "github_project": "Django-Simple-3rd-Party-JWT-Dev-Dashboard",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "django-simple-third-party-jwt-dev-dashboard"
}
        
Elapsed time: 0.31261s