-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix CORS setup #1782
Fix CORS setup #1782
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,6 +191,16 @@ var tags = { 'azd-env-name': environmentName } | |
var tenantIdForAuth = !empty(authTenantId) ? authTenantId : tenantId | ||
var authenticationIssuerUri = '${environment().authentication.loginEndpoint}${tenantIdForAuth}/v2.0' | ||
|
||
// Configure CORS for allowing different web apps to use the backend | ||
// For more information please see https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS | ||
var msftAllowedOrigins = [ 'https://portal.azure.com', 'https://ms.portal.azure.com' ] | ||
var loginEndpoint = environment().authentication.loginEndpoint | ||
var loginEndpointFixed = lastIndexOf(loginEndpoint, '/') == length(loginEndpoint) - 1 ? substring(loginEndpoint, 0, length(loginEndpoint) - 1) : loginEndpoint | ||
var allMsftAllowedOrigins = !(empty(clientAppId)) ? union(msftAllowedOrigins, [ loginEndpointFixed ]) : msftAllowedOrigins | ||
var allowedOrigins = union(split(allowedOrigin, ';'), allMsftAllowedOrigins) | ||
// Filter out any empty origin strings and remove any duplicate origins | ||
var allowedOriginsEnv = join(reduce(filter(allowedOrigins, o => length(trim(o)) > 0), [], (cur, next) => union(cur, [next])), ';') | ||
|
||
@description('Whether the deployment is running on GitHub Actions') | ||
param runningOnGh string = '' | ||
|
||
|
@@ -283,7 +293,7 @@ module backend 'core/host/appservice.bicep' = { | |
managedIdentity: true | ||
virtualNetworkSubnetId: isolation.outputs.appSubnetId | ||
publicNetworkAccess: publicNetworkAccess | ||
allowedOrigins: [ allowedOrigin ] | ||
allowedOrigins: allowedOrigins | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this always end up allowing origins even if they don't enable user auth? I dont see a conditional that makes it empty in that case. But maybe my eyes have glazed over. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or maybe we always allowed them anyway? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. allowedOrigin should be empty if they don't enable user auth. I will double check this, good catch There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this is an interesting case
My thought is that we want to only add in the portal / login origins if auth is enabled, otherwise just pick the origins they added. I'll make this adjustment |
||
clientAppId: clientAppId | ||
serverAppId: serverAppId | ||
enableUnauthenticatedAccess: enableUnauthenticatedAccess | ||
|
@@ -336,7 +346,7 @@ module backend 'core/host/appservice.bicep' = { | |
AZURE_AUTH_TENANT_ID: tenantIdForAuth | ||
AZURE_AUTHENTICATION_ISSUER_URI: authenticationIssuerUri | ||
// CORS support, for frontends on other hosts | ||
ALLOWED_ORIGIN: allowedOrigin | ||
ALLOWED_ORIGIN: allowedOriginsEnv | ||
USE_VECTORS: useVectors | ||
USE_GPT4V: useGPT4V | ||
USE_USER_UPLOAD: useUserUpload | ||
|
@@ -868,4 +878,5 @@ output AZURE_USERSTORAGE_RESOURCE_GROUP string = storageResourceGroup.name | |
|
||
output AZURE_USE_AUTHENTICATION bool = useAuthentication | ||
|
||
output ALLOWED_ORIGIN string = allowedOriginsEnv | ||
output BACKEND_URI string = backend.outputs.uri |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do need to allow credentials