AI / Agents

Skills
llms.txt
llms-full.txt

Developers

Novica Nakov

Author

Norwegian Veterinary Institute

Norwegian Veterinary Institute

Copyright holder, funder

Community

Full license Apache-2.0
Citing pymaskinporten

Meta

Requires: Python >=3.13

pymaskinporten

This is a python package to request a token from Maskinporten - the Norwegian national access control solution for businesses that exchange data.

graph LR
  Consumer["Application"] -- request token ---> Maskinporten
  Maskinporten -- issue new token ---> Consumer
  Consumer -- use token ---> Service["External Service"]

Example usage

This assumes that: 1. You have created the integration on digidir.no and, 2. You have set the necessary environment variables for your API credentials.

## set environment variables for your API
import os
os.environ["KID"] = "your_kid"
os.environ["PRIVATE_KEY"] = "your_private_key"
os.environ["MASKINPORTEN_CLIENT_ID"] = "your_client_id"
os.environ["SCOPE"] = "your_scope"

## get the access token
from pymaskinporten.request_token import request_maskinporten_token
access_token, expires_in = request_maskinporten_token("my_api", "test")
print(f"Access Token: {access_token}")
print(f"Expires In: {expires_in} seconds")

Docker container

If you want to test the library through a web browser the image opens a flask app:

cat > .env <<EOF
>PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n"
>MASKINPORTEN_CLIENT_ID="your-client-id"
>KID="your-kid"
>SCOPE="your-scope"
>STRICT_KEY_VALIDATION=false
>EOF

docker run -p 5000:5000 --env-file .env ghcr.io/norwegianveterinaryinstitute/pymaskinporten:main