
LibreChat SSO with AWS IAM Identity Center via SAML 2.0
A hands-on walkthrough of LibreChat SAML 2.0 SSO with AWS IAM Identity Center, covering real configuration issues and how to resolve them.
Introduction
In the blog post Deploying LibreChat on Amazon ECS using Terraform , I introduced LibreChat, an open-source, self-hosted chat interface that lets you use multiple AI providers from one ChatGPT-style UI. In a team-based setting, LibreChat provides security and governance controls such as role-based access, spend controls, and single sign-on (SSO), which is the focus of this post.
Setting up LibreChat with SSO helps you streamline access by leveraging a centralized identity provider with MFA, group-based access, and audit logs already configured. Since I already have AWS IAM Identity Center configured in my AWS lab environment, it only makes sense to connect the two over SAML 2.0 so that I can avoid managing more app-specific credentials. As I got to work, I soon discovered that the SSO configuration is not well documented and that problems are hard to troubleshoot. What I expected to be a 30-minute job took me half a day, most of it spent staring at generic "Bad input" or "No access" errors with little hint of what was wrong.
So I figured I would share my experience with the community. In this post, I’ll walk you through the setup that worked for me, step by step, and point out the gaps in the documentation as we go. Let’s first review the solution and its architecture.
Architecture Overview
AWS IAM Identity Center is AWS's centralized identity service for managing access to multiple AWS accounts and applications. It provides single sign-on, so a user logs in once and reaches every authorized resource without re-authenticating. That holds whether you use the built-in identity store or federate with another identity provider such as Microsoft Entra ID.
In this architecture, IAM Identity Center is the SAML 2.0 identity provider (IdP) and LibreChat is the service provider (SP). SAML 2.0 is an XML-based standard for exchanging authentication data between the two: the user authenticates once with the IdP, and any SP configured to trust its assertions lets them in.
IAM Identity Center is free, but you need an organization instance . Account instances don't support customer managed SAML 2.0 applications.
The following diagram shows how LibreChat uses IAM Identity Center for authentication, and the two ways a user can reach LibreChat: starting at LibreChat itself (SP-initiated), or starting from the AWS Access Portal (IdP-initiated).

Prerequisites
This post assumes you are familiar with basic IAM Identity Center administration, such as managing users and groups, and are comfortable editing LibreChat’s
.env file. No deep SAML experience is needed.To follow along, you need two things:
- An organization instance of IAM Identity Center. If you don't have one, follow Enable IAM Identity Center in the AWS IAM Identity Center User Guide.
- A running LibreChat instance. Any of these options works:
- Amazon ECS, for a more scalable setup. Follow my previous blog post Deploying LibreChat on Amazon ECS using Terraform .
- A single EC2 instance, for a minimal, lower-cost setup. I run LibreChat on a t4g.medium Amazon Linux 2023 instance. Install Docker Compose manually , then install LibreChat with Docker .
- Your laptop or workstation, if you only want to experiment with the SSO setup. Install LibreChat locally with Docker .
With both in place, it's time to integrate the two.
Setting Up the SAML 2.0 Application in IAM Identity Center
The first step is to create a SAML 2.0 application for LibreChat in IAM Identity Center. Log in to the AWS account where IAM Identity Center is administered and open the IAM Identity Center console.
Creating a Group
As a best practice, let’s assign access through a group rather than to individual users. Granting or revoking access later is then a group membership change, with nothing to touch on the application. Create the group as follows:
- In the left menu, select Groups.
- In the Groups page, click Create group.
- In the Create group page, enter
LibreChatas the group name. Search and add the appropriate users, then click Create group.
Creating the SAML 2.0 Application
- In the left menu, select Application assignments > Applications.
- In the Applications page, click Add application.
- In the Select application type page, select I have an application I want to set up. Then select SAML 2.0 and click Next.
- In the Configure application page, enter the following information and click Submit.
- Display name - Set it to
LibreChator your own preferred name that shows up in the application tile in the AWS Access Portal.
- Description - Set it to
LibreChator your own preferred description.
- IAM Identity Center sign-in URL - Copy this URL and store it locally for use when you configure LibreChat in subsequent steps.
- IAM Identity Center Certificate - Download the certificate and store it locally for use when you configure LibreChat in subsequent steps.
- Application ACS URL - Set it to the LibreChat endpoint that receives the SAML response, which is
<librechat-base-url>/oauth/saml/callback, for examplehttps://chat.yourdomain.com/oauth/saml/callback. It must match theSAML_CALLBACK_URLenvironment variable that you'll set in LibreChat later.
- Application SAML audience - Set it to a unique URI that identifies LibreChat. I use the LibreChat URL, but a URN such as
urn:librechat:examplealso works. It must match theSAML_ISSUERenvironment variable that you'll set in LibreChat later.
- In the LibreChat application page, click Assign users and groups.
- Search for the name of the group created earlier and click on it. Then click Assign. Any user in this group will now have access to LibreChat via SAML 2.0 authentication.
Mapping the Attributes
Lastly, you map IAM Identity Center user attributes to the attributes that LibreChat reads from the SAML assertion. To do that, you need to know the attribute names on both sides.
The IAM Identity Center side is the tricky one. The attribute mappings page in the IAM Identity Center User Guide lists the supported attributes, but the list you need is the last one, under the misleading title "Supported IAM Identity Center attributes for Microsoft AD". I skipped over that list more than once, because nothing in my setup involves Microsoft AD!
For LibreChat, the best source is the SAML section in the LibreChat documentation. The default values of the
SAML_*_CLAIM environment variables give you the attribute names. The exception is SAML_NAME_CLAIM , which has no default. Since IAM Identity Center should supply all the required data, you will set it to name and map it to ${user:preferredUsername} in the IdP. To save you some time, here are the correct attribute mappings:User attribute in the application (i.e. LibreChat) | Maps to this string value or user attribute | Format |
|---|---|---|
Subject | ${user:email} | emailAddress |
name | ${user:preferredUsername} | unspecified |
given_name | ${user:givenName} | unspecified |
family_name | ${user:familyName} | unspecified |
username | ${user:subject} | unspecified |
email | ${user:email} | unspecified |
For context, LibreChat uses
Subject to recognize a returning user, so it must be a stable, unique value, and the email address serves that purpose. ${user:subject} is the user’s IAM Identity Center username, which is why it maps to username .
Back in the LibreChat application page, click Actions and select Enter attribute mappings. Then enter the mapping as per the table above and click Save changes.
This completes the IAM Identity Center side. Let's move on to the LibreChat setup.
Configuring LibreChat as the SAML Service Provider
On the LibreChat side, you configure LibreChat by updating
.env (or environment variables) to do two things:- Disallow user registration and allow only SAML login (via IAM Identity Center).
- Configure LibreChat as the service provider (SP) using the SAML 2.0 application configuration created earlier in IAM Identity Center.
Restricting Login to SAML
Open
.env with a text editor and look for the Registration and Login section , which looks like this by default:#========================## Registration and Login ##========================#
ALLOW_EMAIL_LOGIN=trueALLOW_REGISTRATION=trueALLOW_SOCIAL_LOGIN=falseALLOW_SOCIAL_REGISTRATION=falseALLOW_PASSWORD_RESET=false# ALLOW_ACCOUNT_DELETION=true # note: enabled by default if omitted/commented outALLOW_UNVERIFIED_EMAIL_LOGIN=trueThe visual in the documentation shows the sections of the login page and their associated environment variables:

One thing the documentation doesn't spell out: LibreChat treats SAML as a social login. So you need to set
ALLOW_EMAIL_LOGIN and ALLOW_REGISTRATION to false , and ALLOW_SOCIAL_LOGIN to true :ALLOW_EMAIL_LOGIN=falseALLOW_REGISTRATION=falseALLOW_SOCIAL_LOGIN=trueNote that
ALLOW_SOCIAL_REGISTRATION can stay false . Despite the name, it does not apply to SAML: LibreChat creates the user account automatically on the first successful SAML login. Who can get in is therefore controlled in IAM Identity Center, through the group assigned to the LibreChat application.Setting the SAML Variables
Next, let's configure the SAML section in
.env . There are two things to know according to the SAML page in the LibreChat documentation and what I observed in LibreChat v0.8.8:- If OpenID is enabled, LibreChat disables SAML automatically. So leave the
OPENID_*variables unset in.env.
- In v0.8.8, the UI shows the user’s email address rather than a display name. Set
SAML_NAME_CLAIManyway so that the name is stored in the user profile.
Here is what the section should look like by default:
# SAML# Note: If OpenID is enabled, SAML authentication will be automatically disabled.SAML_ENTRY_POINT=SAML_ISSUER=SAML_CERT=SAML_CALLBACK_URL=/oauth/saml/callbackSAML_SESSION_SECRET=
# Attribute mappings (optional)SAML_EMAIL_CLAIM=SAML_USERNAME_CLAIM=SAML_GIVEN_NAME_CLAIM=SAML_FAMILY_NAME_CLAIM=SAML_PICTURE_CLAIM=SAML_NAME_CLAIM=
# Logint buttion settings (optional)SAML_BUTTON_LABEL=SAML_IMAGE_URL=
# Whether the SAML Response should be signed.# - If "true", the entire `SAML Response` will be signed.# - If "false" or unset, only the `SAML Assertion` will be signed (default behavior).# SAML_USE_AUTHN_RESPONSE_SIGNED=Based on the SAML page in the LibreChat documentation, set the environment variables as described below, using the information that you kept from the IAM Identity Center setup. If you need to retrieve it again, here is a screenshot of the information that you need from the SAML 2.0 application in IAM Identity Center:

-
SAML_ENTRY_POINT- Set it to the IAM Identity Center sign-in URL from the IAM Identity Center metadata section of the SAML 2.0 application.
-
SAML_ISSUER- Set it to the same value as Application SAML audience in the SAML 2.0 application. In my case, that is the LibreChat URL.
-
SAML_CERT- Set it to the content of the IAM Identity Center certificate PEM file downloaded from the IAM Identity Center metadata section of the SAML 2.0 application, with newline characters replaced by\nand the entire single-line value wrapped in double quotes. You may also store the file in the LibreChat file system and specify the path to the PEM file instead.
-
SAML_CALLBACK_URL- Set it to the same value as Application ACS URL in the SAML 2.0 application, for examplehttps://chat.yourdomain.com/oauth/saml/callback. LibreChat sends this value to IAM Identity Center as the assertion consumer service URL in the SAML request, so it should be the full URL and match the ACS URL exactly. In my testing, the default relative path caused IdP-initiated authentication to fail.
-
SAML_SESSION_SECRET- Set this to a random value. You can use the LibreChat Credentials Generator to generate some values and pick the value forCREDS_KEY, for example, as the SAML session secret.
-
SAML_NAME_CLAIM- Set it toname, which matches the attribute mapping in the SAML 2.0 application in IAM Identity Center. Unlike the other claim attribute names,SAML_NAME_CLAIMhas no default value.
Putting it all together, the updated section should look like the following (parts of actual values redacted for obvious reasons):
SAML_ENTRY_POINT=https://portal.sso.us-east-1.amazonaws.com/saml/assertion/<redacted>SAML_ISSUER=https://chat.yourdomain.comSAML_CERT="-----BEGIN CERTIFICATE-----\nMIIFXTCCBEWgAwIBAgIQNzE4NThmZmY1M2E2ZDllMTA2ZDk4YjNjZDQ0YzBhMA\n<remaining lines redacted>\n-----END CERTIFICATE-----"SAML_CALLBACK_URL=https://chat.yourdomain.com/oauth/saml/callbackSAML_SESSION_SECRET=<your generated secret>
# Attribute mappings (optional)SAML_EMAIL_CLAIM=SAML_USERNAME_CLAIM=SAML_GIVEN_NAME_CLAIM=SAML_FAMILY_NAME_CLAIM=SAML_PICTURE_CLAIM=SAML_NAME_CLAIM=nameLastly, restart LibreChat, and you should be ready to validate authentication via SAML 2.0.
Validating SP-Initiated and IdP-Initiated Authentication
SAML 2.0 has two ways to log in: SP-initiated and IdP-initiated. Let's validate both.
SP-Initiated Authentication
Go to the LibreChat URL. You should see Continue with SAML as the only option on the login page:

Clicking on the button will lead you to the IAM Identity Center login page. If you configured a federated identity source (such as Active Directory or Microsoft Entra ID), you should be redirected to the login page for the upstream IdP instead.

Upon successful authentication, you are redirected back to LibreChat, already logged in. Click the profile icon with your initials in the lower-left corner and you should see your email address.

Note that LibreChat does not support single logout (SLO). Clicking "Log out" ends only your LibreChat session, so anyone with access to the browser can sign straight back in while the IAM Identity Center session is active.
IdP-Initiated Authentication
Log in to IAM Identity Center. Once authenticated, you land in the AWS Access Portal. Select the Applications tab and you should see LibreChat as a tile:

Click on the tile and you should be successfully redirected to LibreChat, already logged in. With that, great job setting up SAML 2.0 single sign-on for LibreChat with IAM Identity Center!
If you followed the steps above, everything should be working. In case you need to adapt the setup to your own environment or run into issues later, I’ve put together some troubleshooting tips in the next section.
Troubleshooting "Bad Input" and "No Access" Errors
Troubleshooting SAML issues can be frustrating because the documentation is sparse, the errors are generic, and there are few logs to work with. Most SAML misconfigurations surface as a "Bad input" or "No access" error in IAM Identity Center:

Here are some tips that helped me troubleshoot more reliably:
- Use the network tab in your browser's developer tools to capture HTTP requests and responses for inspection. Make sure you enable the option to persist logs across redirects.
- Test first with SP-initiated authentication, because it lets you inspect the SAML request. Capture the request to
<librechat-base-url>/oauth/samland look at thelocationHTTP response header, which contains the encoded SAML request as theSAMLRequestURL query parameter. For example, here is what I captured in Firefox:

- Use the OneLogin SAML Developer Tools to help you decode and inflate the SAML request XML. First, use the URL encode/decode tool to decode the value copied from the URL query parameter. Then, use the Base64 decode + inflate tool to get the SAML request XML from the decoded Base64 string. The XML should help you see what values such as ACS URL and audience are passed to the IdP.
- A "Bad input" or "No access" error typically points to the SAML 2.0 application in IAM Identity Center, and chances are the attribute mappings are incorrect. I've also seen frequent changes to the attribute mappings corrupt the values to the point where the error becomes persistent. Short of opening an AWS support ticket, the only fix I found was deleting all mappings and re-entering them one by one while testing.
- IAM Identity Center provides a feature for troubleshooting SAML assertions in an IdP-initiated flow. Hold
Shiftwhile clicking the LibreChat application tile in the AWS Access Portal, and a new "administrator mode" tab opens that shows the SAML assertion XML. There you can inspect the attribute values (assuming no breaking mapping issues, otherwise you still get the "Bad input" or "No access" error).

- Check the LibreChat logs for SAML-related entries, which are typically written when a user logs in. With Docker Compose, you can follow them with:
docker compose logs -f api | grep -i saml- Consider temporarily increasing
LOGIN_MAXand/or adjustingLOGIN_WINDOWin LibreChat's.envwhen testing SAML login. See Login and registration rate limiting for details.
Summary
In this blog post, you enabled SSO for LibreChat with AWS IAM Identity Center as a SAML 2.0 identity provider. The configuration is not terribly difficult, but knowing the right details, and how to troubleshoot with limited signals, is key to success. I hope this post helps with both.
The details here may also help when you set up other IdPs, or other SPs that, like LibreChat, use Passport-SAML to implement SAML 2.0. If time allows, I will also write a page for the official LibreChat configuration documentation, similar to the one for Auth0 .
If you found this post helpful, you can find more like it on the Avangards Blog and AWS Builder Center ! Thanks for reading!
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article