hypebeast18
hypebeast186mo ago

Access / refresh tokens

Currently im writting frontend with zitadel. And i faced with problem that i dont know how works tokens (access and refresh). I need make frontend that i login/signup and after that get tokens, write it in the cookies and use access when i gotta make a request. And use refresh when i gotta revalidate access. But i dont know how to get these pair of tokens and how it works. Could you explain me how it work plz
46 Replies
Rajat Singh
Rajat Singh6mo ago
hi @hypebeast18 thanks for your question, what documentation have you already tried/followed. are you trying to get refresh token from what I understood?
hypebeast18
hypebeast18OP6mo ago
Yeah i get access and refresh tokens by using userManager.signinSilent() after i make request userManager.getUser() that contain access and refresh tokens
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
hypebeast18
hypebeast18OP6mo ago
@flo ok, how i can update my access token with refresh ?
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
hypebeast18
hypebeast18OP6mo ago
yes
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
hypebeast18
hypebeast18OP6mo ago
this post method with { grant_type=refresh_token, refresh_token: "", client_id: 123 } ?
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
hypebeast18
hypebeast18OP6mo ago
ok, thank you, i will try it now and give you info form-urlencoded... what is it
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
hypebeast18
hypebeast18OP6mo ago
{ "headers": { "Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json" }, "body": { "grant_type": "refresh_token", "refresh_token": "GnlbqrhMPugePrq7PRHBa7iaawEBwIPH4SFHLOfViVkTPEAdCHKliCeYF2Wu2B-bgu5XACHRatAR3oy3UJFmKGqiKBqmvve2YkJtsJWl", "client_id": "311593280154496056" } } const getAccess = async () => { console.log("userInfo", userInfo); const response = await axios.post("/zitadel/oauth/v2/token", { headers: { "Content-Type": "application/x-www-form-urlencoded", Accept: "application/json", }, body: { grant_type: "refresh_token", refresh_token: userInfo?.refresh_token, client_id: "311593280154496056", }, }); console.log("response", response); }; {"error":"invalid_request","error_description":"grant_type missing"} @flo I got 400 error I can share with you repo and you will see what i do wrong
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
hypebeast18
hypebeast18OP6mo ago
thanks, 5 min
hypebeast18
hypebeast18OP6mo ago
GitHub
GitHub - HypeBeasty18/zitadel-auth
Contribute to HypeBeasty18/zitadel-auth development by creating an account on GitHub.
hypebeast18
hypebeast18OP6mo ago
i need a zitadel for our company For short, i need an instrument that be able to make login/signup after that we get tokens(access/refresh) and use it. I use access with some requests, but after got 401 then I make revalidate access token by using refresh token. Access to make requests and refresh to revalidate access
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
hypebeast18
hypebeast18OP6mo ago
ok, i just wanted to explain you
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
hypebeast18
hypebeast18OP6mo ago
where /zitadel/oauth/v2/token i have proxy here , you can see it in the vite config
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
hypebeast18
hypebeast18OP6mo ago
i got it
No description
hypebeast18
hypebeast18OP6mo ago
Why ? I made how was in the instruction
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
hypebeast18
hypebeast18OP6mo ago
ok
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
hypebeast18
hypebeast18OP6mo ago
yeah it works Thank you man
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Rajat Singh
Rajat Singh6mo ago
hi @hypebeast18 if your query is resolved, please mark the answer by @chilom flo with ✅ and the issue will be autoclose
hypebeast18
hypebeast18OP6mo ago
@Rajat Singh @chilom When i reload my page, i got this error although my refrsh token i got 5 sec ago
No description
No description
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
hypebeast18
hypebeast18OP6mo ago
ok no problem
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
hypebeast18
hypebeast18OP6mo ago
you login and after that reload page and your refresh token is ok ? You dont get this error
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
hypebeast18
hypebeast18OP6mo ago
Could you send me your repo plz. I still have problems
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
hypebeast18
hypebeast18OP6mo ago
thanks . i will see it a little bit later @flo ok the problem with reload page was fix but i have another one problem with invalidate my refresh token. I get { "code": 16, "message": "Errors.Token.Invalid (AUTH-7fs1e)", "details": [ { "@type": "type.googleapis.com/zitadel.v1.ErrorDetail", "id": "AUTH-7fs1e", "message": "Errors.Token.Invalid" } ] }
hypebeast18
hypebeast18OP6mo ago
Even in the postman i have this problem, may be do I something wrong
No description
hypebeast18
hypebeast18OP6mo ago
also any request to zitadel with valid access token
No description
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
hypebeast18
hypebeast18OP6mo ago
Configutation of my app
No description
hypebeast18
hypebeast18OP6mo ago
Configuration of my project
No description
No description
No description
No description
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
hypebeast18
hypebeast18OP6mo ago
@chilom yeah
No description
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?