Skip to main content

How To Properly Auth with SessionId NodeJS

DBene-1858
Original Poster

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?

 

Join the conversation

You need to be logged in to reply to this post and participate in the Geotab Community discussions.

2 Replies

EishiFUN
Geotabber

Hey @DBene-1858​  ,​ 

 

Thank you for asking your question in our community. I have contacted our SDK team to get their help with this. I will let you know as soon as I hear back from them.

 

Thank you for your patience while we look into this. Feel free to reach out with any other questions you have in the meantime. We are happy to help.

 

Have a great day!

Eishi FUN

EishiFUN
Geotabber

I just wanted to follow up on this post. I understand you had a meeting with our team and got this cleared up. Feel free to reach out to the community if any other questions come up. We are here to help!

Still have questions?