Code Monkey home page Code Monkey logo

fenixedu_django's Introduction

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 ;)

fenixedu_django's People

Contributors

samfcmc avatar

Stargazers

 avatar

Watchers

 avatar  avatar

fenixedu_django's Issues

Invalid import in backend.py

As of Django 1.8 (at least) the check_password method is now part of the django.contrib.auth.models.User so this import statement fails to execute. The import for the check_password should be removed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.