How to implement a Google Cloud Platform (GCP) Authorization call via HTTP call in postman - http

I want to implement an HTTP call to Google Cloud Platform (GCP) to generate the Authorization token.
Cant find a the correct GCP documentation for the same as well.
Using the reference from below URL, I was able to generate a Authorizaton token from Postman, using postmans Authorization UI and not the HTTP call UI.
https://www.vulongtran.com/how-to-use-postman-with-google-cloud-platform-apis
And the call to GCP API are working using the token generated from above process.
I tried implementing the same call via HTTP POST request, but not getting expected result.
HTTP POST
URL - https://accounts.google.com/o/oauth2/token
Query param-
grant_type:authorization_code
redirect_uri:https://www.getpostman.com/oauth2/callback
Authorization -
Basic Auth
username -
password -
Headers -
scope:https://www.googleapis.com/auth/cloud-platform
redirect_uri:https://www.google.com
And the response that I get is
400 bad request
{ "error": "invalid_request", "error_description": "Missing required parameter: code" }
2nd Try-
Also tried sending the in the request BODY, like below, but the result was same.
{
grant_type:'authorization_code',
redirect_uri:'https://www.getpostman.com/oauth2/callback'
}
Response
{
"error": "invalid_request",
"error_description": "Missing required parameter: code"
}
I saw another page, where 'code' is used in the call. Dont know what language the code on that page is for.
But I am unable to figure out the correct HTTP call to get the token from there as well.
Google OAuth2: Required parameter is missing: grant_type

Related

Using the Logic App HTTP connector, I get "BadGateway. Http request failed as there is an error getting AD OAuth token", when trying to call Graph API

I am trying to make an API call to Microsoft Graph using the Microsoft Logic App HTTP connector. The call fails with the error:
"BadGateway. Http request failed as there is an error getting AD OAuth token: 'Failed to extract error details from response content ''.'.".
I have been trying many things including being able to run the call successfully via Postman. I have decrypted the Postman token with jwt.ms and verified certain values such as:
"aud": "https://graph.microsoft.com",
"iss": "https://sts.windows.net/{{tenantId}}/",
I went through stacks of Google searches, and as for Stack Exchange, these are the closest matching posts that I could find.
Http request failed as there is an error getting AD OAuth token: 'AADSTS50001: The application named https://management.azure.windows.net
In this case the audience paramater was wrong, and in my case I have tried many, and not really sure anymore which is the correct one, even though none of them worked for me when tested.
Azure Logic App HTTP action authorization fails
The post deals with a shared key use case. My current requirement for this project is to use OAuth.
Secure access and data in Azure Logic Apps
I have tried the following for "Authority":
"authority": "https://sts.windows.net/{{tenantId}}/"
"authority": "HTTPS://login.microsoftonline.com/{{tenantId}}/"
"authority": "HTTPS://login.microsoftonline.com/{{tenantId}}/oauth2/v2.0/authorize"
This is the screen that shows the HTTP connector inside the logic app.
This is the same connector at runtime.
This is the raw HTML that the HTTP connector generates.
Hoping someone can spot where I am going wrong.

Firebase FCM returns Unauthorized error with right server key

I am trying to send a push notification from my server using Firebase Cloud Messaging but keep getting the following error:
Client error: POST https://fcm.googleapis.com/v1/projects/my-project/messages:send resulted in a 401 Unauthorized response... Request had invalid authentication credentials. Expected OAuth 2 access
I have looked everywhere online and everywhere made mention of "using the Server Key instead of the API Key". I am doing this and still receiving the error. Nothing online has helped.
Here is my request:
POST https://fcm.googleapis.com/v1/projects/my-project/messages:send
Headers:
Authorization: Bearer <MY SERVER KEY>
Content-Type: application/x-www-form-urlencoded (I have also tried application/json)
Body:
{
"message": {
"topic": "",
"notifications": {
"title": "Some title",
"body": "Some notification body"
}
}
}
Push notifications directly from the Firebase console work just fine, I just can't get this to work server side.
It seems you are using the v1 HTTP API, but you're trying to authorize it using the instructions from the legacy API. They aren't compatible. As the documentation states:
Important: The server key found in the console cannot authorize send
requests made via the HTTP v1 API—it is used only for legacy HTTP and
XMPP requests.
If you want to use the v1 API, must follow the instructions in the v1 API documentation. If you don't want to use the v1 API, then you will have to use the legacy API instead.

Google Dialogflow with API2 webhook: Failed to Parse response

I am trying to connect my bot to an azure function with a db. I entered the azure function URL as the webhook, it recieves the request as a POST http message.
I tried to respond with the following test message (and many more simpler ones):
{
"fulfillmentText":"fulfillmentText",
"fulfillmentMessages": [{"simpleResponse":{"textToSpeech":"text","ssml":"ssml","displayText":"text"}}]
}
and got a response:
Webhook call failed. Error: Failed to parse webhook JSON response:
Expect message object but got:
"笀∀昀甀氀昀椀氀氀洀攀渀琀吀攀砀琀∀㨀∀昀甀氀昀椀氀氀洀攀渀琀吀攀砀琀∀Ⰰ∀昀甀氀昀椀氀氀洀攀渀琀䴀攀猀猀愀最攀猀∀㨀嬀笀∀猀椀洀瀀氀攀刀攀猀瀀漀渀猀攀∀㨀笀∀琀攀砀琀吀漀匀瀀攀攀挀栀∀㨀∀琀攀砀琀∀Ⰰ∀猀猀洀氀∀㨀∀猀猀洀氀∀Ⰰ∀搀椀猀瀀氀愀礀吀攀砀琀∀㨀∀琀攀砀琀∀紀紀崀紀".
Everytime I enter a query in dialogflow I can check the diagnostic info and I see the response clearly in the "Fufillment Response" tab but then there's the above error in the "Response Status" tab.
Help would me much appreciated.
It looks like the content type of the HTTP response may be unclear. Make sure the HTTP response sets the content-type header explicitly to "application/json" or possibly event "application/json; charset=utf-8".
The problem has something to do with the Azure functions URL. For me a workaround was to write the function in visual studio, deploy to localhost, and use ngrok as a tunnel for dialogflow to call the webhook, rather than using the Azure Functions URL.

Vue-Request not sending Authorization Header

I'm using VueJS with vue-request for http requests. I'm trying to subscribe an user to a Mailchimp list but Mailchimp uses BasicAuth, so I'm doing as such:
scope.$http.post('https://us15.api.mailchimp.com/3.0/lists/listid/members',
{...mydata...}, {headers: {Authorization: 'Basic myencodedAPIkey'}})
But I get an error from the API: 401 Unauthorized - Your request did not include an API key.
So I check the Network log on Chrome and the Authorization is on my headers like this: **Access-Control-Request-Headers: authorization** but it should be like **Authorization: myencodedAPIkey**
On the Console the error appears as:
XMLHttpRequest cannot load
https://us15.api.mailchimp.com/3.0/lists/listid/members. Response
to preflight request doesn't pass access control check: No
'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'http://127.0.0.1:8000' is therefore not allowed
access. The response had HTTP status code 401.
When I use Postman it works just fine as the header is correctly sent.
This problem seems to have been solved here with setting the header on every request
https://laracasts.com/discuss/channels/vue/how-to-solve-the-allow-control-allow-cross-in-the-vuejs-header-request-setting?page=2
and here through setting it once
Vue-Request not sending Authorization Header
You are getting CORS error, when you are trying to request from one host to another, and the 'another' part does not allow it to happen. To prevent this error you can use webpack proxy configuration, so this way you do not have cross origin request, but I don't know how you will deal with this in production environment if your api does not allow cross origin requests.
In a project I'm working on, our devServer configuration is as follow
proxy: {
'/api': {
target: 'http://localhost:8080/'
}
},
with this, any request happening on /api/any/url will be redirect to localhost:8080/api/any/url

AWS API Gateway: Add header if response is Unauthorized

I setup an API Gateway in AWS that uses custom authorizers to implement an OAuth2 flow. It works fine. When the user is not authorized they get a 401 Authorized response. That is correct as well, but I would like to add a header that gives the client the endpoint where it can get the token. Something like AuthorizeUrl: url
How can I add this header to my response?
Unfortunately this isn't possible but it's on our backlog. I know it doesn't really make sense when the client gets a 401 but you can't tell them how to authorize.
I don't have an ETA to provide but I'll add a +1 to the feature request.
AWS added this functionality last year.
Refer to this
To do it manually:
Go to 'Response Headers' in API Gateway Console.
Choose Unauthorized (401)
Below 'Response Headers' add AuthorizeUrl and url
Save and deploy API to some stage.
To add this to Cloudformation, refer to this similar answer.
You can also add this to swagger, by adding this snippet(yaml):
x-amazon-apigateway-gateway-responses:
UNAUTHORIZED:
statusCode: 401
responseParameters:
gatewayresponse.header.AuthorizeUrl:"url"
responseTemplates:
application/json: "{\"message\":$context.error.messageString}"
In the API Gateway console go to the "Method Response" interface. You can add HTTP Status 401. In "Response Headers" add your custom "AuthorizeUrl" header. Then in the "Integration Response" interface you can add the value you'd like for that header.

Resources