Skip to content

torleifg/digdir

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Digdir

Getting Started

Install Miniconda (https://docs.conda.io/en/latest/miniconda.html)

Prerequisites (Selvbetjening)

Prerequisites (Maskinporten)

  • Test and/or production Maskinporten Client
  • Test and/or production JWKS file

Installation

  1. Clone the repo
git clone https://github.com/torleifg/digdir.git
  1. Add channel
conda config --add channels conda-forge
conda config --set channel_priority strict
  1. Create environment
conda create --name <environment> jwcrypto pyjwt urllib3
  1. Activate environment
conda activate <environment>

Usage

Selvbetjening

Add PKCS #12 file

mkdir /cert
cp <path>/*.p12 cert/*.p12

Modify configuration

cd config

cp selvbetjening.ini selvbetjening-local.ini
vim selvbetjening-local.ini

Use

import digdir, json, uuid

s = digdir.Selvbetjening('config/selvbetjening-local.ini', 'VER2')

jwt_grant = s.create_jwt_grant()
access_token = s.get_access_token(jwt_grant)

client = s.create_client(access_token, 'client_name', 'scope1 scope2')
client_id = json.loads(client.data.decode('utf-8'))['client_id']

kid = str(uuid.uuid4())
jwks = digdir.create_jwks(kid)

f = open('cert/keyset.jwks', 'w')
f.write(jwks.export())
f.close()

response = s.add_keyset_to_client(access_token, client_id, jwks.export())

Maskinporten

Modify configuration

cd config

cp maskinporten.ini maskinporten-local.ini
vim maskinporten-local.ini

Use

import digdir, json

m = digdir.Maskinporten('config/maskinporten-local.ini', 'VER2')

f = open('cert/keyset.jwks')
jwks = f.read()
f.close()

jwt_grant = m.create_jwt_grant('client_id', 'scope', 'kid', jwks)
access_token = m.get_access_token(jwt_grant)

person = m.get_krr_person(access_token, 'person_id')

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages