Feature request: have possibility to process the token claims at the end of MSALScheme.__call__
In the readme, you protect a route via Depends in the arguments list of the path operation function:
@app.get("/users/me", response_model=UserInfo, response_model_exclude_none=True, response_model_by_alias=False)
async def read_users_me(current_user: UserInfo = Depends(msal_auth.scheme)) -> UserInfo:
return current_user
Alternatively, you can protect multiple routes by adding the same Depends as a dependency in an APIRouter. As far as I know, you are then not able to capture the return value in a variable. And hence you do not have user info available in the bodies of the path operation functions of the protected routes.
A solution for this would be to optionally process the IDTokenClaims in MSALScheme.__call__ by a function def claims_processor(request: Request, token_claims: IDTokenClaims) -> None just before returning the token_claims. The typical thing to do in such a function is to add user info to request.state, so that path operation functions can retrieve it when desired. I expect that this is a commonly requested feature. E.g., the package fastapi_azure_auth does something alike, see https://github.com/intility/fastapi-azure-auth/blob/main/fastapi_azure_auth/auth.py
The function claims_processor can be passed as an optional argument to the initializer of MSALAuthorization, which will pass it subsequently to the initializer of MSALScheme.
Do you agree that this would be useful? Would you consider including this if I submit a PR (#54 )?