首页 > 解决方案 > 如何验证 OAUTH2 以在 Python 中使用 API?

问题描述

我正在尝试连接 FHIR 服务器以使用 API 并提取信息。

到目前为止,我可以连接,但它需要我使用浏览器进行身份验证并输入我的用户和密码。我正在寻找一种自动化的方法,这样我就可以在不登录浏览器的情况下进行身份验证。

目前我正在使用https://github.com/smart-on-fhir/client-py来执行此操作,但我对其他解决方案持开放态度。我当前执行此操作的代码如下:

from fhirclient import client

def connect_to_fhir():
    settings = {
            'app_id': 'MyApp',
            'api_base': 'https://endpointurl.com/api/',
            'redirect_uri': 'https://localhost:8000/fhir-app/',
            'patient_id': 'test',
        }
    smart = client.FHIRClient(settings=settings)

    print(smart.authorize_url)

    smart.handle_callback(input('Authorize and paste callback url here: '))
    return smart

标签: pythonapioauth-2.0hl7-fhir

解决方案


推荐阅读