fenixedu_django

FenixEdu Django utilities


License
Other
Install
pip install fenixedu_django==1.0.2

Documentation

fenixedu_django

FenixEdu authentication backend for django framework. If you want to develop an app using django and use FenixEdu API to authenticate your users you can use this backend instead of writing all authentication code yourself ;)

If you don't know what the hell is FenixEdu check it out

FenixEdu.org

FenixEdu Developer

Installation

  • If you don't have fenixedu installed, install it first
pip install fenixedu
  • Install fenixedu django
pip install fenixedu-django

Usage

  • Add the FenixEdu authentication backend to your settings.py
AUTHENTICATION_BACKENDS = (
    'fenixedu.authentication.backend.FenixEduAuthenticationBackend',
)
  • Import fenixedu
import fenixedu
  • Instatiatie the FenixEdu Client

** See how here

FenixEdu Python SDK repository

client = fenixedu.FenixEduClient(...)
  • Add a link to the authentication url in your web page

** Example: Show the authentication url in index.html

*** In views.py

def index(request):
    context = {'auth_url': client.get_authentication_url()}
    return render(request, 'index.html', context)

*** In index.html

<a href="{{ auth_url }}">Login</a>
  • After the user logged in and authorized your application he will be redirected to the redirect URL, which will have a code parameter

  • In the view that will receive the code do the following:

code = request.GET.get('code', None)
if code is not None and not request.user.is_authenticated():
    user = authenticate(request=request, client=client, code=code)
    if user is not None:
        login(request, user)
  • Now your user is authenticated.

  • If you want to use FenixEdu API endpoints of private scope you can get the user object from the request

from fenixedu.authentication import users
...
user = users.get_fenixedu_user(request)
# Example: get person
person = client.get_person(user=user)

Any bug, request or anything else just open an issue ;)