- 16 Nov 2022
-
DarkLight
-
PDF
Dynamic User Per Request
- Updated on 16 Nov 2022
-
DarkLight
-
PDF
Scenario
This system has authentication based on the person making the request (it does not use a system user).
The user credentials must be passed into the adapter method (in this case, there are two variables to pass in – dynuser and dynpass). However, we would rather pass them in a single object because that allows for easier expansion in the future.
Set the callProperties
object in the ReqObj
. Be sure to set username to the user variable (dynuser) and password to the password variable (dynpass) in the authentication section.
The adapter library will use these credentials instead of the credentials defined in the IAP Service Instance Configuration for the adapter. However, you should still input values into the IAP Service Instance Configuration for the adapter, or the adapter may not start up.
This requires a code change because you need additional data passed down to the adapter, and that data needs to be added to the request object passed down to the adapter library. It does not require any additional coding in the adapter library; the adapter library is prepared to handle this type of action.
Changes to the adapter.js
File:
- You will need to make changes to allow for the dynamic username and password to be passed into the adapter methods.
- Adding the credential object which will contain the two fields.
- Add the username and password information into the authentication section of the callProperties so it will override the IAP Service Instance Configuration for the adapter.
adapter.js Example
getMyData(query, credentials, callback) {
....
const reqObj = {
payload: { garbage: 'need since post' },
uriPathVars: [groupId, deviceId],
uriQuery: { name: 'anyname' },
uriOptions: { page: 2 },
addlHeaders: { audit: 'turnOn' },
authData: {},
callProperties: {
authentication: {
username: credentials.dynuser,
password: credentials.dynpass
}
},
filter: '[*name=doggie]'
};
Changes to the pronghorn.json
File:
- You will need to make changes to allow for the credential object to be passed into the adapter methods.
- Adding the input into every method defined in the pronghorn.json file.
pronghorn.json Method Example
{
"name": "getMyData",
"summary": "get my data from blah",
"description": "get my data from blah",
"input": [
{
"name": "query",
"type": "object",
"info": "object containing query fields",
"required": false,
"schema": {
"title": "query",
"type": "object"
}
},
{
"name": "credentials",
"type": "object",
"info": "Should contain 2 fields - dynuser and dynpass",
"required": true,
"schema": {
"title": "credentials",
"type": "object"
}
}
],
"output": {
"name": "result",
"type": "object",
"description": "A JSON Object containing status, code and the result"
},
"route": {
"verb": "POST",
"path": "/getMyData"
},
"roles": [
"admin"
],
"task": true
},