•  Home
  •  Dashboard
  •  Company
    • About Us
    • Blog
    • Careers
    • Contact Us
    • Data Centers
    • Looking Glass
    • Network
    • Reseller
  •  Hosting Services
    • Infrastructure
      • iColocation
    • Compute
      • cMetal
      • cVirtual
    • Storage
      • sObject
      • sBlock
    • Networking
      • nIP Transit
      • nWavelength
    • Protection
      • pBackup
      • pDDoS
  •  Solutions
    • Ecommerce
    • Finance
    • Gaming
    • Hosting
    • Management
    • Security
    • System Integrator
  •  Support
    • Community
    • Knowledge Base
    • Open A Ticket
    • Status
  •  USA & Canada: 800-933-1517
  •  International: 626-549-2801
  •  Email: sales@psychz.net
  • Services
    • new-colocation-header-img
      Infrastructure
      • iColocation
    • new-compute-header-img
      Compute
      • cMetal
      • cVirtual
    • new-storage-header-img
      Storage
      • sObject
      • sBlock
    • new-networking-header-img
      Networking
      • nIP Transit
      • nWavelength
    • new-protection-header-img
      Protection
      • pBackup
      • pDDoS
  • Solutions
    • Ecommerce
    • Security
    • Gaming
    • Hosting
    • Management
    • Finance
    • System Integrator
  • Dashboard

Secure Token Integration For Python

  • Home
  • Client
  • Knowledgebase
  • CDN
  • CDN Security
  • Secure Token Integration For Python

Table Of Content

    Related Articles

    • Secure Token Integration For PHP (Secondary)
    • Secure Token Integration For Python (Secondary)
    • Secure Token Integration For PHP
    • CDN URL Token Authentication
    • Add Security Token
    • Security token intro
    • Add DDoS Exemption

    Secure Token Integration For Python

    Publisher: Psychz Networks April 21,2021

    The following article will help you to integrate secure token generated using a secret key in your Python code. First, you need to login to the dashboard and enable Secure Token option for the desired location (domain). Once you enable Secure Token option, you can create a 'Secret Key' which will be then passed on to our backend. With this, you can generate your own tokens with md5 using the Pyhon script below. The newly generated URL then will hold all the necessary information which will match the Secure key saved at our backend and will allow access to the user.

    Sample security token looks like

    domain.com/?md5=Rbp0ZArvj3m3aOQNjo75Xg&
    expires=1619082510

    Once the security token is generated, you can use it in Python code to create the URL token.

    #!/usr/bin/env python3
    import hashlib
    from base64 import b64encode
    from time import time

    def generate_secure_url(security_key, path,
    expire_timeframe="",
    base_url=str(),
    filtered_ip=""):

    expire_timestamp = int(time()) + 3600
    token_content = '{key}{path}{timestamp}{filtered_ip}'.format(
    key=security_key,path=path,
    timestamp=expire_timeframe,
    filtered_ip=filtered_ip)
    md5sum = hashlib.md5()
    md5sum.update(token_content.encode
    ('ascii'))
    token_digest = md5sum.digest()
    token_base64 = b64encode(token_digest).decode
    ('ascii')
    token_formatted = token_base64.replace('\n', '').replace('+', '-').replace('/', '_').replace('=', '')

    # Build the URL
    if expire_timeframe:
    url = '{base_url}{path}?md5={token}&expires={expire_timestamp}'.format(
    base_url=base_url,
    path=path,
    token=token_formatted,
    expire_timestamp=expire_timeframe)
    if not expire_timeframe:
    url = '{base_url}{path}?md5={token}'.format(
    base_url=base_url,
    path=path,
    token=token_formatted)

    return url

    # Example usage:
    # Returns: 'https://test.youdomain.com/index.html?md5=xn3MXhSmjhMvAlE__w5nGQ'
    print('https://test.youdomain.com'+
    generate_secure_url('secret-key', '/index.html','','','11.2.3.4'))

    # Returns: 'https://yourdomain.com/index.html?md5=-yTNoTfS_NiwhPxH2xYcZg&
    expires=31536000
    '
    print(generate_secure_url('secret-key', '/index.html', 31536000, 'https://yourdomain.com', '1.2.3.4'))

    Views: (1672) Votes: (0)

    Related Articles

    • Secure Token Integration For PHP (Secondary)
    • Secure Token Integration For Python (Secondary)
    • Secure Token Integration For PHP
    • CDN URL Token Authentication
    • Add Security Token
    • Security token intro
    • Add DDoS Exemption
    Copyright © 2026 Psychz Networks,
    A Profuse Solutions Inc Company
    Hosting Services
    • Catalog
    Infrastructure
    • iColocation
    Compute
    • cMetal
    • cVirtual
    Storage
    • sObject
    • sBlock
    Networking
    • nIP Transit
    • nWavelength
    Protection
    • pBackup
    • pDDoS
    Company
    • About Us
    • Blog
    • Careers
    • Contact Us
    • Data Centers
    • Looking Glass
    • Network
    • Reseller
    Policies
    • Acceptable Usage Policy
    • Privacy Policy
    • Service Level Agreement
    • Terms and Conditions
    Support
    • Community
    • Knowledge Base
    • Open A Ticket
    • Status
    Get In Touch
    • Psychz Networks,
      A Profuse Solutions Company
      611 Wilshire Blvd #300
      Los Angeles,California 90017
      USA
    • US/Canada: 800-933-1517
    • International: 626-549-2801