A django application to login with github.
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 urlLOGOUT_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", )- In your myapp/urls.py:
urlpatterns= [ ... path("accounts/github/", include('github_auth.urls')), ]- In your myapp/templates:
<ahref="{% 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
<imgsrc="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 fieldsrequest.user.github_auth.avatar_urlor
fromdjango.contrip.auth.modelsimportUseradmin_avatar_url=User.objects.get(username="admin").github_auth.avatar_urland you can use next field to redirect any addresses for example; The user will be redirected to the same address after login.
<ahref="{% url 'redirect-github' %}?next={{request.META.PATH_INFO }}">login wia github</a>👤 Hakan Çelik 👤
- Next attr added when login or logout
- Get email bug fixed
- Migrations files added
- View ( update githubuser ) bug fixed
- login
- logout
- get extra data