OpenFn / lightning

OpenFn/Lightning ⚡️ is the newest version of the OpenFn DPG and provides a web UI to visually manage complex workflow automation projects.
https://openfn.github.io/lightning/
GNU Lesser General Public License v3.0
115 stars 31 forks source link

Credentials UI adds empty values #2189

Open josephjclark opened 2 weeks ago

josephjclark commented 2 weeks ago

When creating a credential in Lightning, values the user does not set can still end up generating a key on the config object.

In commcare, it just happens that this breaks authorisation and the credential doesn't work in some cases. Lightning generates a config object like this:

{
  "username": "joe",
  "password": "i-love-lightning",
  "apikey": "",
}

To reproduce

fn((state) => { 
   console.log(state.data)
   return state
})

You should see that the created credential sets apiKey to empty value, apiKey: "", even though we didn't ask for an API key

Adaptors note

This stuff probably doesn't usually matter, but it just so happens that commare does this:

if ('apiKey' in auth) {
  Object.assign(headers, {
    Authorization: `ApiKey ${auth.username}:${auth.apiKey}`,
  });
} else if ('password' in auth) {
  Object.assign(headers, makeBasicAuthHeader(auth.username, auth.password));
}

We could easily add a workaround in commcare to not use in. But I also think in is a reasonable pattern

The credential doesn't mark apiKey as required or set a default, so I don't know why this key gets set. Oh, it does set minLength, I don't know if that's part of the problem?