helder.rossa
06/02/2023, 2:22 PMrp_st
06/02/2023, 2:38 PMhelder.rossa
06/02/2023, 5:14 PMjson
{
"message": "unauthorised"
}
rp_st
06/02/2023, 6:20 PMrp_st
06/02/2023, 6:21 PMhelder.rossa
06/02/2023, 7:07 PMsh
http :3567/recipe/jwt rid:jwt \
payload:='{"uuid":"someid"}' \
useStaticSigningKey:='true' \
algorithm=RS256 \
jwksDomain=http://localhost:3333 \
validity=31556926000
I was hable to successfuly decode the JWT token and get the payload:
sh
http -pb -j :3333/ Authorization:"Bearer $ACCESS_TOKEN"
{
"jwt": {
"exp": 33242658621,
"iat": 1685732621,
"iss": "http://localhost:3333",
"uuid": "someid"
}
}
thanks!helder.rossa
06/02/2023, 8:08 PMrp_st
06/03/2023, 4:35 AMrp_st
06/03/2023, 4:36 AMhelder.rossa
06/04/2023, 11:31 AMrp_st
06/04/2023, 11:34 AMrp_st
06/04/2023, 11:34 AMrp_st
06/04/2023, 11:34 AMrp_st
06/04/2023, 11:35 AMhelder.rossa
06/04/2023, 11:37 AMhelder.rossa
06/04/2023, 11:40 AMcreateNewSessionWithoutRequestResponse
methodrp_st
06/04/2023, 11:43 AMhelder.rossa
06/04/2023, 11:51 AMrp_st
06/04/2023, 12:56 PMhelder.rossa
06/04/2023, 4:04 PMrp_st
06/04/2023, 4:11 PMrp_st
06/04/2023, 4:11 PMhelder.rossa
06/04/2023, 4:27 PMrp_st
06/04/2023, 4:28 PMrp_st
06/04/2023, 4:30 PMhelder.rossa
06/04/2023, 4:30 PMhelder.rossa
06/04/2023, 4:31 PM"sub": "... user id..."
in the payload of the JWThelder.rossa
06/04/2023, 4:32 PMrp_st
06/04/2023, 4:32 PMrp_st
06/04/2023, 4:32 PMhelder.rossa
06/04/2023, 4:33 PMrp_st
06/04/2023, 4:33 PMrp_st
06/04/2023, 4:33 PMhelder.rossa
06/04/2023, 4:36 PMrp_st
06/04/2023, 4:36 PMrp_st
06/04/2023, 4:36 PMhelder.rossa
06/04/2023, 4:36 PMrp_st
06/04/2023, 4:37 PMrp_st
06/04/2023, 4:37 PMrp_st
06/04/2023, 4:37 PMhelder.rossa
06/04/2023, 4:37 PMrp_st
06/04/2023, 4:37 PMrp_st
06/04/2023, 4:38 PMhelder.rossa
06/04/2023, 4:40 PMrp_st
06/04/2023, 4:40 PMrp_st
06/04/2023, 4:40 PMrp_st
06/04/2023, 4:40 PMrp_st
06/04/2023, 4:41 PMrp_st
06/04/2023, 4:41 PMrp_st
06/04/2023, 4:41 PMhelder.rossa
06/04/2023, 4:56 PMcreateNewSessionWithoutRequestResponse
method. Because that would clearly resolve this issue. In my current tool I just create an access token to an user with -1 (infinite) TTL and that' it. So, it's not possible, but I think it should.
But even the JWT solution, we have to bare that roles (or any other user information) are dynamic, and so, that information should not be in JWT. But the user ID it could be the only information needed here. And then I could retrieve the user and roles from SuperTokens after. That's what I wanted help on. I don't mind to do custom code in my app to get this information and then I could use roles.includes("admin")
like stated in the docs.
I'm sure, that more people will ask for this feature (I've read other threads in Discord) and I think it's not clarified in the docs how to do user API keys. Even if you think that's all in the docs.
With that said, thanks!rp_st
06/04/2023, 4:57 PMrp_st
06/04/2023, 4:58 PMrp_st
06/04/2023, 4:58 PMrp_st
06/04/2023, 4:59 PMhelder.rossa
06/04/2023, 5:02 PMrp_st
06/04/2023, 5:03 PMhelder.rossa
06/04/2023, 6:24 PMjavascript
const userId = 'b5148681-ef9b-44b1-adf0-36e933300af3'; // get from db
const session = await Session.createNewSessionWithoutRequestResponse(userId);
const tokens = session.getAllSessionTokensDangerously();
if (tokens.accessAndFrontTokenUpdated) {
const payload = await session.getAccessTokenPayload();
delete payload.exp;
delete payload.iat;
const jwt = await createJWT(payload, 31556926000);
return res.send({ jwt: jwt });
}
the payload has plenty of information:
json
{
"sub": "b5148681-ef9b-44b1-adf0-36e933300af3",
"exp": 1685906515,
"iat": 1685902915,
"sessionHandle": "04d312e2-c0cd-4744-829a-30b821c50165",
"refreshTokenHash1": "19b507658cda61bfd80013c6f2ba3c68d410e530284f647316b817ee4b28a9f4",
"parentRefreshTokenHash1": null,
"antiCsrfToken": null,
"iss": "http://localhost:3333/api/auth"
}
won't the session store the expiration time in database also?rp_st
06/04/2023, 6:53 PMhelder.rossa
06/04/2023, 9:34 PMjavascript
await server.get(
'/',
{
preHandler: verifySession(),
},
async (req: SessionRequest, res) => {
let session = req.session;
res.send({ session });
}
);
sh
http -pHb -j :3333/ Authorization:"Bearer $ACCESS_TOKEN"
GET / HTTP/1.1
Accept: application/json, */*;q=0.5
Accept-Encoding: gzip, deflate
Authorization: Bearer eyJraWQiOiJzLTgx...uh4Mc3AxqpXUA
Connection: keep-alive
Content-Type: application/json
Host: localhost:3333
User-Agent: HTTPie/3.2.2
{
"message": "unauthorised"
}
helder.rossa
06/04/2023, 10:01 PMhelder.rossa
06/04/2023, 10:03 PMrp_st
06/05/2023, 5:52 AMrp_st
06/05/2023, 5:53 AMhelder.rossa
06/12/2023, 8:50 AMrp_st
06/12/2023, 9:35 AMhelder.rossa
06/16/2023, 3:58 PMrp_st
06/16/2023, 5:50 PMrp_st
06/16/2023, 5:50 PMrp_st
06/16/2023, 5:50 PMhelder.rossa
06/23/2023, 2:51 PMrp_st
06/23/2023, 6:29 PMrp_st
06/23/2023, 6:29 PMrp_st
06/23/2023, 6:29 PMhelder.rossa
06/23/2023, 7:41 PMjson
{
"error": "Unauthorized",
"message": "The access token doesn't match the useDynamicAccessTokenSigningKey setting",
"statusCode": 401
}
rp_st
06/23/2023, 7:45 PMhelder.rossa
06/23/2023, 7:48 PMjavascript
await createJWT(payload, undefined, true)
or
javascript
Session.init({ useDynamicAccessTokenSigningKey: false, })
accepted the ACCESS_TOKEN but.... no req.session
!!!rp_st
06/23/2023, 7:49 PMrp_st
06/23/2023, 7:49 PMrp_st
06/23/2023, 7:50 PMhelder.rossa
06/23/2023, 7:50 PMSession.getSession(...)
rp_st
06/23/2023, 7:51 PMhelder.rossa
06/23/2023, 7:53 PMaddAuthorizationHooks()
that then uses Session.getSession(...)
but I'm not getting a sessionrp_st
06/23/2023, 7:54 PMrp_st
06/23/2023, 7:54 PMhelder.rossa
06/23/2023, 7:57 PMjavascript
const session = await Session.getSession(req, reply);
if (!session) {
throw new Error();
}
rp_st
06/23/2023, 7:57 PMhelder.rossa
06/23/2023, 8:00 PMThe access token doesn't match the useDynamicAccessTokenSigningKey setting
should this be true or false? 🙂
javascript
... await createJWT(payload, undefined, true)
rp_st
06/23/2023, 8:00 PMrp_st
06/23/2023, 8:00 PMrp_st
06/23/2023, 8:00 PMhelder.rossa
06/23/2023, 8:03 PMThe access token doesn't match the useDynamicAccessTokenSigningKey setting
rp_st
06/23/2023, 8:03 PMhelder.rossa
06/23/2023, 8:04 PMrp_st
06/23/2023, 8:05 PMhelder.rossa
06/23/2023, 8:06 PMhelder.rossa
06/23/2023, 8:06 PMrp_st
06/23/2023, 8:07 PMrp_st
06/23/2023, 8:07 PMhelder.rossa
06/23/2023, 8:08 PMhelder.rossa
06/23/2023, 8:08 PMrp_st
06/23/2023, 8:08 PMhelder.rossa
06/23/2023, 8:09 PMhelder.rossa
06/23/2023, 8:09 PMhelder.rossa
06/23/2023, 8:11 PMrp_st
06/23/2023, 8:11 PMrp_st
06/23/2023, 8:11 PMhelder.rossa
06/23/2023, 8:11 PMhelder.rossa
06/23/2023, 10:07 PMjson
{
// custom info in session database
// when JWT was created
"data": {
"apikey": true
},
"email": "user@example.com",
"id": "b08937a7-fb50-4e45-a30d-b70be20135c5",
// UserRoles associated with the user
"roles": [
"admin"
]
}
I guess I'm in the right way. Thanks !!!robschilder
09/07/2023, 8:03 AMqwerzl
10/03/2023, 2:01 PMrp_st
10/03/2023, 2:02 PMqwerzl
10/03/2023, 2:03 PMqwerzl
10/03/2023, 2:03 PM/auth/dashboard
rp_st
10/03/2023, 2:18 PMqwerzl
10/03/2023, 2:25 PM