damp-notebook-13395
10/20/2023, 12:38 PMGET sessions/whoami call to Kratos to validate the token.
However, I am interested to know that is it possible that I can initiate an Ory Kratos client object in such a way, that I can do this validation without making a call to the Kratos server? May be, the sdk client can take secret, algorithm, and issuer during initialisation (which I can copy somewhere from the Ory console), and then can locally validate the incoming token's signature, issuer, expiry etc. etc. and can then extract the user's id and other stuff.
I can do this by writing my own code in Python, but just curious, if there is already an easier helper available in Kratos' sdk that does this.damp-notebook-13395
10/20/2023, 12:40 PMdamp-notebook-13395
10/20/2023, 12:42 PMdamp-notebook-13395
10/20/2023, 3:43 PMdamp-notebook-13395
10/21/2023, 4:29 AMdamp-notebook-13395
10/23/2023, 1:31 AM// rest of the code...
const [session, setSession] = useState<Session | undefined>()
useEffect(() => {
oryFrontend
.toSession({
"tokenizeAs": "my_template"
})
.then(async ({ data }) => {
// User has a session!
setSession(data)
})
.catch(() => {
return router.push(basePath + "/ui/login");
})
}, [router])
if (!session) {
// Still loading
return null
}
// rest of the code...
The above works fine. However what I want to know is that, is there a way to have access to this data object(or just the jwt part) on the next.js server side? I need the token on next.js server side to make authenticated call to my fast-api backend.
Of course, I can manually save the jwt inside cookies while logging in and then fetch the cookie on the server side, but I just wanted to know if there is a way where Ory Kratos itself takes care of putting this jwt in cookies while logging in and removing it from cookies while logging out, so that I have the access to the token throughout my application.
Thanks in advance.alert-advantage-94977
10/23/2023, 1:50 AMdamp-notebook-13395
10/23/2023, 1:55 AMdamp-notebook-13395
10/23/2023, 2:36 AMHTTP/1.1 303 See Other
Cache-Control: 0
Location: <http://127.0.0.1:4455/>
Set-Cookie: csrf_token=b8OebRPTPr5ow23mA5gIZmFNLeuMbv8pZz1jT1Ex7ys=; Path=/; Domain=127.0.0.1; Max-Age=31536000; HttpOnly
Set-Cookie: ory_kratos_session=MTU5OTE2ODc2N3xEdi1CQkFFQ180SUFBUkFCRUFBQVJfLUNBQUVHYzNSeWFXNW5EQThBRFhObGMzTnBiMjVmZEc5clpXNEdjM1J5YVc1bkRDSUFJR055VlROMGRteHhSakJrUzBkbmRUUjBlVFY1V0RCRWFVTnJXVmR6V25oaHx2DICsB6IMbaHSQwnYITUZqr7Qx7CxUlnaneJWH495wQ==; Path=/; Expires=Fri, 04 Sep 2020 21:32:47 GMT; Max-Age=86400; HttpOnly; SameSite=Lax
Vary: Cookie
Date: Thu, 03 Sep 2020 21:32:47 GMT
Content-Length: 0
How do I configure Ory Kratos so that it sets one more cookie for me in the above response, whose value is the jwt token that I am currently fetching by making an explicit call to /sessions/whoami?tokensie_as=mytemplate.
Once the jwt token is set in the cookie after login/registration, I won't have to make the recurring whoami calls everytime I need the jwt token.alert-advantage-94977
10/23/2023, 2:39 AMory_kratos_session as key and some random and long string as value
that cookie will respond with an authenticated identity when doing GET /sessions/whoami
but again, I'm not aware of any JWT issuancedamp-notebook-13395
10/23/2023, 2:42 AMdamp-notebook-13395
10/23/2023, 2:44 AMsessions/whoami everytime I need that jwt. Is there an easier way to configure Ory Kratos, so that it directly sets this jwt as a cookie after successful login/registration.alert-advantage-94977
10/23/2023, 2:45 AMdamp-notebook-13395
10/23/2023, 2:46 AMalert-advantage-94977
10/23/2023, 2:49 AMdamp-notebook-13395
10/23/2023, 2:53 AMCheck Who the Current HTTP Session Belongs To and see the query parameters. tokenize_as is listed there as a query param.damp-notebook-13395
10/23/2023, 2:58 AMmagnificent-energy-493
magnificent-energy-493
I have to make a explicit call to@damp-notebook-13395 It should not be too many calls if the JWT has sufficient TTL, right? I guess it depends on your usage patterns and how βstaleβ the session data can be.everytime I need that jwt.sessions/whoami
damp-notebook-13395
10/23/2023, 5:15 PMwhoami api call.
From how much I am able to figure out Ory Kratos doesn't set the jwt as a cookie automatically, and I would have to manually take care of setting it as a cookie post login/registration and also of unsetting it post logout. Correct me please if I am wrong.magnificent-energy-493
damp-notebook-13395
10/24/2023, 3:08 PMJust use the Ory Session cookie if you want to use cookies.I want to make http call to my fastapi backend and pass the jwt along. Without storing the jwt as cookie and without making a network call to
/whoami, how do I do that?alert-advantage-94977
10/24/2023, 3:13 PMdamp-notebook-13395
10/24/2023, 3:23 PM