django-otp-notify

PyPI Documentation Source

This is a django-otp plugin that delivers tokens via Notify’s SMS service.

See django-otp for more information on the OTP framework.

This project is heavily inspired by django-otp-twilio.

Installation

django-otp-notify can be installed via pip:

pip install django-otp-notify

Once installed it should be added to INSTALLED_APPS after django_otp core:

INSTALLED_APPS = [
    ...
    'django_otp',
    'django_otp.plugins.otp_totp',
    'django_otp.plugins.otp_hotp',
    'django_otp.plugins.otp_static',

    'otp_notify',
]

Notify SMS Devices

class otp_notify.models.NotifySMSDevice(*args, **kwargs)[source]

A SideChannelDevice that delivers a token via the Notify SMS service.

The tokens are valid for OTP_NOTIFY_TOKEN_VALIDITY seconds. Once a token has been accepted, it is no longer valid.

number

CharField: The mobile phone number to deliver to. Notify recommends using the E.164 format. For UK numbers, this would look like ‘+447900900123’.

exception DoesNotExist
exception MultipleObjectsReturned
generate_challenge()[source]

Sends the current TOTP token to self.number.

Raises:Exception if delivery fails.
verify_token(token)[source]

Verifies a token by content and expiry.

On success, the token is cleared and the device saved.

Parameters:token (string) – The OTP token provided by the user.
Return type:bool

Admin

The following ModelAdmin subclass is registered with the default admin site. We recommend its use with custom admin sites as well:

class otp_notify.admin.NotifySMSDeviceAdmin(model, admin_site)[source]

ModelAdmin for NotifySMSDevice.

Settings

OTP_NOTIFY_API_KEY

Default: None

Your Notify API key.

OTP_NOTIFY_ENDPOINT

Default: None

Your Notify endpoint.

OTP_NOTIFY_CHALLENGE_MESSAGE

Default: "Sent by SMS"

The message returned by generate_challenge(). This may contain '{token}', which will be replaced by the token. This completely negates any security benefit to the device, but it’s handy for development, especially in combination with OTP_NOTIFY_NO_DELIVERY.

OTP_NOTIFY_SENDER_ID

Default: None

The sender id used to send SMS messages from. This is generated via the Notify dashboard.

OTP_NOTIFY_NO_DELIVERY

Default: False

Send tokens to the ‘otp_notify.models’ logger instead of delivering them by SMS. Useful for development.

OTP_NOTIFY_THROTTLE_FACTOR

Default: 1

This controls the rate of throttling. The sequence of 1, 2, 4, 8… seconds is multiplied by this factor to define the delay imposed after 1, 2, 3, 4… successive failures. Set to 0 to disable throttling completely.

OTP_NOTIFY_TOKEN_VALIDITY

Default: 30

The number of seconds for which a delivered token will be valid.

Changes

Change Log

License

MIT License

Copyright (c) 2020 Canadian Digital Service – Service numérique canadien

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.