How to send push notification via postman using AWS Pinpoint - android

I want to send push notifications to mobile apps using REST API provided by AWS. I read their documentation but i am getting an error unauthorized. Does any one able to send push notification using REST API ?
The following is an example of a REST request int the documentation
GET /v1/apps/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/campaigns
Accept: application/json
Authorization: AWS4-HMAC-SHA256 Credential=AKIAIOSFODNN7EXAMPLE/20161127/us-
east-1/mobiletargeting/aws4_request, SignedHeaders=accept;host;x-amz-date,
Signature=a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z6a1b2c3d4e5f6
Host: pinpoint.us-east-1.amazonaws.com
X-Amz-Date: 20161127T202324Z
Following is the error I am getting
The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details

Currently, if I specify my AWS AccessKey & SecretKey in the Postman Environment as per the Amazon Pinpoint tutorial with POSTMAN I also get the same error message : The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details..
To get this setup working, I have specified my AWS AccessKey & SecretKey in Postman Authorization tab as illustrated below :
Below is a screenshot of the push notification message received on my Android phone:

Related

Failed to Test Access to Google Photo

After trying to read ALL the documentation about Google Photo API access ... I've failed.
Just testing web access with:
https://photoslibrary.googleapis.com/v1/mediaItems:search
It gave: error code: 401
"message": "API keys are not supported by this API. Expected OAuth2 access token or other authentication credentials that assert a principal. See https://cloud.google.com/docs/authentication"
I tried using the client ID (xxxxxxx) generated with this request:
https://photoslibrary.googleapis.com/v1/mediaItems:search?client_id=xxxxxxx
Besides "client_id" I tried "key" with no luck.
What is the API REST format for "Expected OAuth2 access token"
Thanks!!

Huawei In App Purchase, implemented everything correctly but still getting the error : authorization format invalid

I am trying to implement Huawei in App Purchase kit to my application.
The request I am sending to the server is here:
request {"purchaseToken":"0000017343ec91821b076fd75f71103a5a85595d2dfd245d708fd6058e676f857792b83622c7fd51x434e.1.100059717","productId":"1007"}
I am following this guide here : https://developer.huawei.com/consumer/en/codelab/HMSInAppPurchase/index.html#0
I am following the same steps but
I am getting an error message from server which says :
result: {"responseCode":"6","subErrCode":"211","responseMessage":"6-211-authorization format invalid"}
Which part I might be doing wrong?
In the error you are getting, it says "authorization format invalid". This means your ignature verification data format is invalid. The possible errors might be :
The token in the request header is not encrypted in Base64 mode.
The character string APPAT is not appended before the access token for authorization. The correct access token is similar to APPAT:thisIsAppAtVaule.
for more information, please check : https://developer.huawei.com/consumer/en/doc/development/HMS-Guides/iap-FAQ
You are facing issue in server side. Kindly go through the given link to know more about In App Purchase server side and client side.
In-App Purchase Article Develioper Forum:
Client side : https://forums.developer.huawei.com/forumPortal/en/topicview?tid=0201255229704010231&fid=0101187876626530001
Server side : https://forums.developer.huawei.com/forumPortal/en/topicview?tid=0201273064244120101&fid=0101187876626530001
In-App Purchase Github Link :
Client side: https://github.com/DTSE-India-Community/HMS-In-App-Purchase-Kit
Server side:
https://github.com/DTSE-India-Community/Huawei-In-App-Purchase-And-Push-Kit-Server_Side-Implementation

redirect_uri_mismatch error when enabling server side access to Google API

I have an android app with a python server. I need the server to have access to the users' emails constantly, so I'm following this guide:
https://developers.google.com/identity/sign-in/android/offline-access
def google_api(auth_token):
# If this request does not have X-Requested-With header, this could be a CSRF
#if not request.headers.get('X-Requested-With'):
#abort(403)
# Set path to the Web application client_secret_*.json file you downloaded from the
# Google API Console: https://console.developers.google.com/apis/credentials
CLIENT_SECRET_FILE = 'secret.json'
# Exchange auth code for access token, refresh token, and ID token
credentials = client.credentials_from_clientsecrets_and_code(
CLIENT_SECRET_FILE,
['https://www.googleapis.com/auth/gmail.readonly', 'profile', 'email'],
auth_token)
print credentials
return credentials.id_token
I get the following error:
FlowExchangeError: redirect_uri_mismatch
Here is the secret.json:
{"web":{"client_id":"REDACTED",
"project_id":"REDACTED",
"auth_uri":"https://accounts.google.com/o/oauth2/auth",
"token_uri":"https://accounts.google.com/o/oauth2/token",
"auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"REDACTED",
"redirect_uris":["http://localhost:8080/"],
"javascript_origins":["http://localhost:8080"]}}
I've also tried using http://my_actual_domain.com:5000/ for the redirect_uris and it still returns the same error.
I don't understand what redirect_uris is supposed to be or mean? It's not mentioned in the guide I link at the top
Redirect uri is something which you give it when you created OAuth Client ID. The one you used in the application should match the one you gave while requesting the Client ID.
Please make sure this configured properly.

Firebase Cloud Messaging - How to validate Tokens?

I am using Firebase Cloud Messaging (FCM) and as per the abreviated code below everytime a new Token is generated on the Customer Device... I send this new TOKEN to my SERVER DB (Cloud) where I save it in order to be able to send future Push Notification from the Server to the Device using the CFM API.
//public class CFMInstanceIDService extends FirebaseInstanceIdService ...
public void onTokenRefresh() {
...
String cfmToken = FirebaseInstanceId.getInstance().getToken();
...
sendRegistrationToServer(customerGuid, cfmToken);
}
By doing this I have on the Server a list of ALL (multiples) Devices where a Customer is logged-in. (Tablet, Phone, iPhone, Android, etc)
Is there any way to verify/validate a Token at any time?
I would like to know/ensure that all the tokens that I have associated to a Customer belong to real Devices. I don't want to send Push Notifications to not-existing Tokens.
Here is an example curl request that shows how to validate a token without actually having to send a message:
curl -H "Content-Type: application/json" -H "Authorization: key=$FCM_API_KEY" https://fcm.googleapis.com/fcm/send -d '{"registration_ids":["$FCMTOKEN"]}'
Example invalid response:
{"multicast_id":7452350602151058088,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}
Example valid response:
{"multicast_id":9133870199216310277,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1502817580237626%f590ddc2f9fd7ecd"}]}
I got this answer from google's firebase support team.
Actually there is a workaround, you can use dry_run = true
This parameter, when set to true, allows developers to test a request without actually sending a message.
firebase docs
if user unsubscribe, you have a response with NotRegistered but real sending won't be performed
You can validate the FCM token by calling the
(GET) https://iid.googleapis.com/iid/info/YOUR_APP_TOKEN_HERE
[Header] => 'Authorization: key=YOUR_KEY'
Simple and easy.
If token is valid then it will return 200 status code with some more details in JSON format or if it's invalid then status code will be 400 with error detail in JSON format.
No such thing exists, the only information you can get from a token is app information and not wether it is valid or not
https://developers.google.com/instance-id/reference/server#get_information_about_app_instances
what you should be doing is watching for the response when you go to send push's out and if keys are not valid anymore the response will tell you what keys should be deleted withNotRegistered
https://firebase.google.com/docs/cloud-messaging/server
There is no way to validate if a token is still valid prior to send the downstream message. What you need to do is to check the response after sending the message and then check if the response contains any error.
For example, if the server returns an 200 + error:NotRegistered http code, it means that an existing registration token may cease to be valid.
In the section "Downstream message error response codes of FGC", you will find documented every possible status response.

What is the `Authorization` part of the http post request of Google's Firebase Downstream message?

I want to try to send a message using google's FCM messaging service and as the document says, the http request should be something like this:
https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{ "data": {
"score": "5x1",
"time": "15:10"
},
"to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..."
}
My problem is that I have not idea what Authorization's value should be and when I delete this header and make the request, I get error 401:Unauthorized.I think this must be some kind of api key or something but I cannot find it in my project. Can anyone help me?
PS: for testing purposes I currently am using this site to send a messsage to my device
According to About Firebase Cloud Messaging Server documentation:
Authentication
To send a message, the app server issues a POST request. For example:
https://fcm.googleapis.com/fcm/send
A message request consists of two parts: the HTTP header and the HTTP
body.
The HTTP header must contain the following headers:
Authorization: key=YOUR_SERVER_KEY
Make sure this is the server key, whose value is available in your Firebase project console under Project Settings > Cloud Messaging. Client keys or any other keys are rejected by FCM.
Content-Type: application/json for JSON; application/x-www-form-urlencoded;charset=UTF-8 for plain text.
If Content-Type is omitted, the format is assumed to be plain text.
UPDATE (2016/11/16)
Perhaps you should consider using the FCM token instead of the server keys as the note inside the following screenshot
UPDATE (2016/12/08)
Firebase has upgraded the server keys to a new version and recommended that you upgrade to the newest version. Please see the screenshot below:
i have also faced this error. The issue is with the server key. Don't use the api key from google-services.json file.
You should use the server api key from your firebase console project, at the cloud messaging tab project keys: https://console.firebase.google.com/project/firebase-probiz/settings/cloudmessaging
This is your Server key which you can observe into console.developers.google.com or Firebase project console under Project Settings > Cloud Messaging. Note the key it's auto created by Google Services. You ought add IP Address inco G.Console to restrict usage.
Plus do remember about Content-Type: application/json, otherwise you will get Error=MissingRegistration.

Categories

Resources