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
hi @hypebeast18 thanks for your question, what documentation have you already tried/followed.
are you trying to get refresh token from what I understood?
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•6mo ago
Message Not Public
Sign In & Join Server To View
@flo ok, how i can update my access token with refresh ?
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
yes
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
this post method with { grant_type=refresh_token, refresh_token: "", client_id: 123 } ?
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
ok, thank you, i will try it now and give you info
form-urlencoded... what is it
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
{
"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•6mo ago
Message Not Public
Sign In & Join Server To View
thanks, 5 min
GitHub
GitHub - HypeBeasty18/zitadel-auth
Contribute to HypeBeasty18/zitadel-auth development by creating an account on GitHub.
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•6mo ago
Message Not Public
Sign In & Join Server To View
ok, i just wanted to explain you
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
where
/zitadel/oauth/v2/token i have proxy here , you can see it in the vite config
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
i got it

Why ? I made how was in the instruction
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
ok
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
yeah it works
Thank you man
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
hi @hypebeast18 if your query is resolved, please mark the answer by @chilom flo with ✅ and the issue will be autoclose
@Rajat Singh @chilom When i reload my page, i got this error although my refrsh token i got 5 sec ago


Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
ok no problem
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
you login and after that reload page and your refresh token is ok ? You dont get this error
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
Could you send me your repo plz. I still have problems
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
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"
}
]
}
Even in the postman i have this problem, may be do I something wrong

also any request to zitadel with valid access token

Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
Configutation of my app

Configuration of my project




Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
@chilom yeah

Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View