azure-ad-b2c / vscode-extension

Azure AD B2C VS code extension
MIT License
64 stars 37 forks source link

How to escape double quotes in appsettings? #61

Closed dochoss closed 3 years ago

dochoss commented 3 years ago

Hey team, my team is building some custom AD B2C policies and I'm looking to embed some XML metadata in my custom policy files. Production metadata is different than dev, so I'd like to be able to specify the metadata in the appsettings.json policy. However, adding the XML metadata in appsettings causes errors that leave the policy unable to be built. I've tried escaping double quotes in the metadata with single, double, and triple backslashes and removing line breaks, but none of this will resolve the errors. Any suggestions or assistance with how to accomplish this?

{
    "Environments": [
    {
      "Name": "Production",
      "Production": true,
      "Tenant": "my-tenant.onmicrosoft.com",
      "PolicySettings" : {
        "TenantId": "my-tenant GUID",
        "RelyingPartyPolicyName": "policyName",
        "AppInsightsKey": "myAppInsightsKey",
        "CertName": "myCertName",
        "DevPrefix": "",
        "RelyingPartyMetadata": "<md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" ID="myId" cacheDuration="PT1440M" entityID="myEntityId">
   <md:SPSSODescriptor protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
      <md:AssertionConsumerService index="0" Location="https://google.com" Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" isDefault="true" />
      <md:AttributeConsumingService index="0">
         <md:ServiceName xml:lang="en">AttributeContract</md:ServiceName>
         <md:RequestedAttribute Name="EmployeeID" />
         <md:RequestedAttribute Name="displayName" />
      </md:AttributeConsumingService>
   </md:SPSSODescriptor>
   <md:ContactPerson contactType="administrative" />
</md:EntityDescriptor>"
      }
    ]
  }
trittimo commented 3 years ago

@dochoss Your error is likely related to your newlines. You need to escape both the double quotes and newlines using backslash notation. e.g.

{
   "...": "",
   "PolicySettings": {
      "myXMLSetting": "<ClaimType Id=\"SomeId\">\n\t<DisplayName>SomeIdDisplay</DisplayName>\n\t<DataType>string</DataType>\n</ClaimType>"
   }
}

The extension isn't doing anything special related to JSON. It's just calling JSON.parse on the appsettings file. I'll note that the above policy setting works for me when building.

dochoss commented 3 years ago

Ah I see. I suspected it may have to do with white space. I'll try that. Should do the trick! I'll re-open if it doesn't. Thanks for your help @trittimo!