Skip to main content

CAM passport authentication for IBM Planning Analytics (TM1) with MFA support

Project description

tm1-auth

A Python library for authenticating with IBM Planning Analytics (TM1) in environments that use Cognos Access Manager (CAM) with multi-factor authentication.

TM1py requires a cam_passport to connect to CAM-secured environments, but obtaining one programmatically is non-trivial when MFA is involved. tm1-auth handles the browser-based login flow for you and captures the passport automatically.


Features

  • Automated CAM passport retrieval via a browser login window
  • Works alongside TM1py - pass the retrieved passport directly to TM1Service
  • Supports system browsers (Edge, Chrome) as well as Playwright's bundled Chromium
  • Optional in-memory passport caching via PassportCache
  • Cross-platform: Windows, macOS, Linux

Requirements

pip install playwright
playwright install chromium

Installation

pip install tm1-auth

Quick start

from tm1_auth import get_cam_passport
from TM1py import TM1Service

passport = get_cam_passport(
    auth_url="https://your-cognos-server/ibmcognos/bi/v1/disp"
)

with TM1Service(address="your-tm1-server", port=5001,
                cam_passport=passport, ssl=True) as tm1:
    print(tm1.server.get_product_version())

A browser window opens, you complete the login flow (including MFA), and the passport is captured automatically. The window closes once the passport is detected.


Multiple environments

By default all calls share the same browser profile (~/.tm1_auth/browser_profile). Whether this is useful depends on your setup.

Isolated sessions — use when environments have different credentials, or you want explicit login control for each:

stg_passport = get_cam_passport(
    auth_url="https://stg-cognos/ibmcognos/bi/v1/disp",
    profile_dir="~/.tm1_auth/stg",
)

prd_passport = get_cam_passport(
    auth_url="https://prd-cognos/ibmcognos/bi/v1/disp",
    profile_dir="~/.tm1_auth/prd",
)

Each call gets its own browser session and will prompt for login independently.

Shared session — use when environments share the same identity provider and you want to avoid repeated logins:

stg_passport = get_cam_passport(
    auth_url="https://stg-cognos/ibmcognos/bi/v1/disp",
)

prd_passport = get_cam_passport(
    auth_url="https://prd-cognos/ibmcognos/bi/v1/disp",
)

Both calls use the default shared profile. If your identity provider supports SSO, the second call may complete without prompting for credentials or MFA again. This is not guaranteed — it depends entirely on your IdP configuration and session policies.


Caching passports

If you connect to TM1 multiple times within the same script, use PassportCache to avoid repeated browser logins:

from tm1_auth import get_cam_passport
from tm1_auth.cache import PassportCache

cache = PassportCache(ttl_seconds=3600)

def get_passport(auth_url):
    passport = cache.get(auth_url)
    if not passport:
        passport = get_cam_passport(auth_url)
        cache.set(auth_url, passport)
    return passport

If a cached passport is rejected by TM1py, call cache.invalidate(auth_url) and re-authenticate:

try:
    tm1 = TM1Service(address=address, port=port,
                     cam_passport=get_passport(auth_url), ssl=True)
except Exception:
    cache.invalidate(auth_url)
    tm1 = TM1Service(address=address, port=port,
                     cam_passport=get_passport(auth_url), ssl=True)

PassportCache is in-memory only and does not persist across Python processes.


API reference

get_cam_passport

get_cam_passport(
    auth_url: str,
    profile_dir: str | None = None,
    timeout_seconds: int = 90,
    headless: bool = False,
    executable_path: str | None = None,
    verbose: bool = True,
) -> str
Parameter Description
auth_url The Cognos dispatcher URL (e.g. .../ibmcognos/bi/v1/disp)
profile_dir Persistent browser profile directory. Same directory = shared session. Different directories = isolated sessions. Defaults to ~/.tm1_auth/browser_profile.
timeout_seconds Seconds to wait for login before raising PassportTimeoutError. Default 90.
headless Run without a visible browser window. Not recommended for MFA flows. Default False.
executable_path Path to a specific browser executable. If not set, tries system Edge then Chrome then Playwright's bundled Chromium.
verbose Print progress messages to stdout. Default True.

Returns: The cam_passport cookie value as a string.

Raises:

  • AuthenticationError — browser failed to launch or could not navigate to the auth URL
  • PassportTimeoutError — no passport detected within timeout_seconds

PassportCache

PassportCache(ttl_seconds: int = 3600)
Method Description
get(auth_url) Return cached passport or None if missing/expired
set(auth_url, passport) Cache a passport
invalidate(auth_url) Remove a specific entry
clear() Remove all entries

Exceptions

from tm1_auth.exceptions import AuthenticationError, PassportTimeoutError

Both inherit from AuthenticationError. Catch AuthenticationError to handle all auth failures, or the specific subclass for finer control.


Roadmap

  • Windows integrated authentication (Kerberos / NTLM)
  • API key authentication (Planning Analytics on Cloud)
  • Async support

Contributing

Contributions welcome. Please open an issue before submitting a pull request for significant changes.


Licence

MIT

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

tm1_auth-0.1.0.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tm1_auth-0.1.0-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file tm1_auth-0.1.0.tar.gz.

File metadata

  • Download URL: tm1_auth-0.1.0.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for tm1_auth-0.1.0.tar.gz
Algorithm Hash digest
SHA256 69429c08f1c041355c27043a61df82356d9d9fec0cc7bbbe479ba248307108ae
MD5 7a38c3fd9617fe8a9cc191fd779af642
BLAKE2b-256 5c7cd8a83f277a8475ad6d5fc063b093ad7d51c42a0e7cf1cd0f24945d69c22d

See more details on using hashes here.

File details

Details for the file tm1_auth-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: tm1_auth-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for tm1_auth-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4c531113b952775eca4ae552e698438a7624d48bcc7b6478c7e9f70f7ced4572
MD5 87b6c7bf42945b78af5e5a9b54c4068a
BLAKE2b-256 f07e7f8836e21b04c34b12b3222969768887fca1d748f47523c3ffb0c70e67e6

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