I am using python to insert FHIR jsons into Azure API for FHIR. I have deployed Azure api for fhir service and also did a app registration.
My app is not a web application. It just reads the input json and publishes it to FHIR server. And hence, i created Public/Mobile&Desktop applications.
With postman i am able to successfully post a message. However, i would like to do that with my python script. I am struck at fetching Access Token via OAuth2.
I tried the following code and its throwing empty tenant id . When i googled about OAuth2, There are multiple packages like rauth, ADAL, msal. None of them worked for me.
import requests
app_id = <client_id>
token_url = https://login.microsoftonline.com/<tenant_id>/oauth2/token
token_data = {
'resource': 'APP_ID_URL',
'grant_type': 'password',
'client_id': app_id,
'client_secret': client_secret,
'scope':'',
'username':'USERNAME',
'password':'PASSWORD',
}
I am getting 200 response, but it returns an html saying problem signing in the user. Is there a simple way of getting OAuth2 token via python script. I checked other SO posts related to this. Most of the answers are not working for me.