Gemeente-DenHaag / mijngemeente-gateway

Public proxy gateway for the OpenZaak API.
Other
1 stars 0 forks source link

Basic ExpressJS server #2

Closed GewoonMaarten closed 3 years ago

GewoonMaarten commented 3 years ago

As a developer I want a basic nodejs server, so that I implement the other gateway stories.

Acceptance Criterion:

Out of scope

Example code for generating JWT (taken from postman)

function base64url(source) {
    // Encode in classical base64
    encodedSource = CryptoJS.enc.Base64.stringify(source);

    // Remove padding equal characters
    encodedSource = encodedSource.replace(/=+$/, '');

    // Replace characters according to base64url specifications
    encodedSource = encodedSource.replace(/\+/g, '-');
    encodedSource = encodedSource.replace(/\//g, '_');

    return encodedSource;
}

function addIAT(request) {
//  var iat = Math.floor(Date.now() / 1000) + 257;
    var iat = Math.floor(Date.now() / 1000);
    data.iat = iat;
    return data;
}

var header = {
    "typ": "JWT",
    "alg": "HS256"
};

var data = {
    "iss": pm.environment.get("client_id"),
    "client_id": pm.environment.get("client_id"),
    "user_id": "123",
    "user_representation": "Demo User"
};

data = addIAT(data);

var secret = pm.environment.get("secret");

// encode header
var stringifiedHeader = CryptoJS.enc.Utf8.parse(JSON.stringify(header));
var encodedHeader = base64url(stringifiedHeader);

// encode data
var stringifiedData = CryptoJS.enc.Utf8.parse(JSON.stringify(data));
var encodedData = base64url(stringifiedData);

// build token
var token = encodedHeader + "." + encodedData;

var signature = CryptoJS.HmacSHA256(token, secret);
signature = base64url(signature);

var signedToken = token + "." + signature;
ogjtech commented 3 years ago

As a developer I want a basic nodejs server, so that I implement the other gateway stories.

What is "basic"? Define what functionality should be developed, define if and where it should be hosted, when is the server classified as "a basic NodeJS server"? @mjcarsjens, @vwmvanbeek are there any criteria to this? I added some that seem obvious to me from a technical perspective.

vwmvanbeek commented 3 years ago

@mjcarsjens deze laat ik aan jou