Handling Nullable Json Response when using RESTFul Technical Profile - azure-ad-b2c

I am using the REST technical profile to retrieve data from a claims provider.
The JSON payload that is returned includes values that are optional for some users.
When the value is not set, it will be returned as the null literal
When the value is set, it will be returned as a string that contains an ISO 8601 formatted date time.
User Group 1 (well formed ISO 8601 string)
{
"OptionalIso8601DateTime" : "2022-12-11T12:34:56Z"
}
User Group 2 (null literal)
{
"OptionalIso8601DateTime" : null
}
AAD B2C appears to have two distinct behaviours when processing the JSON Payload of a REST endpoint (that are not configurable) which results the inability for a claims mapping to be defined that does not result in a server_error response being generated for one group of users.
Behaviours:
All strings that are determined to contain valid dateTime string literals are automatically cast to dateTime
as a result, a valid dateTime string literal can only be mapped to claims of type dateTime
The null literal value is automatically cast as a string - and populated with the empty string value
as a result, the null literal can only be mapped to claims of type string
I have attempted to define mappings using the string and dateTime data types, however neither is able to function for both user groups.
Observations:
AAD B2C Claim DataType
Payload Value
Result
Comment
string
null
""
null literal is converted to empty string
string
"2022-12-11T12:34:56Z"
AADB2C99072
dateTime cannot be converted to string
dateTime
null
AADB2C99072
string cannot be converted to dateTime
dateTime
"2022-12-11T12:34:56Z"
1670762096
value emitted as number (unix epoch) as per default OpenId Jwt Issuance Policy
I have no control over the format of the payload that is returned by the external system. Ideally, they would omit the claim in the event that there is no value, however returning the null literal is valid according to the Json specification.
I am looking for a mechanism to be able to map the data (specifically the case where the value is not null) as a valid dateTime so that it can be passed to downstream applications - that does not result in authentication failing with error AADB2C99072 for one set of users.
Ideally, if there were some way to configure AAD B2C to ignore null values (treat them as absent from the payload), or for the null to be preserved so that there is not an error when the empty string is set as the value of the dateTime claim.

Related

How to add map in the Azure App Configuration

In the Azure App Configuration, we store value in the form of key-value pair. Generally, we store string values in the key-value pair like:
"key" : "red"
But I want to store map in value like:
"key" : {
1: {1,2,3},
2: {1,4}
}
In my spring-boot application, I will read the variable as Map<integer, List>
You can Leverage content-type to store JSON key-values in App Configuration.
Data is stored in App Configuration as key-values, where values are treated as the string type by default. However, you can specify a custom type by leveraging the content-type property associated with each key-value, so that you can preserve the original type of your data or have your application behave differently based on content-type.
Valid JSON values
When a key-value has JSON content-type, its value must be in valid JSON format for clients to process it correctly. Otherwise, clients may fail or fall back and treat it as string format. Some examples of valid JSON values are:
"John Doe"
723
false
null
"2020-01-01T12:34:56.789Z"
[1, 2, 3, 4]
{"ObjectSetting":{"Targeting":{"Default":true,"Level":"Information"}}}

Stop formData string from being converted to a date string representation

This one is being hard to uncover. We have a .NET Core 2.2 app in which we have a form with many fields and a field for the user to attach some file.
Problem: one specific field CaqhNumber has a min and max length = 8.
When the user types in a value for example 20200706 the value that get's sent to the server is a date string representation of this value. So on the server side we get:
07/06/2020
Basically it thinks this specific field is an ISO date.
How can one stop this from happening? We just want to get the string on the server side the way it was entered on the UI side. It's not a date. It's plain string in both sides.
Something tells me this is related to the .NET Core configs.
Guess what... there was a piece of code behind the curtains messing up with the value:
const isValidDate = moment(
value,
moment.ISO_8601,
true
).isValid();
if (isValidDate) {
formData.append(
key,
moment(value).format('MM/DD/YYYY')
);
The fix:
if (value instanceof Date) {
formData.append(key, moment(value).format('MM/DD/YYYY'));

Offsets In Azure Event Hubs

I have a small client application sending data to an Azure event hub, and another application reading from it.
According to https://msdn.microsoft.com/en-us/library/azure/dn789972.aspx, you can include an offset in the event hub receiver. I'm looking to include an offset in the form of the timestamp as mentioned on MSDN. Does anyone know how to do this? I can easily include the numerical string format for the offest (e.g string myOffset = "12345", but I can't seem to get the timestamp format.
Cheers
It's not clear what you mean by "can't seem to get the timestamp format", but when you create your receiver, you pass a DateTime data type to the CreateReceiver method.
public EventHubReceiver CreateReceiver(
string partitionId,
DateTime startingDateTimeUtc,
long epoch
)
See MSDN on CreateReceiver:
https://msdn.microsoft.com/en-us/library/dn790504.aspx
If you have the timestamp as a string, you might try the DateTime.Parse (or TryParse) method to get the DateTime value.
string MyString = "Aug 25, 2015";
DateTime MyDateTime = DateTime.Parse(MyString);
See more on MSDN for Parsing Time:
https://msdn.microsoft.com/en-us/library/2h3syy57(v=vs.110).aspx

PubNub message format in callbacks

When I get a callback, I get an object passed in. The content of the object seems to have two levels of 'encoding'. It always seems to consist of 3 basic elements:
My data
Timestamp
Channel
in that order so [0]=data, [1] = timestamp and [2] = channel where timestamp and channel are PubNub supplied strings. My data comes in as a JSON object (string, numeric, or object etc.) in the first item returned.
But nowhere can I find in the documentation that this structure (i.e. 3 incoming 'objects') is actually defined. If it is defined then I should be able to map a type or class to it, to better handle it, i.e. cast it to a 'PubNubMessage' class [object data; string timestamp; string channel;]?
Can someone please point me at a document where this message format is actually defined?

Checking for Null Values in CRM 2011 Custom Workflow Activity

I am trying to perform some logic in a CRM 2011 Custom Workflow Activity with some attributes from the calling entity. I am having an issue with determining whether a particular attribute is null or not. I have tried seemingly all combinations of GetAttributeValue and the Attributes collection, but it seems that I will always get either a Specified Cast is not Valid or Object Reference Not Set to an Instance of an Object error when there is a null value for an attribute I'm trying to access. Does anyone know the correct method for accessing an attribute that may be null? In this example, I am working with attributes of the Guid/Entity Reference type.
You can always check to see if the attributes collection contains the specific attribute that you're looking for, but you shouldn't even have to do that. All Non-nullable types (Guid, DateTime, etc) are stored as nullable types in the Attributes collection and that's probably your problem. Try something like this ( assuming late bound):
var isValid = entity.GetAttributeValue<bool?>("new_IsValid");
CRM never returns a non-nullable value. Even things that you think would be null (bool, DateTime, int, etc) are returned as their nullable equivalent. A non-nullable cast will still succeed if the value is not null, but if the value is null, it'll give you a null reference error;
object a = new bool?(true);
bool value = ((bool)a); // Works
object b = new bool?();
bool value = ((bool)b); // Null Ref Error
This syntax ended up working for me:
//if current outside counsel not null, grab GUID value
if (thisCase.lgl_outsidecounselid != null)
{
currentOCGUID = thisCase.lgl_outsidecounselid.Id;
}
//it's null, set Guid to Guid.empty
else
{
currentOCGUID = Guid.Empty;
}

Resources