Wenche.Systembruker (wenche v0.1.1)

Copy Markdown View Source

System user flow for Altinn 3.

Ported from wenche/systembruker.py in the original Python Wenche project.

Altinn 3 requires that end-user systems register themselves in the system register and create a system user for each organization they will act on behalf of.

Required options

All public functions require a :name option — a short, lowercase identifier for the system (e.g. "kontira"). This is used to build the system ID (<vendor_orgnr>_<name>) and as the display name in Altinn.

registrer_system/4 additionally requires a :description option — a map with "nb", "nn", and "en" keys describing the system.

Setup (run once)

  1. registrer_system/4 — registers the system in Altinn's system register
  2. opprett_forespoersel/4 — sends request to org for approval
  3. User approves via confirmUrl in browser

For submission, use Wenche.Maskinporten.get_systemuser_token/2 to get a token.

Summary

Functions

Gets all approved system users for the system.

Creates a system user request for the organization.

Registers or updates the system in Altinn's system register.

Returns the list of resource IDs that the system requests access to.

Returns the raw rights structure used in Altinn API payloads.

Returns the system ID in the format <vendor_orgnr>_<name>.

Functions

hent_forespoersel_status(maskinporten_token, request_id, opts \\ [])

Gets the status of a system user request.

Returns {:ok, response_map} or {:error, reason}.

Optional options

  • :env"test" or "prod" (default: "prod")

hent_systembrukere(maskinporten_token, vendor_orgnr, opts \\ [])

Gets all approved system users for the system.

Returns {:ok, [system_user_map]} or {:error, reason}.

Required options

  • :name — short lowercase system identifier (e.g. "kontira")

Optional options

  • :env"test" or "prod" (default: "prod")

opprett_forespoersel(maskinporten_token, vendor_orgnr, org_nummer, opts \\ [])

Creates a system user request for the organization.

Returns {:ok, %{id: uuid, status: "New", confirmUrl: url}} or {:error, reason}.

The user must go to confirmUrl and approve in the browser.

Required options

  • :name — short lowercase system identifier (e.g. "kontira")

Optional options

  • :env"test" or "prod" (default: "prod")

registrer_system(maskinporten_token, vendor_orgnr, client_id, opts \\ [])

Registers or updates the system in Altinn's system register.

Tries POST first. If the system already exists, uses PUT to update.

Required options

  • :name — short lowercase system identifier (e.g. "kontira")
  • :description — map with "nb", "nn", "en" keys

Optional options

  • :env"test" or "prod" (default: "prod")

Returns {:ok, response_map} or {:error, reason}.

resource_ids()

Returns the list of resource IDs that the system requests access to.

Each entry is a short resource value string, e.g. "app_brg_aarsregnskap-vanlig-202406".

rights()

Returns the raw rights structure used in Altinn API payloads.

system_id(vendor_orgnr, name)

Returns the system ID in the format <vendor_orgnr>_<name>.