smart-on-fhir / client-py

Python SMART on FHIR client
http://docs.smarthealthit.org
Other
596 stars 213 forks source link

API/Oauth authentication example #88

Open atulkakrana opened 4 years ago

atulkakrana commented 4 years ago

Hi, It will help a lot if you can add some examples for FHIR client (client-py) on how we can authenticate sessions/calls from Python? For example - how can we use authenticate to access FHIR API: https://synthea.mitre.org/fhir-api ??

EricPHassey commented 3 years ago

@atulkakrana have you got any help on authenticate this? Also looking for the same.

alihbuzaid commented 2 years ago

we need this badly I was about to write an issue, also against azure services

thanks

maxschloegel commented 2 years ago

I was also struggling to figure out, how to use user-password authentication with the fhirclient (specifically BasicAuth) until I came across the following stackoverflow answer. According to this, it is also possible to pass username and password to the url like this:

http://user:passwd@www.server.com/index.html

I then changed my settings-dictionary for the client initialization from:

settings = {
    "app_id": "some_app_id",
    "api_base": "https://my_fhir_server.com"}
smart = fhirclient.client.FHIRClient(settings=settings)

to

user = "username"
pw = "password"
settings = {
    "app_id": "some_app_id",
    "api_base": f"https://{user}:{pw}@my_fhir_server.com"}
smart = fhirclient.client.FHIRClient(settings=settings)

and it works as expected.

While this is a good enough workaround for my case, I only checked this for BasicAuth. And this might not be the most secure solution, but I am no expert on this.

In any case, it would be great to officially address different authentication methods like mentioned in #91 .

os-netizen commented 1 year ago

@atulkakrana Do you have any update on this? Would love some help as I am facing the same issues