1

我已使用此链接为 FHIR 部署和配置 Azure API - https://docs.microsoft.com/en-gb/azure/healthcare-apis/tutorial-web-app-fhir-server

使用邮递员,我能够成功地将患者信息插入 fhir-server。

为了自动化它,我使用 python 和客户端服务流。

   def get_access_token(self):

        token_url = 'https://login.microsoftonline.com/{}/oauth2/v2.0/token'.format(azure_app_tenant_id)

        token_data = {
        'grant_type': 'client_credentials',
        'client_id': azure_app_client_id,
        'client_secret': azure_app_client_secret,
        'scope': fhir_endpoint_url + "/.default",

        }

        token_r = requests.post(token_url, data=token_data)

        log.info("Retrieving Access Token")
        if token_r.status_code == 200:
            log.info("Access Token Retrieved Successfully")
        else:
            raise Exception("Error retrieving access token")

        print(token_r.json()["access_token"])
        return token_r.json()["access_token"]

我可以使用 get_access_token 获取访问令牌。但是,当我使用 access_token 并插入患者记录时,它会抛出 Authorization Failed - 403 错误。

    def insert_patient_record(self, payload):
        log.info("Inserting Patient Record")
        headers = {
            'Authorization': 'Bearer {}'.format(self.get_access_token()),
            'Content-Type': 'application/json'
        }

        response = requests.request("POST", fhir_endpoint_url, headers=headers, data=payload)
        print("Response Code: ", response.status_code)
        if response.status_code == 200:
            log.info("Patient Record inserted Successfully")
        else:
            print("Response Text: ", response.text)
            raise Exception("Error inserting patient record")

Response Text:  {"resourceType":"OperationOutcome","id":"24515888da8e954da1e763d96193155b","issue":[{"severity":"error","code":"forbidden","diagnostics":"Authorization failed."}]}

注意:在 FHIR-Server Authentication 部分,我添加了我之前在 ADD 中创建的已注册 APP 的对象 ID。

4

1 回答 1

1

看起来您尚未添加已注册应用程序的(正确)对象 ID。重要的是,应用程序注册有一个对象 id,但服务主体也有。它是您要查找的服务主体的应用程序 ID。

在此处查看说明:

https://docs.microsoft.com/en-us/azure/healthcare-apis/find-identity-object-ids

您可以使用 PowerShell 找到它的服务主体对象 ID:

$(Get-AzureADServicePrincipal -Filter "AppId eq 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'").ObjectId

或 Azure CLI:

az ad sp show --id XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX | jq -r .objectId

我还建议将您的令牌粘贴到https://jwt.ms之类的内容中,然后查看oid声明。那是您添加的对象ID吗?

于 2020-04-20T16:56:14.140 回答