https://github.com/uptick/django-xauth
A simple Django application for AJAX authorisation.
https://github.com/uptick/django-xauth
Last synced: 10 months ago
JSON representation
A simple Django application for AJAX authorisation.
- Host: GitHub
- URL: https://github.com/uptick/django-xauth
- Owner: uptick
- License: bsd-3-clause
- Created: 2016-06-09T00:55:25.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2018-03-23T06:25:19.000Z (about 8 years ago)
- Last Synced: 2025-05-07T17:12:35.747Z (about 1 year ago)
- Language: Python
- Size: 11.7 KB
- Stars: 1
- Watchers: 0
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# django-xauth
[](https://badge.fury.io/py/django-ajax-auth)
Some simple AJAX authorisation endpoints for Django.
## Why?
I wanted a package to integrate AJAX authorisation with Django's
standard authorisation views. When a request is made via AJAX it
should be handled as such, and when a standard request is made the
login form should be rendered.
## Installation
`pip` is the easiest way to get the package:
```python
pip install django-ajax-auth
```
Add the package to your Django settings file:
```python
INSTALLED_APPS = [
'xauth',
...
]
```
Replace the standard authorisation URLs in your URL configuration:
```python
urlpatterns = [
url(r'^', include('xauth.login_ajax_urls'))
]
```
## Usage
Now you can either perform the usual non-AJAX GET and POST to login
as you would normally, or POST using `application/json` encoding to
login over AJAX.
```javascript
import $ from 'jquery'
$.ajax({
url: '/login',
method: 'POST',
contentType: 'application/json',
data: {
username: 'harry',
password: 'henderson123'
}
})
```
Sometimes you may wish to only allow AJAX logins, in which case set
`XAUTH_AJAX` to `True` in your settings file.