Skip to main content

Django-Xero

Xero integration for Django.

Features

This package allows users to authenticate to Xero via a Public App that you have registered on the Xero Developer Portal.

Whenever you want to trigger authentication with Xero, just redirect to the view xero_auth_start (either directly or via resolve('xero-auth-start') and this package will do the rest. The view also accepts an optional nextparameter to control where the user will land on successful authentication; otherwise it will redirect to /.

Xero sessions last for 30 minutes, but if you want to end them earlier, POST to the view xero_logout (again with an optional next).

There is also a @xero_required decorator for views, which will automatically check if an active Xero session is present. If not, it will redirect to an interstitial page asking the user to do the authentication dance. You can control that page by creating a custom template xero/interstitial.html (make sure it has a link to xero-auth-start somewhere).

Once authorized, in your view you will get a .xerouser attribute which you can use to do stuff like:

from djxero.decorators import xero_required

@login_required
@xero_required
def my_view(request):
    client = request.user.xerouser.client
    contacts = client.contacts.all()
    ...

That client is a preconfigured xero.Xero object from pyxero.

Some details will be exposed in User instances under .xerouser, but the Xero mechanisms are such that it's all pretty meaningless - there is currently no way to know anything about the user from the xero session alone. For that reason, note that you must have some other registration mechanism to create a regular Django user first (e.g. regular login page with some other auth system); this package only extends that User instance to attach a temporary Xero session.

If your User model has the same email or firstname/lastname as recorded in Xero, you can try to guess its details with request.user.xerouser.guess_user() and then manually save the ID in request.user.xerouser.xero_id, but the heuristic is very basic and may or may not work.

Supported Platforms

  • Python 3.7 (should work on 3.5/3.6 too, but is untested).
  • Django 2

Requirements

django-xero should automatically download all necessary prerequisites, but I like to give credit where credit is due. We stand on the shoulders of the following giants:

Installation

  1. Install the package
    pip install django-xero
    
  2. Add encrypted_model_fields and djxero to INSTALLED_APPS in your settings. Note that the authentication system is required.
    INSTALLED_APPS = [
        'django.contrib.auth',
        'django.contrib.sessions',
        ...
        'encrypted_model_fields',
        'djxero',
        ...
    ]
    
  3. Generate an encryption key:
    python -c 'import base64; import os; print(base64.urlsafe_b64encode(os.urandom(32)))'
    
    and add it to your settings. NOTE: in production, you want to store this safely.
    FIELD_ENCRYPTION_KEY = b'A7c4T1Kx3XmttUjm2cX8ScYcUEdF7RzFziEzfoBO7x4='
    
  4. Run migrations to create the necessary objects
    python manage.py migrate djxero
    
  5. Set the Xero secrets for your public app. You can do this from the admin site (easier), or directly via manage.py shell:
    from djxero.models import XeroSecret
    consumer_key = XeroSecret.objects.get(pk='xero_consumer_key')
    consumer_key.value = 'your key'
    consumer_key.save()
    consumer_secret = XeroSecret.objects.get(pk='xero_consumer_secret')
    consumer_secret.value = 'your secret'
    consumer_secret.save()
    
  6. in your project urls.py, add the following:
    urlpatterns = [
       path('xero/', include('djxero.urls')),
       ...
    ]
    

Issues

For problems, file an issue on GitHub. The author is available for hire (hint hint).

Credits and License

Copyright (c) 2019 Giacomo Lacava.

Released under the terms of the Apache Software License, version 2.

Release files for django-xero 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-xero 0.0.3
File Size Uploaded
django-xero-0.0.3.tar.gz 6.8 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-xero 0.0.3
File Interpreter ABI Platform
django_xero-0.0.3-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 6.8 MB

Release files / django-xero-0.0.3.tar.gz

Download URL django-xero-0.0.3.tar.gz
Size 6.8 MB
Tags Source
SHA-256 checksum
How to use checksums
ac6d912e8773f61500dd4f4a08635c53a13e5b72a84f15171be4b9ca7637e5ad
BLAKE2b-256 checksum
How to use checksums
1d7f2f4f8c2c73bb50614185e38131c46f53c5b0129339f5b1127b05713e85ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

Release files / django_xero-0.0.3-py2.py3-none-any.whl

Download URL django_xero-0.0.3-py2.py3-none-any.whl
Size 17.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
9f9bc446c430c720b4a153bc7e52ab8ef4f889260f091c61fae41657d7a1fbbd
BLAKE2b-256 checksum
How to use checksums
17363b4cbb47d5d4ff4a29985f7e9b83a0c34632f6ac66402358944735959303
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page