{
"changeType": "created,updated,deleted",
"notificationUrl": "https://somewebsite.com/mswebhook/graph/notifications",
"resource": "/teams/{team-id}/channels/{channel-id}/messages",
"expirationDateTime": "2019-12-30T09:41:21Z",
"clientState": "",
"includeResourceData": true,
"encryptionCertificate": "TUlJQklUQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FRNEFNSUlCQ1FLQ0FRQlhFL0xOZjVYYVY4ZFlXbWFuSU9qUwphSnhyUG1tN0dHN0lWOGYwV2RjZDltbUkvaTVXQzhCNFBYaVBKREtKTnVFL2QvMXo5TndSbjR1UFBQQm9sN1BWCmdudVJ6UmZJSVEvUW1TZjYwUi9LUnYybHVlZzVwNW84Qk5UNDczdTRCbVZJVHNBWlF1eG43RGdnUi9JZlQzSVgKelpMdzNXWitDYzJyS1crblpmbUwwU0NiN21EL3RTZ3VqQUJPVEVvS0xBODkvNWhUamhuNzcvWHJzUTYrV1hMVgpKL3NtVDJvU3R3TzBnYXRIRUkwWkRSL0VYNkdVWDRRRVI4M0puS2hPSDJrZzZQNlZUMDFGUEw0Nk5WemZydWE4ClVob052Z0VlQStPY2xBOU5mUUpJQnVKUVFTbGZ0TmhYODJtVEdhVEtBTFN1bWZieUNac1ljQ3l4MXQ5RXF6Qi8KQWdNQkFBRT0=",
"encryptionCertificateId": "id",
"lifecycleNotificationUrl": "https://somewebsite.com/mswebhook/graph/notifications"
}
when this request is sent from postman It is giving
{
"error": {
"code": "InvalidRequest",
"message": "System.Security.Cryptography.CryptographicException: Cannot find the requested object.\r\n\r\n at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)\r\n at System.Security.Cryptography.X509Certificates.X509Utils._QueryCertBlobType(Byte[] rawData)\r\n at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromBlob(Byte[] rawData, Object password, X509KeyStorageFlags keyStorageFlags)\r\n at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData)\r\n at Microsoft.Graph.Encryptor.Encryptor.ValidateCertificate(String certificate, String& errorMessage) in X:\\bt\\1070414\\repo\\src\\Dev\\Notifications\\Notifications.Azure\\Encryptor\\Encryptor.cs:line 293",
"innerError": {
"request-id": "e578bdba-2c47-41d7-a0da-5395b05e4203",
"date": "2019-12-31T06:57:59"
}
}
}
without includeResourceData property, subscription and notifications are working fine.
I am facing problem while choosing encryptionCertificate property.Currently I am passing Base64bit encoded 2048 bit RSA public key (online generated) in encryptionCertificate.
Related
AWS Poinpoint APNS by default sets "mutable-content": 0.
I am using Node.js.
Below works fine, but mutable-content is always 0. "mutable-content": 0:
var messageRequest = {
'Addresses': {
https://forums.aws.amazon.com/: {
'ChannelType': channelType
}
},
'MessageConfiguration': {
'APNSMessage': {
'Action': action,
'Body': message,
'Priority': priority,
'SilentPush': silent,
'Title': title,
'TimeToLive': ttl,
'Url': url,
}
}
Below is the payload I get when an APNS is sent using the above setup
["aps": {
alert = {
body = "TEST";
title = "Test message sent from Amazon Pinpoint.";
};
"content-available" = 1;
"mutable-content" = 0;
}, "data": {
pinpoint = {
deeplink = "https://www.example.com";
};
}]
How can I set "mutable-content": 1 for an APNS through AWS Pinpoint?
There is no documentation but this worked for me after some trial and error:
var payload = {
"aps": {
"alert": {
"title": "Bold text in the notification",
"body": "Second line in the notification"
},
"sound": "default",
"mutable-content": 1
}
};
var messageRequest = {
Addresses: {
[token]: {
ChannelType: "APNS",
},
},
MessageConfiguration: {
APNSMessage: {
RawContent: JSON.stringify(payload),
},
},
};
Just replace their template with RawContent and create the payload as you would normally. Can refer to apple docs on how to create the raw payload. You can also adjust content-available key using this method. Here is the link to how to create a payload with json:
https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/generating_a_remote_notification
I know this is a bit old, but just ran into this issue and wanted to share my solution.
I found that setting the "MediaUrl" parameter to a non-empty string would cause pinpoint to send "mutable-content": 1
I did not see this in any of the pinpoint documentation.
I am building a small weather API as exercise to use QML and properly operate an API call using OpenWeather and you can see there a typical API response.
The problem I am having is that I can't get the API call to work. After setting a minimal example with some cities that you can see below, right next to the city it should appear the symbol of the weather, but it does not happen. The list of the icon can be found here. Source code of the MVE can be found here for completeness.
The error from the compiler: qrc:/main.qml:282: SyntaxError: JSON.parse: Parse error
This is what is happening
This is what is expected
Typical API JSON response can be found both here and below:
{
"coord": {
"lon": -122.08,
"lat": 37.39
},
"weather": [
{
"id": 800,
"main": "Clear",
"description": "clear sky",
"icon": "01d"
}
],
"base": "stations",
"main": {
"temp": 282.55,
"feels_like": 281.86,
"temp_min": 280.37,
"temp_max": 284.26,
"pressure": 1023,
"humidity": 100
},
"visibility": 16093,
"wind": {
"speed": 1.5,
"deg": 350
},
"clouds": {
"all": 1
},
"dt": 1560350645,
"sys": {
"type": 1,
"id": 5122,
"message": 0.0139,
"country": "US",
"sunrise": 1560343627,
"sunset": 1560396563
},
"timezone": -25200,
"id": 420006353,
"name": "Mountain View",
"cod": 200
}
Below a snippet of code related to the API call:
main.qml
// Create the API getcondition to get JSON data of weather
function getCondition(location, index) {
var res
var url = "api.openweathermap.org/data/2.5/weather?id={city id}&appid={your api key}"
var doc = new XMLHttpRequest()
// parse JSON data and put code result into codeList
doc.onreadystatechange = function() {
if(doc.readyState === XMLHttpRequest.DONE) {
res = doc.responseText
// parse data
var obj = JSON.parse(res) // <-- Error Here
if(typeof(obj) == 'object') {
if(obj.hasOwnProperty('query')) {
var ch = onj.query.results.channel
var item = ch.item
codeList[index] = item.condition["code"]
}
}
}
}
doc.open('GET', url, true)
doc.send()
}
In order to solve this problem I consulted several sources, first of all : official documentation and the related function. I believe it is correctly set, but I added the reference for completeness.
Also I came across this one which explained how to simply apply XMLHttpRequest.
Also I dug more into the problem to find a solution and also consulted this one which also explained how to apply the JSON parsing function. But still something is not correct.
Thanks for pointing in the right direction for solving this problem.
Below the answer to my question. I was not reading properly the JSON file and after console logging the problem the solution is below. code was correct from beginning, only the response needed to be reviewed properly and in great detail being the JSON response a bit confusing:
function getCondition() {
var request = new XMLHttpRequest()
request.open('GET', 'http://api.openweathermap.org/data/2.5/weather?q=London&units=metric&appid=key', true);
request.onreadystatechange = function() {
if (request.readyState === XMLHttpRequest.DONE) {
if (request.status && request.status === 200) {
console.log("response", request.responseText)
var result = JSON.parse(request.responseText)
} else {
console.log("HTTP:", request.status, request.statusText)
}
}
}
request.send()
}
Hope that helps!
In your code, your url shows this: "api.openweathermap.org/data/2.5/weather?id={city id}&appid={your api key}". You need to replace {city id} and {your api key} with real values.
You can solve it by providing an actual city ID and API key in your request URL
I write code for Restful services.in postman when i tried to send a request by using #Postmapping its getting error in postaman
this is my controller class
public class BookController {
private BookRepository bookrepository;
#PostMapping("/addBook")
public String save(#RequestBody Book book)
{
bookrepository.save(book);
return "added book with id"+book.getId();
}
#GetMapping("/findAllBooks")
public List<Book> getBooks()
{
return bookrepository.findAll();
}
#DeleteMapping("/delete")
public String deleteBook(#PathVariable int id){
bookrepository.deleteById(id);
return "book deleted"+id;
}
}
when i send a request to postman by post method at the time i m getting a error like the below
{
"timestamp": "2019-03-27T12:22:20.319+0000",
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/addBook"
}
When I run below console application from window it works
using System.Security.Cryptography.X509Certificates;
public static void Main(string[] args)
{
Console.WriteLine("File exists: " + File.Exists("key.p12"));
var certificate = new X509Certificate2("key.p12", "notasecret");
Console.WriteLine("Success");
Console.ReadLine();
}
but when I tried in AWS lambda its throwing error
.ctor: MissingMethodException
at Interop.Crypto.Pkcs12Parse(SafePkcs12Handle p12, String pass, SafeEvpPKeyHandle& pkey, SafeX509Handle& cert, SafeX509StackHandle& ca)
at Internal.Cryptography.Pal.OpenSslPkcs12Reader.Decrypt(String password)
at Internal.Cryptography.Pal.PkcsFormatReader.TryReadPkcs12(OpenSslPkcs12Reader pfx, String password, Boolean single, ICertificatePal& readPal, List`1& readCerts)
at Internal.Cryptography.Pal.PkcsFormatReader.TryReadPkcs12(SafeBioHandle bio, String password, Boolean single, ICertificatePal& readPal, List`1& readCerts)
at Internal.Cryptography.Pal.CertificatePal.FromBio(SafeBioHandle bio, String password)
at Internal.Cryptography.Pal.CertificatePal.FromFile(String fileName, String password, X509KeyStorageFlags keyStorageFlags)
at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(String fileName, String password, X509KeyStorageFlags keyStorageFlags)
at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(String fileName, String password)
at test_openssl_lambda.Functions.TriggerSync() in /tmp/src818283224/src/test-openssl-lambda/test_openssl_lambda/Function.cs:line 21
at lambda_method(Closure , Stream , Stream , ContextInfo )
Below is my project.json
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": false
},
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
},
"Amazon.Lambda.Core": "1.0.0",
"Amazon.Lambda.APIGatewayEvents": "1.1.0",
"Amazon.Lambda.Serialization.Json": "1.1.0",
"Amazon.Lambda.Tools": {
"type": "build",
"version": "1.5.0"
},
"System.Security.Cryptography.X509Certificates": "4.3.0"
},
"tools": {
"Amazon.Lambda.Tools": "1.5.0"
},
"frameworks": {
"netcoreapp1.0": {
"imports": "dnxcore50"
}
}
}
And calling Function.cs (which is same as above console application)
using System.Security.Cryptography.X509Certificates;
using Amazon.Lambda.Core;
[LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
public void Trigger()
{
Console.WriteLine("File exists: " + File.Exists("Key.p12"));
var certificate = new X509Certificate2("Key.p12", "notasecret");
Console.WriteLine("Success");
}
It throws exception because its not able to do DllImport System.Security.Cryptography.Native.OpenSsl in AWS Lambda environment(Linux kernel version – 4.4.51-40.60.amzn1.x86_64)
Can someone help me in fixing the issue? i.e., helping me to get installing System.Security.Cryptography.Native.OpenSsl in AWS Lambda?
This exception happens when the underlying machine doesn't have the required OpenSSL version prerequisite installed, which seems to be the case on AWS Lambda.
See https://github.com/dotnet/corefx/issues/14356
Now I have changed my project to .Net Core 2.1 and its working.
I am trying to implement custom authorizer lambda function via java SDK. Can somebody tell me the exact format of the JSON response that is expected from my lambda function. Also in which format i should return the output (JSON object or policy object).
{
"policyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": "execute-api:Invoke",
"Resource": [
"arn:aws:execute-api:us-east-1:1234567:myapiId/staging/POST/*"
],
"Effect": "Allow"
}
]
},
"principalId": "User123"
}
this is the format i am providing in output in JSONObject format but getting error
Mon Apr 10 09:42:35 UTC 2017 : Endpoint request body after
transformations:
{"type":"TOKEN","authorizationToken":"ABC123","methodArn":"arn:aws:execute-api:ap-southeast-1:007183653813:ohlqxu9p57/null/GET/"}
Mon Apr 10 09:42:36 UTC 2017 : Execution failed due to configuration
error: Authorizer function failed with response body:
{"errorMessage":"An error occurred during JSON serialization of
response","errorType":"java.lang.RuntimeException","stackTrace":[],"cause":{"errorMessage":"com.fasterxml.jackson.databind.JsonMappingException:
JsonObject (through reference chain:
com.google.gson.JsonObject[\"asString\"])","errorType":"java.io.UncheckedIOException","stackTrace":[],"cause":{"errorMessage":"JsonObject
(through reference chain:
com.google.gson.JsonObject[\"asString\"])","errorType":"com.fasterxml.jackson.databind.JsonMappingException","stackTrace":["com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:210)","com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:177)","com.fasterxml.jackson.databind.ser.std.StdSerializer.wrapAndThrow(StdSerializer.java:199)","com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:683)","com.f
[TRUNCATED] Mon Apr 10 09:42:36 UTC 2017 :
AuthorizerConfigurationException
Any help would be great. Thanks in advance
The issue you are facing is Lambda framework related.
Essentially, Lambda will invoke the handler function and pass a serialized JSON.
public class LambdaCustomAuthorizer implements RequestHandler<AuthorizationRequestDO, Object> {
public Object handleRequest(AuthorizationRequestDO input, Context context) { }
}
When you work with custom authorizer, API gateway passes following JSON to your lambda function:
{
"type":"TOKEN",
"authorizationToken":"",
"methodArn":"arn:aws:execute-api:::///"
}
you should have a custom DO AuthorizationRequestDO
which is a POJO::
public class AuthorizationRequestDO {
String authorizationToken;
String methodArn;
public String getAuthorizationToken() {
return authorizationToken;
}
public void setAuthorizationToken(String authorizationToken) {
this.authorizationToken = authorizationToken;
}
public String getMethodArn() {
return methodArn;
}
public void setMethodArn(String methodArn) {
this.methodArn = methodArn;
}
#Override
public String toString() {
return "AuthorizationRequestDO [authorizationToken=" + authorizationToken + ", methodArn=" + methodArn
+ ", getAuthorizationToken()=" + getAuthorizationToken() + ", getMethodArn()=" + getMethodArn() + "]";
}
}
Your Resource property should be a single string value.
{
"policyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": "execute-api:Invoke",
"Resource": "arn:aws:execute-api:us-east-1:1234567:myapiId/staging/POST/*",
"Effect": "Allow"
}
]
},
"principalId": "User123"
}