Self hosted medplum docker container
# support
j
Hi, I'm trying to build an EMR app using HonoJs with medplum server on my backend and on a nextjs frontend. My HonoJs backend acts like a proxy between medplum and my nextjs frontend I'm currently running medplum locally using [docker-compose without the frontend](https://github.com/medplum/medplum/blob/main/docker-compose.full-stack.yml) trying to use medplum sdk to connect to the medplum server On the frontend I'm using auth0 for authentication and would like guidance on how to make an authenticated connection to medplum. I don't seem to find much on self hosting on docker. I tried medplum.startclientlogin but passing in admin_cliend_id but that didn't work as well. So some guide on using self hosted docker and the sdk would be helpful while still ensuring audit logging.
m
Hi @JT ! Interesting, do you have an example of the error that you get when using medplum.startclientlogin?
j
Hi @User, so this is what I tried
Copy code
import { MedplumClient } from "@medplum/core";

async function testMedplumConnection() {
  console.log('šŸš€ Testing Medplum FHIR Server Connection...\n');
  
  // First, let's check server health
  try {
    const response = await fetch('http://localhost:8103/healthcheck');
    const health = await response.json();
    console.log('āœ… Server health check:', health);
  } catch (healthError) {
    console.error('āŒ Server not reachable:', healthError.message);
    return;
  }

  // Test the FHIR base URL without authentication first
  console.log('\n--- Testing FHIR Server Access ---');
  
  try {
    const medplumClient = new MedplumClient({
      baseUrl: 'http://localhost:8103/'
    });

      await medplumClient.startClientLogin(
        '2a4b77f2-4d4e-43c6-9b01-330eb5ca772f', // from docker-compose.yml
        'top_secret' // added MEDPLUM_ADMIN_CLIENT_SECRET env
      );

      console.log(`Client credentials authentication ${medplumClient.isAuthenticated() ? 'successful' : 'failed'}  `);


    
  } catch (error) {
    console.error('āŒ Error connecting to FHIR server:', error.message);
    if (error.outcome) {
      console.error('Error details:', JSON.stringify(error.outcome, null, 2));
    }
  }
}

// Run the test
testMedplumConnection().catch(console.error);
I added a MEDPLUM_ADMIN_CLIENT_SECRET to test if it would work but it didnt. is there a way for me to connect to the fhir server without needing the medplum app UI?
f
Yea, you can connect to the FHIR server without needing the medplum app. Is your health check working here?
j
Yes my health check is working
f
Are you able to get the error messages returned by the server in this code segment:
Copy code
try {
    const medplumClient = new MedplumClient({
      baseUrl: 'http://localhost:8103/'
    });

      await medplumClient.startClientLogin(
        '2a4b77f2-4d4e-43c6-9b01-330eb5ca772f', // from docker-compose.yml
        'top_secret' // added MEDPLUM_ADMIN_CLIENT_SECRET env
      );
j
Hi @finnbergquist this is the output of that code
Copy code
npx tsx test-tmp.ts 
šŸš€ Testing Medplum FHIR Server Connection...

āœ… Server health check: {
  ok: true,
  version: '4.3.8-5d2307796',
  platform: 'linux',
  runtime: 'v20.19.4',
  postgres: true,
  redis: true
}

--- Testing FHIR Server Access ---
āŒ Error connecting to FHIR server: Failed to fetch tokens
Error details: {
  "resourceType": "OperationOutcome",
  "issue": [
    {
      "severity": "error",
      "code": "invalid",
      "details": {
        "text": "Failed to fetch tokens"
      }
    }
  ]
}
f
Could you see if this works with your client id and client secret:
Copy code
curl -X POST http://localhost:8103/oauth2/token \
    -H "Content-Type: application/x-www-form-urlencoded" \
    -d "grant_type=client_credentials&client_id=$MY_CLIENT_ID&client_secret=$MY_CLIENT_SECRET"
And can you confirm that the ClientApplication that you are using for the client id & client secret exists
j
So am I supposed to first set a client application? If so is a client application set? What I did was run [this](https://github.com/medplum/medplum/blob/main/docker-compose.full-stack.yml) without the medplum-app and add the medplum client secret env(which I'm not sure if that even should even exist). I saw somewhere on medplum docs that talked about the client application but it looks like that's if I was using the medplum-app? I didn't seem to find a doc with a setup running on your self hosted container
f
I would suggest running the Medplum app as well to help get things setup. It will help you get the server setup with your [Projects](https://www.medplum.com/docs/access/projects), and you can look at the ClientApplications that you will be able to use to authenticate. Think of Medplum app as a developer console to deal with admin tasks and setup for your Medplum server. And then, you connect to the Medplum server to use it as your backend for your app.
j
Okay thanks let me add the medplum-app and get back to you on that. for the medplum-app is there a default admin credentials to login?
f
yea, upon getting the medplum app running locally, you can access the app at http://localhost:3000/ & the default username is admin@example.com, default password medplum_admin.
131 Views