Skip to main content

App for Django and DRF which give an opportunity to login via TG.

Project description

Django Telegram Authentication

Simple Django app for authentication via Telegram.

Installation

pip install django-tgauth

Quick start

  1. Add "auth_tg" to your INSTALLED_APPS setting:
INSTALLED_APPS = [
    ...
    'auth_tg',
]
  1. Add your Telegram Bot settings to settings.py:
BOT_TOKEN = 'your-bot-token'
BOT_USERNAME = 'your-bot-username'
  1. You can add an additional checking on your telegram channels. Just add these without gap:
CHANNELS = '12345678910,12345678911'
CHANNEL_NAMES = '@channel1,@channel2'
  1. Add backend and custom user model into settings.py as well:
AUTH_USER_MODEL = 'auth_tg.User'

AUTHENTICATION_BACKENDS = [
    'auth_tg.authentication.TelegramAuthBackend',
    'django.contrib.auth.backends.ModelBackend',
]
  1. Include the auth_tg URLconf to your project urls.py:
path('auth/', include('auth_tg.urls')),
  1. You can try out this functional: Add new app:
    cd yourproject-name
    
    python manage.py startapp yourapp_name
    
    Then you need to create urls.py and add this code:
    from django.urls import path
    from .views import *
    
    urlpatterns = [
        path('', Home.as_view(), name='home'),
        path('profile/', Profile.as_view(), name='profile')
    ]
    
    And add simple views to views.py:
    from auth_tg.views import TgAuthProfileView, TgAuthHomeView
    
    class Home(TgAuthHomeView):
        ...
    
    class Profile(TgAuthProfileView):
        ...
    
    Don't forget to add your new app to INSTALLED_APPS and URLconf:
    INSTALLED_APPS = [
        ...
        'auth_tg',
        'yourapp_name',
    ]
    
    path('', include('yourapp_name.urls')),
    
  2. Run migrations:
python manage.py makemigrations
python manage.py migrate
  1. If you want to use your own base.html then you need to add this to your html file.
<script src="{% static 'auth_tg/js/telegramAuth.js' %}"></script>

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

django_tgauth-0.1.4.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_tgauth-0.1.4-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file django_tgauth-0.1.4.tar.gz.

File metadata

  • Download URL: django_tgauth-0.1.4.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.6

File hashes

Hashes for django_tgauth-0.1.4.tar.gz
Algorithm Hash digest
SHA256 f9ededbe37e36132cc7f7fca5d363296fb1b8cb4909bb23ee01f6f40eeb65683
MD5 aa53e7d4c0021c02e096673f8f3bc035
BLAKE2b-256 191617e81ae3beec6ee4e9e8dc069bbe48185734bddd6c4a3933cf280b5c90bf

See more details on using hashes here.

File details

Details for the file django_tgauth-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: django_tgauth-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 16.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.6

File hashes

Hashes for django_tgauth-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 840baa175fb8efb422849df3dd939487f4e3d549ef3deaf0365bad7c2d666576
MD5 944f1c4f0f0969f66028bfaa792a15bc
BLAKE2b-256 5fe4723d47fbb24d85fa2da87f7448ec8bebf643f8be4824e4ac8bb836f18629

See more details on using hashes here.

Supported by

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