How to use REST API in connect express app?

I want to use JWT with httpClient, but httpClient is null.
I think I’m missing something.

index.js

...
  app.get("/test", addon.checkValidToken(), (req, res) => {
    let httpClient = addon.httpClient(req);
    console.log(httpClient);    // null
    console.log(req.clientKey); // undefined
    httpClient.get(...);        // Cannot read property 'get' of null
    res.render("test.jsx", {
      title: "Atlassian Connect",
    });
  });

atlassian-connect.json

...
    "authentication": {
        "type": "jwt"
    },
    "lifecycle": {
        "installed": "/installed" ,
        "uninstalled": "/uninstalled",
        "enabled": "/enabled",
        "disabled": "/disabled"
    },
    "scopes": ["READ","WRITE"],
    "apiVersion": 1,
    "modules": {
        "generalPages": [
            {
                "url": "/test",
                "key": "hello-world",
                "location": "system.top.navigation.bar",
                "name": {
                    "value": "Hello-World"
                }
            }
        ]

Try calling the ACE middleware with

app.get("/test", addon.authenticate(true), (req, res) => ...

this should populate addon.httpClient correctly.

2 Likes

Thanks for reply.
It returned 401 error.
Maybe my app does not have JWT enabled :frowning: