Github Auth
A django application to login with github.
π Installation and Usage π
Installation
-
Github Aauth can be installed by running
pip install github_auth. -
Add "github_auth" to your INSTALLED_APPS setting:
INSTALLED_APPS = [] # β¦ "github_auth", ]
- Set login and logout redirect url
LOGIN_REDIRECT_URL = "/" # after users login, they will redirect this url LOGOUT_REDIRECT_URL = "/" # after users logout
- Set your Github app configuration
GITHUB_AUTH = dict( redirect_uri="your_redirect_uri", scope="your scope", client_secret="your github client_secret", client_id="your github client_id", )
Usage
- In your myapp/urls.py:
urlpatterns = [ ... path("accounts/github/", include('github_auth.urls')), ]
- In your myapp/templates:
<a href="{% url 'redirect-github' %}">login wia github</a>
- Github Auth extend default user model using
OneToOneFieldso you can use as below.
after login to show profile image from github profile image
<img src="request.user.github_auth.avatar_url" title="request.user"> <p>{{request.user.github_auth.get_extra_data_as_dict.bio}}</p>
request.user.github_auth.get_extra_data_as_dict.bio # and other extra_data fields request.user.github_auth.avatar_url
or
from django.contrip.auth.models import User admin_avatar_url = User.objects.get(username="admin").github_auth.avatar_url
and you can use next field to redirect any addresses for example;
The user will be redirected to the same address after login.
<a href="{% url 'redirect-github' %}?next={{ request.META.PATH_INFO }}">login wia github</a>
Author / Social
π€ Hakan Γelik π€
Version Notes
V0.0.7
- Next attr added when login or logout
- Get email bug fixed
- Migrations files added
V0.0.5
- View ( update githubuser ) bug fixed
V0.0.2
- login
- logout
- get extra data