I'm using lazy-loaded modules in my angular application and until now everything works fine.
Now I have a specific question about securing and I did not find an answer yet. You have the opportunity to "secure" lazy loaded modules with an Angular Guard and "CanLoad". But this is only in the frontend and so it could be bypassed and the module would be loaded even if the user is not allowed to see ist. Eg Admin-Area.
I'm using JWTs for authorization and the data is all hosted on an Azure Backend completely separated from the application server that hosts the Angular App.
I'm now thinking about if there is any way to use the JWTs to validate and check if the current module is allowed to be loaded by that user server side.
so for example you have the following modules:
- FeatureA
- FeatureB
- FeatureC
- Admin
In the JWT for every Feature module/area there is a variable in the payload which says if the user is allowed to use this feature (true/false).
Now if the user would try to load the lazy-loaded module for feature A, I would like to validate the JWT on the application server with the public key to know "this key is valid and was signed exactly like that by the azure server".
Next it would check if the variable for FeatureA is set to true. If so, I return the module (the js-chunk file) back to the client. If not, I would return 403 forbidden.
so if even the application was modified, the person only gets the feature module if it has an valid JWT which says this feature is activated for that user.
Is there any way to do this? I don't know where I should start looking for a solution. So if anyone could tell me how I can get that and what I need for it, I would be really grateful!
thanks in advance,
Sazeidya.