C
C#2w ago
Lounder

What are your thoughts on my application flow? Diagrams attached

Diagrams will be pasted below Example API endpoint: GET api/teams/4/warehouse/3/area/13
No description
31 Replies
Lounder
LounderOP2w ago
Conditional flow diagram ^
Lounder
LounderOP2w ago
Proposed solution 1
No description
Lounder
LounderOP2w ago
What I don't like about this is how many parameters are passed around Any suggestions on how I can mitigate this parameter passing, or is it good enough?
Lounder
LounderOP2w ago
Another thing I can do is use middleware/filters to achieve this validation. Example:
No description
WAASUL
WAASUL2w ago
It looks quite well done. How are you validating that a member is a TeamMember? @Lounder (Please @ on Reply) If it's done by accessing data from an access token. Make sure that it still applies. Since tokens are mostly static.
Lounder
LounderOP2w ago
I get the user ID from the token and make a DB query to check if the member is present in the team
WAASUL
WAASUL2w ago
I would be nice if you can avoid doing that everytime. Maybe by implementing some sort of caching mecanism.
Lounder
LounderOP2w ago
But then a user could be removed from the team and he would still have access
WAASUL
WAASUL2w ago
@Lounder (Please @ on Reply) You could blacklist there token. Every token has a issued at property. In theory, if a member is no longer part of an team. You can blacklist there id with a timestamp. During authorization, check if the user id is present in the cache. If so compare the issued at from the token against the timestamp from the cache. If the token was issued at after the timestamp mentioned in the cache. It means the token is newer.
Lounder
LounderOP2w ago
That's actually a really good idea Awesome, thanks or I could blacklist their JIT
WAASUL
WAASUL2w ago
Just make sure you are using a distributed cache. You cannot rely on an in memory cache.
Lounder
LounderOP2w ago
JTI*
WAASUL
WAASUL2w ago
@Lounder (Please @ on Reply) You don't want to do that. The token is very long. It will take unnessery space.
Lounder
LounderOP2w ago
so you're saying I shouldn't store a JTI at all?
WAASUL
WAASUL2w ago
what is an JTI?
Lounder
LounderOP2w ago
one sec json token identifier it is used for such situations - blacklisting or forcing the expiry of a token it is a random string
WAASUL
WAASUL2w ago
What if the user is authenticated in multiple devices?
Lounder
LounderOP2w ago
hm
WAASUL
WAASUL2w ago
All of a sudden you will need to store all jti. By storing the user id. You will save space and it will make everything easier.
Lounder
LounderOP2w ago
if userId is X and timestamp < Y, return unauthorized is that what you mean that should work
WAASUL
WAASUL2w ago
I just store it like this. {"blkusr:userid", "datetime in utc"} the first one is the key and the second one is the datetime in utc.
Lounder
LounderOP2w ago
Oh so you mean store {"blkusr:userid", "datetime in utc"} in a non-memory cache. Then have a middleware which checks if a token contains the given userId and timestamp is older than given datetime in utc
WAASUL
WAASUL2w ago
Exactly.
Lounder
LounderOP2w ago
that's awesome Thank you
WAASUL
WAASUL2w ago
No worries. Also just one last point. If the cache service is not available don't allow by passing. Just a last barrier.
Lounder
LounderOP2w ago
Technically, I could apply the same logic for all other checks right? Such as isTeamOwner, isTeamMember, teamExists when a team is deleted, I could blocklist all members' jwts
WAASUL
WAASUL2w ago
In theory, you could. But you will have to store information about the teams in the jwt. Instead of blacklisting all members id. You can blacklist the team id. That way you save space.
Lounder
LounderOP2w ago
Oh wow, yeah This will make it a bit complicated, but very performant I'm debating if I should do it now or later after I have MVP It would be a hassle to write, right?
WAASUL
WAASUL2w ago
it's really up to you. I would suggest doing some research on it first. If you do decide to go with that approach. Then implement it very early in the process.
Lounder
LounderOP2w ago
Thanks for the help! I really appreciate it opened my eyes a bit
WAASUL
WAASUL2w ago
No worries. Glad to help. Yeah I'm doing a similar thing. I took me weeks to create a solution.

Did you find this page helpful?