Skip to content

Commit 846388f

Browse files
committed
Incorporated OIDC for authenticating towards Azure in GH Action
1 parent 3e7803e commit 846388f

File tree

1 file changed

+4
-22
lines changed

1 file changed

+4
-22
lines changed

hvalfangst_function/function_app.py

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import json
21
import logging
3-
import os
4-
from io import StringIO
5-
6-
import azure.functions as func
7-
import jwt
2+
import json
83
import pandas as pd
4+
import azure.functions as func
5+
from io import StringIO
96
from sklearn.preprocessing import LabelEncoder
107

118
# Decree and declare our project as an Azure Function App subsidiary
@@ -63,25 +60,10 @@ def blob_trigger(inbound: func.InputStream, outbound: func.Out[str]):
6360
return f"Error: {str(e)}"
6461

6562

66-
def validate_jwt(token: str, audience: str) -> bool:
67-
try:
68-
decoded = jwt.decode(token, audience=audience, options={"verify_signature": False})
69-
# Optionally check claims like roles or scopes
70-
return True
71-
except Exception as e:
72-
logging.error(f"JWT validation failed: {e}")
73-
return False
74-
75-
7663
@app.route(route="upload_csv", auth_level=func.AuthLevel.ANONYMOUS)
77-
@app.blob_output(arg_name="outbound", path="hvalfangstcontainer/in/input.csv", connection="AzureWebJobsStorage")
64+
@app.blob_output(arg_name="outbound", path="hvalfangstcontainer/in/input.csv", connection="") # AzureWebJobsStorage
7865
def upload_csv(req: func.HttpRequest, outbound: func.Out[str]) -> str:
7966
try:
80-
81-
token = req.headers.get("Authorization").split(" ")[1] # Extract Bearer token
82-
if not validate_jwt(token, audience=os.environ.get("FUNCTION_APP_CLIENT_ID")):
83-
return func.HttpResponse("Unauthorized", status_code=401)
84-
8567
logging.info("Received HTTP request to upload CSV")
8668

8769
# Parse raw bytes derived from request body to string

0 commit comments

Comments
 (0)