veejar
veejar

Reputation: 141

Enable Javascript on B2C Custom Policy

Javascript is disabled on the Client Side, even though i have added below as per documentation.

<RelyingParty>
  <DefaultUserJourney ReferenceId="B2CSignUpOrSignInWithPassword" />
  <UserJourneyBehaviors>
   <ScriptExecution>Allow</ScriptExecution>
  </UserJourneyBehaviors>
  ...
</RelyingParty>

When i try to upload the Custom Policy, i get an error - "Please use page contract in content definitions when enabling JavaScript." Cannot find anything related to this error in documentation.

Tried to add metadata to content definitions, using datauri -

<ContentDefinition Id="api.localaccountpasswordreset">  
  <RecoveryUri>~/common/default_page_error.html</RecoveryUri>
 <DataUri>urn:com:microsoft:aad:b2c:elements:contract:selfasserted:1.1.0</DataUri>
  ...
 </ContentDefinition>

Expect javascript to work on client side login pages

Upvotes: 14

Views: 10869

Answers (5)

Mobin Molai
Mobin Molai

Reputation: 21

Replace all the data URIs in your content definitions with the one's defined in the below url:

B2C Documentation Reference Custom Policy Schema (ContentDefinitions)

Use and replace to the new data URI instead of Old DataUri value one everywhere in your policy documents and this will fix the issue.

Mine was fixed using the same approach. Not only that but the Microsoft documentation clearly states that

If you intend to use JavaScript, you need to define a page layout version with page contract version for all of the content definitions in your custom policy.


This is an overview of the process: Enable JavaScript and page layout versions in Azure Active Directory B2C

Upvotes: 2

Sandesh Segu
Sandesh Segu

Reputation: 103

Replace the DataUri tag from

<DataUri>urn:com:microsoft:aad:b2c:elements:idpselection:1.2.0</DataUri> to <DataUri>urn:com:microsoft:aad:b2c:elements:contract:providerselection:1.2.0</DataUri>

for the ContentDefinition api.idpselections and api.idpselections.signup.

Upvotes: 7

Willian De Castro
Willian De Castro

Reputation: 81

I facing the same problem, to correct I follow this steps(for custom policies):

  1. _Base.Xml go to ContentDefinitions and find DataUri, change all old uris to new like this link https://learn.microsoft.com/en-us/azure/active-directory-b2c/contentdefinitions#migrating-to-page-layout

  2. Ensure that you have the word contract between your elements and your page identifier, example: change this urn:com:microsoft:aad:b2c:elements:globalexception:1.2.0 for this urn:com:microsoft:aad:b2c:elements:contract:globalexception:1.2.0

  3. In your specific Custom Polcy, find for RelyingParty and add the ScriptExecution element to the UserJourneyBehaviors element of RelyingParty

some like this

<RelyingParty>
  <DefaultUserJourney ReferenceId="B2CSignUpOrSignInWithPassword" />
  <UserJourneyBehaviors>
    <ScriptExecution>Allow</ScriptExecution>
  </UserJourneyBehaviors>
  ...
</RelyingParty>
  1. upload the base.xml
  2. upload your custom policy.xml

Upvotes: 3

marek_lani
marek_lani

Reputation: 4123

I observed two issues despite having all the settings of AAD B2C policies correct. First issue was that browser was caching old html and I needed to to reload with clearing the cache. Another issue was that if I followed recommendation from AAD B2C documentation to palce the script into header, it wasn't executing. I moved it to the body element and it worked.

Upvotes: 0

Kamruzzaman
Kamruzzaman

Reputation: 1443

It's work for me Only when I update all ContentDefinition with contract Like, It's take my time

SignUpOrSignin.xml

<UserJourneyBehaviors>
  ...
  <ScriptExecution>Allow</ScriptExecution>
</UserJourneyBehaviors>

TrustFrameworkExtensions.xml / TrustFrameworkBase.xml

<ContentDefinition Id="api.selfasserted.appfactor.registration">
    <LoadUri>https://raw.githubusercontent.com/mdzzaman/dev-info/master/az/selfasserted-appfactor-registration.html</LoadUri>
    <RecoveryUri>https://raw.githubusercontent.com/mdzzaman/dev-info/master/az/selfasserted-appfactor-registration.html</RecoveryUri>
    <DataUri>urn:com:microsoft:aad:b2c:elements:contract:selfasserted:2.1.6</DataUri>
    <Metadata>
      <Item Key="DisplayName">App Factor</Item>
    </Metadata>
  </ContentDefinition>


 <ContentDefinition Id="api.error">
    <LoadUri>~/tenant/templates/AzureBlue/exception.cshtml</LoadUri>
    <RecoveryUri>~/common/default_page_error.html</RecoveryUri>
    <DataUri>urn:com:microsoft:aad:b2c:elements:contract:globalexception:1.2.1</DataUri>
    <Metadata>
      <Item Key="DisplayName">Error page</Item>
    </Metadata>
  </ContentDefinition>

  <ContentDefinition Id="api.signuporsignin">
    <LoadUri>~/tenant/templates/AzureBlue/unified.cshtml</LoadUri>
    <RecoveryUri>~/common/default_page_error.html</RecoveryUri>
    <DataUri>urn:com:microsoft:aad:b2c:elements:contract:unifiedssp:2.1.4</DataUri>
    <Metadata>
      <Item Key="DisplayName">Signin and Signup</Item>
    </Metadata>
  </ContentDefinition>

... All

Upvotes: 0

Related Questions