google glass notification mismatch development and production server - google-glass

I try to send notification through menu in my app using mirror api. for development environment I am using a proxy server but in production I am using just SSl cause it is public domain. my callback URL for this two section is bellow
// development
callbackUrl = "https://3a4660af.ngrok.com/notify";
// production
if (callbackUrl.equals("https://www.mydomain.com:8080/notify")) {
callbackUrl = "https://www.mydomain.com:8443/notify";
} else {
callbackUrl = "https://www.mydomain.com:8443/notify";
}
LOG.info("\ncallbackUrl : " + callbackUrl);
Subscription subscription = new Subscription();
subscription.setCollection(collection);
subscription.setVerifyToken(userId);
subscription.setCallbackUrl(callbackUrl);
subscription.setUserToken(userId);
getMirror(credential).subscriptions().insert(subscription)
.execute();
But when I try to read notification from notification class I got mismatch so that the notification action is not working. the notification log in bellow
//development
got raw notification : { "collection": "timeline",
"itemId": "6fa2445e-b14f-46b2-9cff-f0d44d63ecab",
"operation": "UPDATE", "verifyToken": "103560737611562800385",
"userToken": "103560737611562800385",
"userActions": [ { "type": "CUSTOM", "payload": "dealMenu" } ]}
//production
got raw notification : "collection": "timeline",
"operation": "UPDATE",
"userToken": "103560737611562800385", { "payload": "dealMenu" ]null
in Notification class
BufferedReader notificationReader = new BufferedReader(
new InputStreamReader(request.getInputStream()));
String notificationString = "";
// Count the lines as a very basic way to prevent Denial of Service
// attacks
int lines = 0;
while (notificationReader.ready()) {
notificationString += notificationReader.readLine();
lines++;
LOG.info("\ngot raw notification during read : "
+ notificationString);
// No notification would ever be this long. Something is very wrong.
if (lines > 1000) {
throw new IOException(
"Attempted to parse notification payload that was unexpectedly long.");
}
}
LOG.info("\ngot raw notification : " + notificationString);
JsonFactory jsonFactory = new JacksonFactory();
LOG.info("\ngot jsonFactory : " + jsonFactory);
// If logging the payload is not as important, use
// jacksonFactory.fromInputStream instead.
Notification notification = jsonFactory.fromString(notificationString,
Notification.class);
LOG.info("\n got notification " + notification);
In production I cannot received all the perimeters what I need. Why this mismatch happen???

Related

How to add content_available when I use fcm by aws pinpoint? (iOS background message handler)

I was checked that setBackgroundMessageHandler of #react-native-firebase/messaging module works well when tested as follows body through FCM REST API.
{
"to" : DEVICE_TOKEN,
"notification" : {
"body" : "TEST BODY",
"title": "TEST TITLE"
},
"content_available":true
}
I want to send FCM message through aws pinpoint.
When I checked, #react-native-firebase/messaging module can receive notification type message.
Therefore, to send a notification message, I create and send a message as shown below.
let params = {
ApplicationId: applicationID /* required */,
SendUsersMessageRequest: {
/* required */
MessageConfiguration: {
/* required */
GCMMessage: {
"RawContent": `{\"notification\": {\"title\": \"${title}\",\"body\":\"${message}\", \"sound\":\"default\"}, \"content_available\": \"true\"}`
},
},
Users: users,
},
};
try {
return await pinpoint.sendUsersMessages(params).promise();
} catch (err) {
console.log('Error - ', err);
}
LOG A new FCM message arrived! {"messageId":"1656032665101862","data":{"pinpoint.campaign.campaign_id":"_DIRECT"},"notification":{"body":"TEST BODY","sound":"default","title":"TEST TITLE"},"from":"560179008583"}
However, when checking the remoteMessage, the content_available value cannot be received by the app.
Is there any way to send content_available using AWS Pinpoint's GCMMessage?
If you have any guides or advice for me to solve this problem, please.

AWS Pinpoint: Set APNS "mutable-content": 1

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.

AWS Dedicated long code number fails to send SMS

I have requested a dedicated long code number from AWS Pinpoint. And I have enabled two way sms for it. And tried to send TRANSACTIONAL SMS to a number, Although SMS's are receiving but they are not from My dedicated long code but they are from default senderId IM-NOTICE.
SAMPLE PYTHON CODE I TRIED:
region = "ap-south-1"
originationNumber = "+91xxxxxxxxxx"
destinationNumber = "+91xxxxxxxxxx"
message = ("This is a sample message sent from Amazon Pinpoint by using the "
"AWS SDK for Python (Boto 3).")
applicationId = "xxxxxxxxxxxxxxxxx"
messageType = "TRANSACTIONAL"
registeredKeyword = "xxxxxx"
senderId = "MySenderID"
client = boto3.client('pinpoint',
aws_access_key_id='AKIAIVXXXXXXKHXXXXP33RWFHLNXXXXXXXYYA',
aws_secret_access_key='XXXUPbs6Kj6O2iXXXXXXXXXXXXXXX',
region_name=region)
try:
response = client.send_messages(
ApplicationId=applicationId,
MessageRequest={
'Addresses': {
destinationNumber: {
'ChannelType': 'SMS'
}
},
'MessageConfiguration': {
'SMSMessage': {
'Body': message,
'Keyword': registeredKeyword,
'MessageType': messageType,
'OriginationNumber': originationNumber,
'SenderId': senderId
}
}
}
)
except ClientError as e:
print(e.response['Error']['Message'])
else:
print("Message sent! Message ID: "
+ response['MessageResponse']['Result'][destinationNumber]['MessageId'])

Integrating ASP.NET Web Api and Android Volley

I'm developing an ASP.NET Web Api project with Entity Framework and other project with Android and the Volley lib.
The idea is the project in ASP.NET to be the server and the Android app the client.
Both projects already work. The ASP.NET project is already connected to SQL Server and returns values in json format from one database, and the client also parses json from an online server that I used for testing when I was following one tutorial.
ASP.NET Web Api Controller:
public class StoreController : ApiController
{
// GET: api/Store
public IEnumerable<bo> Get()
{
using (EGLA_PHCEntities services = new EGLA_PHCEntities())
{
return services.bo.Where(e => e.nmdos == "Ficha Servico 30").Where(e => e.fechada == false).ToList();
}
}
...
}
Android:
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = response.getJSONArray(null);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject employee = jsonArray.getJSONObject(i);
String firstName = employee.getString("fieldA");
String mail = employee.getString("fieldB");
mTextViewResult.append(firstName + ", " + mail + "\n\n");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
});
The problem is that my project in ASP.NET does not return a name for the array of objects, and Android is waiting for a name.
The solution can be applied in one side or another. It can go through the ASP.NET project to return a name, or the project in Android to parse the json with an empty array name.
Modified because the list of fields is very extense:
[
{
"fieldA":"Something",
"fieldB":"Store 30",
},
{
"fieldA":"Something 2",
"fieldB":"Store 30 2",
}
]
The error that is returned in the Android app is "org.json.JSONException: No value for null". If I change
JSONArray jsonArray = response.getJSONArray(null);
to:
JSONArray jsonArray = response.getJSONArray("services");
The error returned is: "org.json.JSONException: No value for services"

Identity Server 3 Token Request from POSTMAN Http Tool

Using POSTMAN, I'm struggling to to retrieve my Identity Server 3 token.
Error code is : 400 Bad Request
Here are the details:
POST /identity/connect/token HTTP/1.1
Host: localhost:44358
Content-Type: application;x-www-form-urlencoded
Cache-Control: no-cache
Postman-Token: 57fc7aef-0006-81b2-8bf8-8d46b77d21d1
username=MYUSER-ID&password=MY-PASSWORD&grant_type=password&client_id=rzrwebguiangulajsclient&client_secret=myclientsecret&redirect_uri=https://localhost:44331/callback
I've done something similar with a simple Visual Studio 2015 WebApi project, where the end point was \token.
Any guidance/advice is appreciated...
regards,
Bob
The minimum required for a Resource Owner OAuth request is the following (line breaks added for readability):
POST /connect/token
Header
Content-Type: application/x-www-form-urlencoded
Body
username=MYUSER-ID
&password=MY-PASSWORD
&grant_type=password
&client_id=rzrwebguiangulajsclient
&client_secret=myclientsecret
&scope=api
Off the bat you are not requesting a scope in your request. Otherwise there is most probably something wrong in the configuration of your client within Identity Server.
Your best bet would be to enable logging and look at what comes back when this request errors.
Update: also, please don't use the ROPC grant type
I'm happy to say that we got Postman to work.
It turns out I was so close to getting Postman to work with Identity Server 3 Authorization.
The final piece to the solution was setting the Postman client Flow to Flow = Flows.ClientCredentials (see the postmantestclient client definition below):
using System.Collections.Generic;
using IdentityServer3.Core.Models;
namespace MyWebApi.MyIdentityServer.Config
{
public static class Clients
{
public static IEnumerable<Client> Get()
{
return new[]
{
new Client
{
ClientId = MyConstants.MyIdentityServer.MyWebGuiClientId,
ClientName = "My Web Gui Client",
Flow = Flows.Implicit,
AllowAccessToAllScopes = true,
IdentityTokenLifetime = 300,
AccessTokenLifetime = 300, //5 minutes
RequireConsent = false,
// redirect = URI of the Angular application
RedirectUris = new List<string>
{
MyConstants.MyIdentityServer.MyWebGuiUri + "callback.html",
// for silent refresh
MyConstants.MyIdentityServer.MyWebGuiUri + "silentrefreshframe.html"
},
PostLogoutRedirectUris = new List<string>()
{
MyConstants.MyIdentityServer.MyWebGuiUri + "index.html"
}
},
new Client
{
ClientId = MyConstants.MyIdentityServer.SwaggerClientId,
ClientName = "Swagger Client",
Flow = Flows.Implicit,
AllowAccessToAllScopes = true,
IdentityTokenLifetime = 300,
AccessTokenLifetime = 300,
RequireConsent = false,
// redirect = URI of the Angular application
RedirectUris = new List<string>
{
"https://localhost:44358/swagger/ui/o2c-html"
}
},
new Client
{
ClientId = "postmantestclient",
ClientName = "Postman http test client",
Flow = Flows.ClientCredentials,
AllowAccessToAllScopes = true,
IdentityTokenLifetime = 300,
AccessTokenLifetime = 300, //5 minutes
RequireConsent = false,
ClientSecrets = new List<Secret>
{
new Secret("PostmanSecret".Sha256())
},
RedirectUris = new List<string>()
{
"https://www.getpostman.com/oauth2/callback"
}
}
};
}
}
}