Open josefaidt opened 3 months ago
I’m facing a similar issue. We have configured multiple Azure Enterprise Apps for SSO login, with each app designated for a specific environment (dev, test, and prod). Is it possible to dynamically configure the metadataContent
based on the git branch or environment variable? Because the metadataContent
value is different in each app.
Hey @binli0114 you can store this as an environment variable or an SSM Parameter to reference in your auth definition
@josefaidt SSM Parameter won't work because they are resolved in runtime. Do you have example of using environment variable? Thanks
@josefaidt Thanks for the hint, I figured out how to do it.
Add preBuild commands in amplify.yml for the backend
backend:
phases:
preBuild:
commands:
- |
if [ "$AWS_BRANCH" = "dev" ]; then
echo "SAML_PROVIDER_APP_ID=123" >> .env
elif [ "$AWS_BRANCH" = "test" ]; then
echo "SAML_PROVIDER_APP_ID=456" >> .env
elif [ "$AWS_BRANCH" = "prod" ]; then
echo "SAML_PROVIDER_APP_ID=789" >> .env
fi
In the auth/resource.ts
add following
import 'dotenv/config';
const SAML_PROVIDER_APP_ID = process.env.SAML_PROVIDER_APP_ID || '0000';
export const auth = defineAuth({
loginWith: {
email: true,
externalProviders: {
saml:{
name: "Azure-AD-SAML",
metadata:{
metadataContent:`https://login.microsoftonline.com/xxxxx/federationmetadata/2007-06/federationmetadata.xml?appid=${SAML_PROVIDER_APP_ID}`,
metadataType:"URL"
},
...
}
Another use case for multiple SAML providers is building multi-tenant enterprise SaaS on Amplify when different customers will be onboarded for SSO with their own identity providers. Currently, Amplify supports multiple OIDC providers but only one SAML. AWS Cognito doesn't have such a limitation, it's possible to configure multiple SAML providers for a single user pool.
Environment information
Description
In the event I have an "internal" and "external" SAML provider, I'd like to set both SAML providers on my user pool so I can programmatically redirect end users to sign in with one or the other based on some condition.