Skip to main content

A Campgrounds Synapse module that generates an n-digit verification code when signing up through email.

Project description

Request Digit Token

A Campgrounds Synapse module that generates an n-digit verification code when signing up through email.

Installation

From the virtual environment that you use for Synapse, install this module with:

pip install path/to/synapse-request-digit-token

(If you run into issues, you may need to upgrade pip first, e.g. by running pip install --upgrade pip)

Config

Add the following to your homeserver configuration under modules:

modules:
  - module: request_digit_token.RequestDigitToken
    config:
      # The length of the digit token.
      token_length: 6
      # How long before the digit token expires.
      token_lifetime: "1h"

Routes

This module exposes two HTTP routes for requesting and validating a digit token:

Request Token

Sends an n-digit token to the specified email.

URL

POST /_synapse/client/register/email/requestToken

Data Params

  • email - The signup email.
  • client_secret - The client secret.
  • send_attempt - The number of request attempts.
{
   "email": "test@mailer.com",
   "client_secret": "test_secret",
   "send_attempt": 1
}

Response

Status: 200 OK

{
   "sid": "wcgdeXSQmlODwfDB"
}

Status: 400 Bad Request, 500 Server Error

{
    "errcode": "",
    "error": ""
}

Validate Token

Validates the token from the client.

URL

GET /_synapse/client/register/email/validateToken

Query Params

  • token - The digit token.
  • client_secret - The client secret.
  • sid - The session id.
?token=123456&client_secret=test_secret&sid=wcgdeXSQmlODwfDB

Response

Status: 200 OK

{}

Status: 400 Bad Request, 500 Server Error

{
    "errcode": "",
    "error": ""
}

Development

In a virtual environment with pip ≥ 21.1, run

pip install -e .[dev]

To run the unit tests, you can either use:

tox -e py

or

trial tests

To run the linters and mypy type checker, use ./scripts-dev/lint.sh.

Releasing

The exact steps for releasing will vary; but this is an approach taken by the Synapse developers (assuming a Unix-like shell):

  1. Set a shell variable to the version you are releasing (this just makes subsequent steps easier):

    version=X.Y.Z
    
  2. Update setup.cfg so that the version is correct.

  3. Stage the changed files and commit.

    git add -u
    git commit -m v$version -n
    
  4. Push your changes.

    git push
    
  5. When ready, create a signed tag for the release:

    git tag -s v$version
    

    Base the tag message on the changelog.

  6. Push the tag.

    git push origin tag v$version
    
  7. If applicable: Create a release, based on the tag you just pushed, on GitHub or GitLab.

  8. If applicable: Create a source distribution and upload it to PyPI:

    python -m build
    twine upload dist/request_digit_token-$version*
    

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

synapse_request_digit_token-1.0.0.tar.gz (6.6 kB view details)

Uploaded Source

File details

Details for the file synapse_request_digit_token-1.0.0.tar.gz.

File metadata

File hashes

Hashes for synapse_request_digit_token-1.0.0.tar.gz
Algorithm Hash digest
SHA256 da5a5c1f6ce43476f33b8b88efa13ed3e9a27ff6b43445bf6538bca53352e26b
MD5 98275197d178abbe2dfa19a84506fc9e
BLAKE2b-256 7aa033ba492b01f9e31a2cc76ef41ef0e4d63a1e51f2d4a0065c96c528a4b9b1

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