You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
commcare at the moment uses two different auth schemes: basic and api key.
This is fine, but a big problem is that different functions supports different schemes.
I presume that any commcare API can use either auth, but this needs validating.
We should ensure that the new request helper is smart enough to load the two different credential types from config, and set up the header appropriately.
Design
Here's what I suggest
When calling request, we should pass state.config as the first argument:
request(state.configuration, { path: 'case' })
That way, you don't need to pass the whole state object.
The request signature should like be:
request(auth: Object, options: Object): Promise<>
We should not need to pass authType into the request at all.
Inside request, we set set the Authorization differently depending on the shape of auth:
If there's an apikey,we do Authorization: ApiKey ${username}:${apiKey},
Otherwise if there's a password, we do: Authorisation: ${Buffer.from(${username}:${password}).toString('base64')}
Otherwise we should probably throw an error like "no authorisation credentials provided"
Note that we don't do any of this if an Authorization header has already been set
commcare at the moment uses two different auth schemes: basic and api key.
This is fine, but a big problem is that different functions supports different schemes.
I presume that any commcare API can use either auth, but this needs validating.
We should ensure that the new
request
helper is smart enough to load the two different credential types from config, and set up the header appropriately.Design
Here's what I suggest
When calling request, we should pass state.config as the first argument:
That way, you don't need to pass the whole state object.
The request signature should like be:
We should not need to pass
authType
into the request at all.Inside
request
, we set set the Authorization differently depending on the shape ofauth
:Authorization:
ApiKey ${username}:${apiKey},
Authorisation: ${Buffer.from(
${username}:${password}).toString('base64')}
We probably want a helper function like:
I'd love to see some unit tests against that function!
The text was updated successfully, but these errors were encountered: