File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed
code/function/fastapp/health Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change 1+ from typing import Annotated
2+ from fastapi import Header , HTTPException
3+ from hashlib import sha256
4+ import base64
5+ from fastapp .core .config import settings
6+
7+ async def verify_health_auth_header (x_ms_auth_internal_token : Annotated [str , Header ()]) -> bool :
8+ """Returns true if SHA256 of header_value matches WEBSITE_AUTH_ENCRYPTION_KEY.
9+
10+ x_ms_auth_internal_token: Value of the x-ms-auth-internal-token header.
11+ RETURNS (bool): Specifies whether the header matches.
12+ """
13+ website_auth_encryption_key = settings .WEBSITE_AUTH_ENCRYPTION_KEY
14+ hash = base64 .b64encode (sha256 (website_auth_encryption_key .encode ('utf-8' )).digest ()).decode ('utf-8' )
15+ if hash != x_ms_auth_internal_token :
16+ raise HTTPException (status_code = 400 , detail = "x-ms-auth-internal-token is invalid" )
17+ else :
18+ return True
You can’t perform that action at this time.
0 commit comments