Can I make Auth0 management api client singleton?

Hello All,
My api authentication token lifetime is big, I want to make the management api client singleton so that I don’t need to generate token every time and initiate management api client for each request.

Now the question is whether management api client is capable or not to make it singleton because, behind the scene, its call http request and I don’t know whether the socket connection keep live for long?

You shouldn’t need to get a new token every time you want to make a request. I am not sure on making it a singleton, but the management client may allow you to store the token, then request a new one when it expires, rather than instantiating a new client for every request. What library/language are you working with?

Let me know,

Hello Dan, I am using .net nuget packages:
package id=“Auth0.AuthenticationApi” version=“7.0.2” targetFramework=“net462”
package id=“Auth0.Core” version=“7.0.2” targetFramework=“net462”
package id=“Auth0.ManagementApi” version=“7.0.2” targetFramework=“net462”

When the management api life time elapsed, if I want to access any api, it shows

ErrorApiException {“Expired token received for JSON Web Token validation”}.

So at this moment, what to do?

How often are you making these calls? The token is always returning this error?

Also, did you use a quickstart to set up your app? Or a tutorial? If not, could you post your code?

Its normal that it’ll show this error, it shows the error when the token lifetime expires. My concern is, if I made the token lifetime more longer, hence as token is not expiring, I don’t need to create management api client again, is management api client same instance can I use for a longer period? Fyi, management api client of the Auth0 library uses http client

You can initialize the management client in the application then store a token and pass that in if that makes sense.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.