I am trying to cache an access token obtained from an oauth2 flow. I would like to do this with the wix secrets api.
I try to use the update() function from the wixSecrectsBackend but I read that this function needs wix members activated. This function also only seems to work when i am logged in with an admin user on the live site.
If I am not logged in with an admin user, it gives me a 403 error.
Some side info, I am calling this function from the backend, the backend should be allowed to call such functions shouldn’t it?
Yes, that is fine, I have the members area enabled, however I can’t seem to make requests to the wixSecretsBackend unless the function call originates from a web session where a wix admin is logged in.
Should it not be great if the backend could make changes to the wixSecrets without having to be logged in with an admin account?
I even tried with the job scheduler (maybe this runs within admin context) , This also does not seem to be able to call the function without a permission error.
thanks for the help Yisrael!
I have written 2 functions, the first GetAccessToken() gets the previously cached access token from the secrets backend, checks if it is expired & tries to refresh it when needed. This function uses the storeAccessToken() function to store the refreshed token into the secretsbackend. ( this is where it goes wrong and I get a 403 code back from the wixSecretsBackend.update() function)
Even the error message that you posted states: Error refreshing access token
As far as I can tell, you never get to updateSecret().
Also, I don’t see where you set the teamleaderSecretId variable. I guess it’s a global variable that you set somewhere else in the code. Note that global variables might not behave as you expect in backend code. You should get the value of teamleaderSecretId right inside of the storeAccessToken() function to ensure it doesn’t get changed by another process.
I put the global variable inside my code now, and I am sorry, the error code i provided was wrong, I got that code because there was no valid access token in the secret to refresh.
This is the actual error I was talking about
“root”: {
Hello, I’ve got the same issue here. I get PERMISSION_DENIED: Permission denied, status: 403" every time I try to create or update a secret if the request doesn’t come from a loggedin admin session.
I’ve got an http function that tries to update a secret which fails with this error, while the same code called from a dashboard page works just fine.
I don’t really have an update yet, for now what I do is encrypt the access token with a key from wixsecrets and store it in a wix collection and decrypt it with the key when I want to use it…