How to create app_id and app_secret when self-host...
# support
s
I am trying to self-host medplum on a Kubernetes cluster. I have it running on GKE but I don't see any instructions on how to create app_id and app_secret? Can you please provide some pointers? The same client code that I use to authenticate works with Medplum cloud so I know the code works.
I would appreciate some pointers here. Maybe it's documented somewhere but I went thru the documentation and couldn't find it.
r
I believe this is what you want https://www.medplum.com/docs/auth/methods/client-credentials however you'll have to go to your /ClientApplication
s
Thanks, Reshma! Let me share more context here. I deployed the Medplum docker container to a Kubernetes cluster and configured it to expose port 8103 and 5000. I configured the Medplum server to use
localhost:8103
as the baseUrl. The server starts and I can see that the API URL works as expected. I am trying to register a client so that I can get the client ID and client secret. The link you shared doesn't talk about self-hosted containers or how to register new clients. I tried accessing
http://localhost:8103/ClientApplication
but that doesn't lead anywhere. It just returns an error like
Cannot GET /ClientApplication
. I think this might be one of those that need to be configured using CLI but I don't see any documentation anywhere.
Nevermind, I ran the Medplum app and configured a client and secret. I can auth to the service using those credentials. Is there any recommendation on which project should be used for generating the credentials? I used the Super Admin project but I am not sure what are the implications.
r
Good question - don't use the Super Admin project for anything other than administration - create a new project for patient data etc.
r
Thanks @reshma . @s1r1usbl4ck. I'll just point you to a few more resources/docs: - A description of how Super Admin is special, and the kinds of privileges / powers it has (https://www.medplum.com/docs/access/projects#superadmin) - The project init operation (https://www.medplum.com/docs/api/fhir/operations/project-init#invoke-the-init-operation). This can be used to create Projects via the API, rather than the medplum app - We also have an endpoint for generating new ClientApplication resources via API. (https://www.medplum.com/docs/api/project-admin/client#post-adminprojectsprojectidclient). You can this to programmatically generate client credentials via api, if you prefer not to use the Medplum app
s
This is very helpful. Thank you! What $TOKEN should I use when making this query?
r
Hi @s1r1usbl4ck. , for creating projects programmatically, you should create a
ClientApplication
in the super admin project. This will give you a client id / client secret that has the ability to create projects
Then you can use the
client- credentials
auth flow to get a token
s
Right but how do I create the ClientApplication programmatically? Do I have to create it using the portal? Is there any way to configure the client-id and client-secret of the Super Admin in the config file so that we can use that to make queries the first time around? We have self-hosting setup working but it requires some manual steps to create a project, fetch client-id and secret, etc., My question is - how can I automate it thru code so that it automatically creates project and fetches client credentials as part of the deployment without any manual steps.
r
We have an endpoint for programatically creating ClientApplications (https://www.medplum.com/docs/api/project-admin/client). So your workflow could look something like this: - Start a new Medplum Cluster - Have a client sign into the "Super Admin" project using the default credentials (admin@example.com). https://www.medplum.com/docs/contributing/run-the-stack#start-the-servers - Using the create client application endpoint to create a new
ClientApplication
, Now you've created a new
ClientApplication
, with superAdmin privileges. After that, you can use the
ClientApplication
to create a new project by calling the
Project/$init
operation. This will create a new project, and populated with a a new
ClientApplication
that is scoped to the new project. This new ClientApplication can be used for creating data in teh new porject
312 Views