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
- Add "auth_tg" to your INSTALLED_APPS setting:
INSTALLED_APPS = [
...
'auth_tg',
]
- Add your Telegram Bot settings to settings.py:
BOT_TOKEN = 'your-bot-token'
BOT_USERNAME = 'your-bot-username'
- You can add an additional checking on your telegram channels. Just add these without gap:
CHANNELS = '12345678910,12345678911'
CHANNEL_NAMES = '@channel1,@channel2'
- 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',
]
- Include the auth_tg URLconf to your project urls.py:
path('auth/', include('auth_tg.urls')),
- 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')),
- Run migrations:
python manage.py makemigrations
python manage.py migrate
- 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
Release history Release notifications | RSS feed
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)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9ededbe37e36132cc7f7fca5d363296fb1b8cb4909bb23ee01f6f40eeb65683
|
|
| MD5 |
aa53e7d4c0021c02e096673f8f3bc035
|
|
| BLAKE2b-256 |
191617e81ae3beec6ee4e9e8dc069bbe48185734bddd6c4a3933cf280b5c90bf
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
840baa175fb8efb422849df3dd939487f4e3d549ef3deaf0365bad7c2d666576
|
|
| MD5 |
944f1c4f0f0969f66028bfaa792a15bc
|
|
| BLAKE2b-256 |
5fe4723d47fbb24d85fa2da87f7448ec8bebf643f8be4824e4ac8bb836f18629
|