Hey Guys,
Just currently going through the Geotab verification process and I've been informed that our current implementation is causing excessive numbers of auth requests (Whereas it should be a max of 1 per 24 hours / service account). Our session Id auth has been implemented based on the documentation provided here: https://github.com/Geotab/mg-api-js but following the exact steps provided there for the credentials object it seems to not accept the session Id when authenticating the api instance.
This is an vague example of how we do authentication before a get feed call happens (that is invoked hourly by a cron job)
const getApi = (authentication: GeotabAuth, options?: GeotabAuthOptions) => {
return new GeotabApiWrapper(authentication, options);
};
export const getAuthedApi = async (
userId: string,
userSettings: VendorSettings,
) => {
const testAuthObj = {
credentials: {
userName: "username",
password: null,
database: "db",
sessionId: "2352afawfsfwa2",
},
path: "serverAddress",
};
const geotabApi = getApi(testAuthObj);
await geotabApi
.authenticate()
.then((response: any) => console.log("I have authenticated", response));
const currentSession = await geotabApi.getSession();
const currentSessionId = currentSession?.credentials?.sessionId;
if (currentSessionId !== userSettings.apiSessionId) {
// Update RTDB with new session ID
await UserModel.updateUserDeep(userId, {
vendorSettings: {
geotab: { apiSessionId: currentSessionId },
},
});
}
return geotabApi;
};
But for some reason I'm getting: Error: Must provide either password or session ID
The auth object structure is based on the docs but its not being accepted even though the session Id provided is fresh as it's been generated today by pw/username auth. (It works all fine with pw/username hence we didn't see any issues arising regarding auth yet but turns out its not utilising sessions properly)
Any ideas what we doing wrong here?