Skip to main content

JetStream Authentication MiddleWare

Project description

JSA Auth Middleware is a python package built for integrating with JetStream across multiple micro-services, with the aim of handling authentication and Single-Sign-On while ensuring API security.

Quick start

  1. Configure AUTH_BASE_URL in project settings pointing to the Authentication server without trailing slash

  2. Add jsa_auth_middleware.JSAMiddleware to your MIDDLEWARE configuration in settings.py to validate authentication of all incoming requests. Maintain the order and hierarchy of middlewares, with Django middlewares above JSAMiddleware.

    MIDDLEWARE = [
        ...
        'jsa_auth_middleware.JSAMiddleware',
    ]
  3. Setup JSAMiddleware configuration in settings.py:

    JSA_AUTH_MIDDLEWARE_CONFIG = {
        'IGNORE_URLS': (
            '<<URL_TO_IGNORE>>',
        ),
        'IGNORE_STARTSWITH_URLS': (
            '<<URL_TO_IGNORE>>',
        ),
        'AUTH_BASE_URL': '', # optional if variable isn't in `settings.py`
    }
  4. To interact with the API:

    from jsa_auth_middleware import JSAMiddleware
    
    jsa_auth = JSAMiddleware()
    
    # To get key
    # Pass baseb4 encoded string of '<username>:<password>'
    status_code, response_data = jsa_auth.get_key(token)
    
    # Sample response data
    """
    data = {
        "token": "*****"
    }
    status_code = 200
    
    returns status_code, data
    """
    
    
    # To authenticate
    # Pass token key gotten from the get_key method
    
    status_code, response_data = jsa_auth.get_auth_token(token)
    
    # Sample response data
    """
    data = {
        "token": "*****"
    }
    status_code = 200
    
    returns status_code, data
    """
  5. Import Query Response across application to define and process API response:

    from jsa_auth_middleware.query_response import Response
    
    
    resp = Response()
    resp.failed() # on failure, using default failure status_code
    resp.message = '<<Some response message>>'
    resp.add_params('<<data_key>>', <<data_value>>)
    
    
    resp = Response()
    resp.passed() # on success, using default success status_code
    resp.message = '<<Some response message>>'
    resp.add_params('<<data_key>>', <<data_value>>)
    
    
    # Setting response status code
    resp.status_code = <<CustomStatusCode>>

NOTE

The IGNORE_STARTSWITH_URLS in JSA_AUTH_MIDDLEWARE_CONFIG has the following default pre-defined endpoints patterns to be ignored:

(
    "/admin/",
    "/swagger/",
    "/redoc/",
)

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

jsa-auth-middleware-0.0.3.4.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

jsa_auth_middleware-0.0.3.4-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file jsa-auth-middleware-0.0.3.4.tar.gz.

File metadata

  • Download URL: jsa-auth-middleware-0.0.3.4.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.7

File hashes

Hashes for jsa-auth-middleware-0.0.3.4.tar.gz
Algorithm Hash digest
SHA256 39dec4f5664e4588735ee4ba1a9f020eea6efcf9b9f28ead305689cc13f0980b
MD5 2262c753f26b0dde8df0d80edc031d61
BLAKE2b-256 2715813de0652f64b1a75192feca65f76c944fbc5303fa5939cf55ba3af991d3

See more details on using hashes here.

File details

Details for the file jsa_auth_middleware-0.0.3.4-py3-none-any.whl.

File metadata

  • Download URL: jsa_auth_middleware-0.0.3.4-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.7

File hashes

Hashes for jsa_auth_middleware-0.0.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b75a308dbe40de53b3a20ed35744de3efa60a3d3b7124b22ede4be50ee51e54a
MD5 c45f2f658ab9caec8db10926f61c471c
BLAKE2b-256 97d1cf02a08e8a00e46c0db22db57745b1413dc47e34697678d84e8fa7cd6e2a

See more details on using hashes here.

Supported by

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