I'm trying to implement push notification on my site with AWS SNS https protocol but am having trouble figuring out how to receive the token returned from the subscribe method. What is an example of a handler that processes the confirm sub POST request from SNS? I'm currently proving the browser's endpoint as the param to subscribe, is that the right endpoint? I've gone through the SNS Doc multiple times but can't seem to wrap my head around it.
this is the response i'm getting from the subscribe method:
{ ResponseMetadata: {…}, SubscriptionArn: "pending confirmation" }
Your code should read the HTTP headers of the HTTP POST requests that Amazon SNS sends to your endpoint. Please see [Source] for the HTTP header example.
Read the value for SubscribeURL and visit that URL. To confirm the subscription and start receiving notifications at the endpoint, you must visit the SubscribeURL by HTTP Get request.
if (message['Type'] === 'SubscriptionConfirmation') {
https.get(message['SubscribeURL'], function (res) {
// You have confirmed your endpoint subscription
});
}
Source: https://docs.aws.amazon.com/sns/latest/dg/SendMessageToHttp.html#SendMessageToHttp.confirm
Related
I have an API Setup in API Gateway with 2 routes currently: Login and Register which are both attached to AWS Lambdas to perform operations on a DynamoDB Table.
When I perform a Post Request on Postman, I can see my custom response Body in the body of the response i get back. I'm using this to get back a jwt token hence the need for custom body.
However, in my React Native code:
I get a correct status code in the response of 200 but if i log out response.body i get "undefined"...
Edit: There is also no sign of the jwt token under any other name in the response when thats logged out as a whole too.
any help would be appreciated! Thanks
EDIT: EXTRA PHOTOS
Had to use
await for response.text()
to get the desired data out of the response, not just a single await on the whole response. Solved by #ThibaultCapelli
I'm trying to use this api in my pet project, but when I test it on docs page - POST request "create User" it always sends back 401: Unauthorized
The question is: how I can create a new user?
I think this free-to-use api is very popular:
api link:
https://nestjs-boilerplate-test.herokuapp.com/docs/#/
It is happening because you are not authorized to use the api.
You need a TOKEN or an API KEY to be able to make request to that API server.
I need help with axios, I don't know why is sending two request here an image of chrome network in one post call
I'm using react, and when I send request the function only trigger once (I debugged and put console.logs and get one response) but in chrome network I got two request, with different headers and type.
One have Authorization token, and the other don't have tokensuccess request and
wrong request this is in one call and I don't know what is happening.
Thanks for your time!
Is it an OPTION request?. OPTION requests are used to check if your client has permission to make the desired request to the API.
The HTTP OPTIONS method requests permitted communication options for a given URL or server. A client can specify a URL with this method, or an asterisk (*) to refer to the entire server.
I need to fetch some data from ApiGateway endpoint and then based on response store this data in database.
I created simple Lambda function that just fetch data from ApiGateway endpoint and print it in console. My first Lambda function did not have any VPC configuration and fetch operation worked like a charm.
const fetch = require('node-fetch');
exports.handler = async () => {
const data = await fetch("https://<<ag-api-key>>.execute-api.us-east-1.amazonaws.com/v1/data");
const response = await data.json();
console.log(data, response);
}
As I need to store data received from endpoint into database which run under VPC I decided to put Lambda in same VPC(this vpc has configured Internet Gateways and other stuff to have access to internet).
As a result fetch operation start to fail with 403 response code and {"message":"Forbidden"} response body.
Api Gateway resource does not have any custom domain configuration and maintained by other team so I do not have direct access to its configuration
May be anyone can suggest how I can fix this
Security Groups, check if port 443 is open
Check your CORS Setting on API Gateway.
Try Hitting the API Gateway with Postman/Fiddler, or any other testing tool to make sure your API Gateway is online and you can get the response you want.
If you are using a Private API-Gateway (Sounds like you are using public looking at the URL) you will need some header data and different URL. I can guide you through it if needed. I would avoid private API gateway if I were you.
Let me know if any of that helps. I have ran into that issue many times in different situations.
I am using the OAuth server flow for Google.
It starts with the user clicking a link that runs javascript to open a popup with the following request in the URI which is all working great:
var endpoint = "https://accounts.google.com/o/oauth2/auth";
endpoint = endpoint + "?scope="+encodeURIComponent(googlecalendar.SCOPES);
endpoint = endpoint + "&redirect_uri="+encodeURIComponent("https://myserver/google/");
endpoint = endpoint + "&response_type=code";
endpoint = endpoint + "&access_type=offline";
endpoint = endpoint + "&approval_prompt=force";
endpoint = endpoint + "&client_id="+encodeURIComponent(googlecalendar.CLIENT_ID);
endpoint = endpoint + "&state="+encodeURIComponent(googlecalendar.USER_ID);
On the server side, I get the state which contains the user_id for my DB and the authorisation code.
Now I want to exchange the authorisation code for access token (and renew token). This will be a HTTP request with a redirect URI, no state parameter is included.
The problem is that when I get those, I will need to store them against a user in my DB, but I don't have any way to check which user the callback is for.
The best I was able to come up with is using the token to query the google user's identity it belongs to but this still won't help me to find the user in the DB.
Can anyone help me with this flow? There must be some way to do. I don't want to use client libraries because later when I need to create watchers the PHP client library does not include this for the calendar API.
Short Answer
Despite the presence of a redirect parameter, the access token will generate a standard 200 response, not a 301 redirect. Depending on how you issue and handle the request/response, you can preserve your state.
More Detailed Answer
According to section 4.1.4 of the OAuth 2.0 spec document (RFC 6749), the response to an Access Token Request should be an "HTTP/1.1 200 OK".
In other words, the server will not perform a redirect, meaning you can issue a request and process the response in the same scope (either in the client or server, whatever your situation), so your database user ID need only be in local memory.
This is different from the Authorization Request, which is supposed to result in an "HTTP/1.1 302 Found" (redirect). See section 4.1.2.
So why is the redirect_uri parameter required?
According to section 4.1.3, the server must:
ensure that the "redirect_uri" parameter is present if the "redirect_uri" parameter was included in the initial authorization request as described in Section 4.1.1, and if included ensure that their values are identical.
In other words, the redirect_uri acts as a sort of secret or password which the server must use to verify the access token request. If the client fails to provide a redirect_uri parameter, or the parameter value is different from the original request, then the server must reject the access token request.