Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sophi-app-internal

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sophi-app-internal

  • 0.1.23
  • PyPI
  • Socket score

Maintainers
2

sophi-app-internal Python Package

Overview

sophi-app-internal is a Python package designed to facilitate secure and authenticated HTTP request handling, particularly in environments where JWT (JSON Web Token) authentication is used. The package includes utilities for validating JWTs, fetching public keys, constructing HTTP request objects with robust header and parameter management, and interacting with Azure Cosmos DB.

Features

  • JWT validation and verification using Auth0.
  • Secure fetching of JSON Web Key Sets (JWKS).
  • Construction and management of HTTP request objects with headers, parameters, and body handling.
  • Azure Cosmos DB client for querying and managing documents.

Installation

To install the sophi-app-internal package, use the following command:

pip install sophi-app-internal

Token Validator Usage

Setting Up Variables

Before using the package, ensure you have set up the necessary environment variables:

  • AUTH0_DOMAIN: Your Auth0 domain, e.g. <tenant>.us.auth0.com.
  • AUTH0_AUDIENCE: The expected token audience.

Note: client ID and client secret are not required to validate tokens

You can set these variables in your environment or pass them directly when initializing the Auth0ManagementApiClient.

Note: You need to register your API on Auth0 before getting a valid audience value.

Example Code

Here's an example of how to use the token_validator method:

from sophi_app_internal.integrations.auth0.management_api import Auth0ManagementApiClient

# Initialize the client
auth0_client = Auth0ManagementApiClient()

token = "<your token>"  # Ensure you remove the 'Bearer' keyword if present

# Validate the token
try:
    claims = auth0_client.token_validator(token)
    user_id = claims['sub']
    print(user_id)
except Exception as e:
    print(e)

Cosmos DB Client Usage

Setting Up Variables

Before using the Cosmos DB client, ensure you have set up the necessary variables:

  • COSMOS_CONNECTION_STRING: Your Azure - Cosmos DB connection string.
  • DB_NAME: The name of your database.
  • CONTAINER_NAME: The name of your container.

You can set these variables in your environment:

import os

connection_string = os.getenv("COSMOS_CONNECTION_STRING")
db_name = "your_db_name"
container_name = "your_container_name"

Example Code

Using CosmosContainerClient

Here's an example of how to use the CosmosContainerClient to query and manage documents in Azure Cosmos DB.

import os
import logging
from sophi_app_internal import CosmosContainerClient

# Set up logging
logging.basicConfig(level=logging.INFO)

# Set up connection variables
connection_string = os.getenv("COSMOS_CONNECTION_STRING")
db_name = "your_db_name"
container_name = "your_container_name"

# Initialize the client
client = CosmosContainerClient(connection_string, db_name, container_name)

# Query from the initial container
query = "SELECT * FROM c"
user_id = "1234"
partition_key = [user_id]
documents = client.query_cosmosdb_container(query, partition_key)
print(documents)

# Switch to a different database and container
new_db_name = "another_db_name"
new_container_name = "another_container_name"
client.set_database_and_container(new_db_name, new_container_name)

# Query from the new container
documents = client.query_cosmosdb_container(query)
print(documents)

# Upsert a document
document = {
    "id": "1",
    "name": "Sample Document",
    "description": "This is a sample document."
}
client.upsert_cosmosdb_document(document)

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc