Skip to main content

OAuth2 login provider for VATSIM using django-allauth.

Project description

django-allauth-vatsim

OAuth2 login provider for VATSIM using django-allauth.

Description

Welcome to django-allauth-vatsim!

This OAuth2 provider for django-allauth enables users to log in using their account on the VATSIM online ATC network. The following components are included:

  • OAuth2 provider for VATSIM (supports both production and sandbox environments).
  • Social account adapter which can optionally be used to populate the user model with VATSIM-specific account details, such as a user's CID, pilot / controller rating and ATC division.
  • Implementation of a basic test case to ensure that the login provider works as expected.

Installation

To get started, install and configure django-allauth as described here. Next, install django-allauth-vatsim into your project.

pip install django-allauth-vatsim

In your settings.py file, add it to your INSTALLED_APPS list so it looks similar to this:

INSTALLED_APPS = [
    # Django apps
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "django.contrib.sites",
    # 3rd party apps
    "allauth",
    "allauth.account",
    "allauth.socialaccount",
    "django_allauth_vatsim",
]

Also, add the base VATSIM OAuth2 URL:

The corresponding line in your settings.py file should look like the following:

VATSIM_OAUTH_URL = "https://auth.vatsim.net"

Finally, you need to configure the credentials (client ID and secret) which you have obtained from VATSIM. As these are sensitive credentials, it is highly recommended to store them as environment variables using a package such as environs. The provider configuration should be specified as follows:

SOCIALACCOUNT_PROVIDERS = {
    "vatsim": {
        "APP": {
            "client_id": "<YOUR_CLIENT_ID>",
            "secret": "<YOUR_CLIENT_SECRET>",
        }
    },
}

Once all of the above is done, you can start using the new login provider, e.g. by using the following tag in your login template to initiate the authentication flow:

{% provider_login_url 'vatsim' %}

Optional: adding the social account adapter to populate user profiles

If you like, you can utilize the included social account adapter to populate a user's profile in your database with additional details, such as their CID, VATSIM division, and controller / pilot rating information.

The adapter is configured to store this information in a Profile database model that is linked to the user model with a one-to-one relationship, which means it is also necessary to set up and configure a basic customized user model to make this work, preferably in a dedicated accounts app. The steps required to set this up are beyond the scope of this README, but this excellent tutorial will guide you through the process. As an example, the CustomUser and UserProfile models that I created while working on this look as follows:

from django.contrib.auth.models import AbstractUser
from django.db import models

class CustomUser(AbstractUser):
    pass


class UserProfile(models.Model):
    user = models.OneToOneField(CustomUser, on_delete=models.CASCADE, related_name='profile')
    cid = models.IntegerField(primary_key=True)
    rating_id = models.IntegerField()
    rating_long = models.CharField(max_length=100)
    rating_short = models.CharField(max_length=50)
    region_id = models.CharField(max_length=20)
    region_name = models.CharField(max_length=100)
    division_id = models.CharField(max_length=20, blank=True, null=True)
    division_name = models.CharField(max_length=100, blank=True, null=True)
    pilot_rating_id = models.IntegerField()
    pilot_rating_long = models.CharField(max_length=100)
    pilot_rating_short = models.CharField(max_length=50)
    subdivision_id = models.CharField(max_length=20, blank=True, null=True)
    subdivision_name = models.CharField(max_length=100, blank=True, null=True)

    def __str__(self):
        return f"{self.user.username} {self.cid}"

If you decide to set this up in your project, add the following line to settings.py to register the social account adapter:

SOCIALACCOUNT_ADAPTER = "django_allauth_vatsim.adapter.VATSIMSocialAccountAdapter"

Contributing

As this is my first time publishing a Python package and also my first time developing a plugin for django-allauth, it's very much possible that I've overlooked something obvious that could make this project even more stable and / or useful. As such, contributions, suggestions and constructive criticisms are most welcome and greatly appreciated. If you do encounter any issues or would like to improve this package, feel free to open an issue or submit a pull request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_allauth_vatsim-0.0.1.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_allauth_vatsim-0.0.1-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file django_allauth_vatsim-0.0.1.tar.gz.

File metadata

  • Download URL: django_allauth_vatsim-0.0.1.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for django_allauth_vatsim-0.0.1.tar.gz
Algorithm Hash digest
SHA256 2fce9657a28eaf43daa8bebf02a37311ddda8f9e559aa60dca224a4feef51639
MD5 675ed435e39c103bcc68d1948411f735
BLAKE2b-256 c94e200212f40c4d237f3d81bf254f4ee2e1885bb4bb01f4324466fed24a2003

See more details on using hashes here.

File details

Details for the file django_allauth_vatsim-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_allauth_vatsim-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 89e953aa6a93468365fb65f5590956da7c1653bc777660629cb38a9ccaf2844e
MD5 9b32b1d2383cd3f65fe31fbf15625a69
BLAKE2b-256 2c0548023ee1dbc3c2dd5a19b0f1a20cca71835d2cbcdf5361d8adb800279d0f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page