Custom policy showing error labels on page load - azure-ad-b2c

I saw a question similar here. I'm facing the same issue with my policy too.
<ContentDefinition Id="api.localaccountsignup">
<LoadUri>https://mysite.azurewebsites.net/b2c/signup</LoadUri>
<RecoveryUri>~/common/default_page_error.html</RecoveryUri>
<DataUri>urn:com:microsoft:aad:b2c:elements:selfasserted:1.1.0</DataUri>
<Metadata>
<Item Key="DisplayName">Local account sign up page</Item>
</Metadata>
<LocalizedResourcesReferences MergeBehavior="Prepend">
<LocalizedResourcesReference Language="en" LocalizedResourcesReferenceId="signup_en" />
</LocalizedResourcesReferences>
</ContentDefinition>
Validation errors are showing on the page load itself. As the solution of the question says hide that using CSS, but is there any other solution to fix this from B2C without using style.?

Related

azure-ad-b2c custom policy how to localize Error messages

Hello iam looking for solution to localize error message to below message but seems it is not overriding
1. Added localization to below content definition tried MergeBehavior="Prepend",MergeBehavior="Append" and MergeBehavior="ReplaceAll"
<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:1.2.0</DataUri>
<Metadata>
<Item Key="DisplayName">Signin and Signup</Item>
</Metadata>
<LocalizedResourcesReferences MergeBehavior="Prepend">
<LocalizedResourcesReference Language="en" LocalizedResourcesReferenceId="api.signuporsignin.en" />
</LocalizedResourcesReferences>
</ContentDefinition>
2.Overriding localization using resources api.signuporsignin.en
<Localization Enabled="true">
<SupportedLanguages DefaultLanguage="en" MergeBehavior="ReplaceAll">
<SupportedLanguage>en</SupportedLanguage>
</SupportedLanguages>
<LocalizedResources Id="api.signuporsignin.en">
<LocalizedStrings>
<LocalizedString ElementType="ErrorMessage" StringId="UserMessageIfInvalidPassword">We didn't recognize this username and password combination.</LocalizedString>
</LocalizedStrings>
</LocalizedResources>
</Localization>
Can anyone suggest me any way to localize error messages in azure b2c custom policy(signupsignin)

Change Password with Custom Policy

We are following https://learn.microsoft.com/en-us/azure/active-directory-b2c/custom-policy-password-change#:~:text=Choose%20All%20services%20in%20the,for%20and%20select%20the%20TrustframeworkExtensions. to setup change password via custom policy.
Positive scenario works well, however, if a user provides incorrect old password, we get a message 'The username or password provided in the request are invalid.' Didn't find from where the message is coming.
Any leads would be helpful.
Verify in your validation technical profile in the metadata and confirm whether this is the information. see example below:
<TechnicalProfiles>
<TechnicalProfile Id="login-NonInteractive">
<DisplayName>Local Account SignIn</DisplayName>
<Protocol Name="OpenIdConnect" />
<Metadata>
<Item Key="UserMessageIfClaimsPrincipalDoesNotExist">We can't seem to find your account</Item>
<Item Key="UserMessageIfInvalidPassword">**Your password is incorrect**</Item>
<Item Key="UserMessageIfOldPasswordUsed">Looks like you used an old password</Item>
<Item Key="ProviderName">https://sts.windows.net/</Item>
<Item Key="METADATA">https://login.microsoftonline.com/{tenant}/.well-known/openid-configuration</Item>
<Item Key="authorization_endpoint">https://login.microsoftonline.com/{tenant}/oauth2/token</Item>
<Item Key="response_types">id_token</Item>
<Item Key="response_mode">query</Item>
<Item Key="scope">email openid</Item>
<Item Key="grant_type">password</Item>
<!-- Policy Engine Clients -->
<Item Key="UsePolicyInRedirectUri">false</Item>
<Item Key="HttpBinding">POST</Item>
</Metadata>

ContentDefinitionParameters with Default Value

I know how to send extra information during signin.
<ContentDefinitionParameters>
<Parameter Name="campaignId">{OAUTH-KV:customUi}</Parameter>
</ContentDefinitionParameters>
The only place I will be using this value is in the Content Definitions like below
<ContentDefinition Id="api.signuporsignin">
<LoadUri>cdn.mydomain.com/{OAUTH-KV:ui-version}/thepage.html</LoadUri>
<RecoveryUri>~/common/default_page_error.html</RecoveryUri>
<DataUri>urn:com:microsoft:aad:b2c:elements:contract:unifiedssp:1.2.0</DataUri>
<Metadata>
<Item Key="DisplayName">Signin and Signup</Item>
</Metadata>
<LocalizedResourcesReferences MergeBehavior="Prepend">
<LocalizedResourcesReference Language="en" LocalizedResourcesReferenceId="api.signuporsignin.en" />
</LocalizedResourcesReferences>
</ContentDefinition>
The problem with this is that if the front end, does not add the ui-version to the query string the login will error. I was wondering if it was possible to give this a default value? That way, if the parameter is missing, I can default it and the login will work.
Anyone any ideas on how best to achieve this?
If you want to append a static query parameter using custom policy use input claims
</CryptographicKeys>
<InputClaims>
<InputClaim ClaimTypeReferenceId="myQueryParam" DefaultValue="staticParamValue"/>
</InputClaims>
<OutputClaims>
this will append as &myQueryParam=staticParamValue.
If the input claim is not using a defaultValue, it will send whatever value is inside the claim at this point in time of policy execution. It could be a claims resolver too.

Override ContentDefinition at RelyingParty Azure AD B2C Custom Policy

Can I override the <ContentDefinition><LoadUri> in a RP policy?
RP Policy.xml
<BasePolicy>
<TenantId>mytenant.onmicrosoft.com</TenantId>
<PolicyId>B2C_1A_TFExts</PolicyId>
</BasePolicy>
<BuildingBlocks>
<ContentDefinitions>
<ContentDefinition Id="api.idpselections-ext-local">
<LoadUri>~/tenant/default/idpSelector.cshtml</LoadUri>
</ContentDefinition>
</ContentDefinitions>
</BuildingBlocks>
TFExts.xml
<BuildingBlocks>
<ContentDefinitions>
<ContentDefinition Id="api.idpselections-ext-local">
<LoadUri>https://localhost:44377/</LoadUri>
<RecoveryUri>~/common/default_page_error.html</RecoveryUri>
<DataUri>urn:com:microsoft:aad:b2c:elements:idpselection:1.0.0</DataUri>
<Metadata>
<Item Key="DisplayName">Idp selection page</Item>
<Item Key="language.intro">Sign in</Item>
</Metadata>
</ContentDefinition>
</ContentDefinitions>
</BuildingBlocks>
I was overwriting the wrong ContentDefinition Id. So yes, I can override a <ContentDefinition><LoadUri> in a relying party policy.
<BuildingBlocks>
<ContentDefinitions>
<ContentDefinition Id="api.selfasserted-ext-local">
<LoadUri>https://localhost:44377/</LoadUri>
</ContentDefinition>
</ContentDefinitions>
</BuildingBlocks>

How to Create a Custom Error Page in Azure AD B2C | Custom Policies

When using custom policies, how can I specify the error page for a <UserJourney>? Based on the values in the TFP base xml file, I would have thought it would be <RecoveryUri> but that is not working.
<ContentDefinition Id="api.signuporsignin-ext-local">
<!-- <LoadUri>~/tenant/default/unified.cshtml</LoadUri> -->
<LoadUri>https://localhost:44377/</LoadUri>
<!-- <RecoveryUri>~/common/default_page_error.html</RecoveryUri> -->
<RecoveryUri>https://localhost:44377/Home/Error</RecoveryUri>
<DataUri>urn:com:microsoft:aad:b2c:elements:unifiedssp:1.0.0</DataUri>
<Metadata>
<Item Key="DisplayName">Signin and Signup</Item>
</Metadata>
</ContentDefinition>
Current Result:
You would want to update the api.error content definition:
<!-- This content definition is to render an error page that displays unhandled errors. -->
<ContentDefinition Id="api.error">
<LoadUri>~/tenant/default/exception.cshtml</LoadUri>
<RecoveryUri>~/common/default_page_error.html</RecoveryUri>
<DataUri>urn:com:microsoft:aad:b2c:elements:globalexception:1.1.0</DataUri>
<Metadata>
<Item Key="DisplayName">Error page</Item>
</Metadata>
</ContentDefinition>

Resources