How can I decode a base64 string in Adaptive-Cards payload? - microsoft-teams

I need to decode a base64 string being sent from an external service to an MS-Teams Adaptive-Card via a webhook.
I have the webhook setup, tested with postman, all very easy, but I need to somehow decode a base64 string included in the payload, for example;
{
"#context": "https://schema.org/extensions",
"#type": "MessageCard",
"themeColor": "0072C6",
"title": "How to decode a base64 string?",
"text":"eg 'aGVsbG8='"
}
Anyone know if this is possible please?
TIA.
Jarrod.

It seems like there is no way to decode the code inside the Adaptive card.

Related

How do I decode/decrypt Apple Server-to-Server Notifications?

My website supports Sign In with Apple.
In the configurations of this service, I have an endpoint here:
What I receive in this endpoint is a JSON like this:
"{"payload":"eyJraW...................NLnyA"}
However, I don't find absolutely anywhere how to decrypt/decode this payload...
The "Learn more" link sends me here: https://developer.apple.com/help/account/configure-app-capabilities/about-sign-in-with-apple
The page below this one is this: https://developer.apple.com/help/account/configure-app-capabilities/enabling-server-to-server-notifications
Nowhere I see how to interpret these messages...
Does anyone know what do I need to do to read these payloads?
It looks like the general procedure for Server-to-Server notifications are outlined here. This is what the docs have to say:
These notifications contain a cryptographically signed payload, in JSON Web Signature (JWS) format, signed by Apple’s private key. After your server receives a notification, examine the JWS payload and use the algorithm specified in the header’s alg parameter to validate the signature. For more information, see Fetch Apple’s public key for verifying token signature.
So, this payload is really just a JWT (verify/decode with the JWT library of your choice, there are many to choose from). Because anyone can access your endpoint, you need to verify that the token is really from Apple. Note: do not try to decode the JWT yourself. Because of security concerns, it is better to let a library do it for you.
After validating the token signature, your server performs work according to the type value in the events claim of the token. The notification payload object contains information about user-initiated account modification events.
The decoded JWT will contain something like this (example is from the docs):
{
"iss": "https://appleid.apple.com",
"aud": "com.mytest.app",
"iat": 1508184845,
"jti": "abede...67890",
"events": {
"type": "email-enabled",
"sub": "820417.faa325acbc78e1be1668ba852d492d8a.0219",
"email": "ep9ks2tnph#privaterelay.appleid.com",
"is_private_email": "true"
"event_time": 1508184845
}
}
events.type has the event that happened (full list is here), and the rest of the token contains everything else you'll need.
#Michael M.'s answer helped me understanding that this payload is basically a JWT.
This is what we need to do (minimal example):
use Firebase\JWT\JWK;
use Firebase\JWT\JWT;
$json = json_decode(file_get_contents('php://input'));
$publicKeys = json_decode(file_get_contents('https://appleid.apple.com/auth/keys'), true);
$decodedPayload = JWT::decode($json->payload, JWK::parseKeySet($publicKeys));
var_dump($decodedPayload);

Is it possible to parameterize Post requests payload and then encode it to base64 in Jmeter

The background is that I want to make a REST to Google pub/sub. Where the data need to follow this format:
Link to documentation of Pub/Sub format
My current solution is that I uses an BeanShell PreProcessor script to encode the payload to base64 before I send the request to the endpoint. This solution works, but I would like to
parameterize the data in the payload, instead of having the whole payload inserted as test data in the csv-file.
BeanShell PreProcessor used to encode the message before it is being sent:
import org.apache.jmeter.protocol.http.util.Base64Encoder;
String csv_payload = vars.get("csv_payload");
String csv_payload_encoded = Base64Encoder.encode(csv_payload);
vars.put("csv_payload_encoded", csv_payload_encoded);
Payload populated from the csv-file in Post request:
{
"messages": [
{
"data":"${csv_payload_encoded}",
}
]
}
Example of payload data stored in the csv-file that is sent in the request:
{"identId":"123456","requestId":null,"payload":{"header":{"requestid":1,"timeStamp":1617873956,"version":"0.0.0.1","eventId":0001,"creatorId":0,"messageTTL":34560},"body":{"checkid":001,"checkData":{"diagnosticsData":{"troubleSource":0,"data":"[2020-01-01 16:00:53.707961][[lat[0]][long[0]][alt[0]][canbetrust[0]][mars[0]]][signal[5]][TEM2 wake up]"}}}}}
Example of the encoded payload that the request sends to google pub/sub:
{
"messages": [
{
"data":"eyJpZGVudElkIjoiMTIzNDU2IiwicmVxdWVzdElkIjpudWxsLCJwYXlsb2FkIjp7ImhlYWRlciI6eyJyZXF1ZXN0aWQiOjEsInRpbWVTdGFtcCI6MTYxNzg3Mzk1NiwidmVyc2lvbiI6IjAuMC4wLjEiLCJldmVudElkIjowMDAxLCJjcmVhdG9ySWQiOjAsIm1lc3NhZ2VUVEwiOjM0NTYwfSwiYm9keSI6eyJjaGVja2lkIjowMDEsImNoZWNrRGF0YSI6eyJkaWFnbm9zdGljc0RhdGEiOnsidHJvdWJsZVNvdXJjZSI6MCwiZGF0YSI6IlsyMDIwLTAxLTAxIDE2OjAwOjUzLjcwNzk2MV1bW2xhdFswXV1bbG9uZ1swXV1bYWx0WzBdXVtjYW5iZXRydXN0WzBdXVttYXJzWzBdXV1bc2lnbmFsWzVdXVtURU0yIHdha2UgdXBdIn19fX19",
}
]
}
If there are any feedback I would appreciate it or any other improvements suggestion
for how I would be able to proceed in order to parameterize and encode the payload to base64 eg:
Example of
Don't use Beanshell, since JMeter 3.1 you're supposed to be using JSR223 Test Elements and Groovy language for scripting
There is __base64Encode() function available via Custom JMeter Functions plugin bundle installable using JMeter Plugins Manager
If you CSV file has references to other JMeter Functions or Variables you can resolve them by wrapping into __eval() function like:
to read the file:
${__FileToString(somefile.csv,,)}
to read the file and resolve any functions or variables in it:
${__eval( ${__FileToString(somefile.csv,,)})
to read the file, resolve any functions or variables and Base64-encode the result:
${__base64Encode(${__eval( ${__FileToString(somefile.csv,,)})},)}
Demo:

How can I use the bot composer to dynamically configure the body part of a HTTP REQUEST

I am using Bot Composer to publish my first chatbot. I need to construct the chatbot to send out an HTTP POST request to fetch external resources from a remote website. As specified by the composer interface, I can embed JSON, form data, or string in the body of the HTTP POST request. Instead of hard-coding the body part of the POST request, I need to pass in one or multiple properties (chatbot's variable) to generate the body of the HTTP POST dynamically. Here are my questions:
(1) can I pass a variable to the body part of the HTTP REQUEST (such as POST)? can I embed a property such as $(user. name) in the HTTP POST body?
For example, can I embed a property such as $(user.name) in a string or form data (such as fname=$(user. name) to construct the body part of the HTTP POST REQUEST?
(2) The document specifies that there is a pre-build function JSON to serialize data. If I understand correctly, I can't pass a variable (such as $(user. name) to the JSON pre-built function. Therefore, I will probably need to embed an expression in the body to pass the variable. Yet, I couldn't find any detailed information. Is there anywhere I can find a good example showing how to write an expression inside the body part of the HTTP REQUEST
Thanks for any information/assistance.
Yes, you can do this. The simplest way is to set the body to Object and then put in your structured json, something similar to:
{
"userinfo": {
"username": "${user.username}",
"name": "${user.personalname}",
"favoritecolor": "${user.favcolor}",
"profileupdated":"${dialog.userprofileuptodate}"
}
}
I am trying to figure out how to set it up in an adaptive expression in LG, and then be able to refrence it with something like:
# APIBodyTemplate()
-```
{
"userinfo": {
"username": "${user.username}",
"name": "${user.personalname}",
"favoritecolor": "${user.favcolor}",
"profileupdated":"${dialog.userprofileuptodate}"
}
}
```
And then using something like the following in an expression in the body field:
=json(APIBodyTemplate()), but that is not quite working yet. Might be a bug. I will update when I have more info.

Send Images With Raw Option In Postman

I'm trying to send a list of objects to my server with Postman. However, I can't find information about how to send images in Postman using the Raw option. I'm thinking of trying something like this:
[
{
"name": "image1",
"file": "(i don't know what to type here)"
},
{
"name": "image2",
"file": "(i don't know what to type here)"
}
]
Any help will be highly appreciated.
If you have a specific use case for uploading using Raw, then you can encode your images to base64 and send in JSON that way. See this answer for more info: Answer
An easier way to do this is to use form-data, and select File instead of Text. Then, you can select 1 or more files to send in the body.
Postman docs for sending data: Docs

Disable HTML encoding of substitution_data

After we switched from Mandrill to SparkPost we encountered issues when sending emails using transmission. In Mandrill merge_vars were not HTML encoded and we sometimes put HTML in them, however in SparkPost substitution_data does appear to be HTML encoded and it's messing some of our emails. Is there a global setting that allows to turn this off or at least disable it for a transmission?
Edit: I forgot to mention that we use csharp-sparkpost library, which means it might be a problem directly related to the library rather than SparkPost API and I need to investigate it further.
Edit2: I tested sending an email directly using JSON and the result was the same, so I can conclude that the HTML encoding is done by SparkPost and not by the c# library.
You can render HTML in substitution variables without escaping by using 3 braces around your variables. e.g. With this in your transmission:
{
"substitution_data": {
"firstName": "<em>Jimbo</em>"
},
"content": {
"html": "<p>Hi {{{firstName}}}</p>"
}
}
...you get this in your HTML message body:
<p>Hi <em>Jimbo</em></p>
There are more details in the SparkPost reference docs: https://developers.sparkpost.com/api/#/introduction/substitutions-reference/escaping-html-values

Resources