Hello @Andrew Kelly
One way to achieve this is by passing the OAuth2 token obtained from the initial login to the Azure Function in the request headers. To do this, you can modify your application to include the OAuth2 token in the request headers when calling the Azure Function. In your Azure Function code (Python), you can then extract the token from the request headers and use it to authenticate the user. Here's an example of how you can extract the OAuth2 token from the request headers in Python:
import os
import jwt
def main(req):
token = req.headers.get('Authorization').split(' ')[1]
decoded_token = jwt.decode(token, os.environ['JWT_SECRET'], algorithms=['HS256'])
user_id = decoded_token['sub']
# Use the user_id to authenticate the user and perform the necessary actions
In this example, we are assuming that the OAuth2 token is passed in the Authorization
header using the Bearer scheme. We extract the token from the header and decode it using the JWT library. We then extract the sub
claim from the decoded token, which contains the user ID. You can use this user ID to authenticate the user and perform the necessary actions. Note that you will need to set the JWT_SECRET
environment variable in your Azure Function app settings to the same value that was used to sign the OAuth2 token in your application.
I hope that this response has addressed your query and helped you overcome your challenges. If so, please mark this response as Answered. This will not only acknowledge our efforts, but also assist other community members who may be looking for similar solutions.