danaigc / DreamMachineAPI

Explore Dream Machine AI for the revolutionary AI video generator. Create unique, high-quality videos instantly from text and images. Free to use. Download and enjoy innovative video content now!
https://dreammachineai.io/
109 stars 20 forks source link

how to refresh access_token automatically? #8

Open sc0rp10n-py opened 1 month ago

sc0rp10n-py commented 1 month ago

Is it possible to refresh token automatically? so when access_token expires, it refreshes and the code still remains usable?

sc0rp10n-py commented 1 month ago

from my investigating, i have found out that this request is made from frontend with the old access and refresh token

curl 'https://internal-api.virginia.labs.lumalabs.ai/api/users/v1/me' \
  -H 'accept: application/json, text/plain, */*' \
  -H 'accept-language: en-US,en;q=0.9' \
  -H 'cookie: mp_5605fd5eb4a607ba5b575d93b8d63527_mixpanel=sampe%20mp_5605fd5eb4a607ba5b575d93b8d63527_mixpanel; access_token=sample.access.token; refresh_token=sample.refresh.token' \
  -H 'dnt: 1' \
  -H 'origin: https://lumalabs.ai' \
  -H 'priority: u=1, i' \
  -H 'referer: https://lumalabs.ai/' \
  -H 'sec-ch-ua: "Not/A)Brand";v="8", "Chromium";v="126", "Google Chrome";v="126"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "macOS"' \
  -H 'sec-fetch-dest: empty' \
  -H 'sec-fetch-mode: cors' \
  -H 'sec-fetch-site: same-site' \
  -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36'

and it returns the updated cookies in response cookies

I tried printing the cookies using requests in python but I keep getting empty cookies

maybe you can do something from it and get automatic updated tokens @danaigc

DramaChen commented 1 month ago

we meet the same problem. how to refresh access_token automatically?

OlegRuban-ai commented 1 month ago

I support, I'm worried about the problem - how to make sure that acces_token is not updated every approximately 60 minutes or automatically retrieve fresh values? It is updated very often, but is not in the general list of cookies, but must be taken from the application, which makes it difficult to solve the problem. The access_token from the browser_cookie3 package does not see the cookie in the list, and the solution via selenium is unstable. Maybe someone has more ideas?

OlegRuban-ai commented 1 month ago

Also note that Luma changed access_token to luma_session and you need to replace this in the code. But the session is still often thrown out, which is why re-authorization is required.

yrj109 commented 1 month ago

help me, brother~

yuanjie-ai commented 1 month ago

image