Microservice returning 405 after going through Zuul gateway - spring

I have the following setup: an authentication service (which uses JWT), a Zuul API gateway and a QR code service. Whenever I test the follow flow locally:
With username and password as body:
localhost:8762/api/auth-service/auth/
I get the Bearer token and use it to access the QR code service:
I use the text in the body and it's a POST request which returns the QR image.
localhost:8762/api/qr-service/qr-codes/
However, when I try this in my staging environment in Portainer I get the following:
{
"timestamp": "2020-12-07T13:16:59.188+00:00",
"status": 405,
"error": "Method Not Allowed",
"message": "",
"path": "/qr-codes/"
}
Somehow, by the time it gets to the QR service, it has changed to a GET request since the output logs show this:
Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported]
Anyone know how to resolve this?

I forgot to add https:// to the staging environment request.

Related

How to configure authentication from Azure data factory to Google Sheets

I am trying to fetch data from Google Sheets via the Azure Data Factory. I have a data flow configured, and a Google Sheets Linked Service configured as well. The Google Sheets Linked Service is using an API key that has no Application Restrictions, and for API restrictions, it is restricted to Google Sheets. When I test the connection, it is successful. However, when I try to fetch a spreadsheet using the data flow in debug mode, I get the error:
at Source 'GoogleSheetsOutput': Failure to read most recent page request: DF-REST_001 - Error response from server: Some({
"error": {
"code": 403,
"message": "The caller does not have permission",
"status": "PERMISSION_DENIED"
}
}), Status code: 403. Please check your request url and body. (url:https://sheets.googleapis.com/v4/spreadsheets/<my_spreadsheet_id>/values/Sheet1!A2:B3,request body: None, request method: GET)
I made a service account, and shared the google sheet with the service account e-mail, and I also shared it with the admin on the account, which is where the API Key was made.
Any ideas what I need to do here? I would also prefer to use oauth / service account instead if possible, so I am happy to go down that route if there is some documentation I can follow.
"error": { "code": 403, "message": "The caller does not have permission", "status": "PERMISSION_DENIED" }
I tried to repro this and got the same error.
To solve this, I changed access of my google sheets from restricted to Anyone with the link
It worked and data is previewed without error.

cannot fetch the CSRF Token from a SpringBooot application (rest API)

Been searching a lot but nothing seems to be working for me,
I'm trying without success to obtain the CSRF Token from a springboot application.
Postman is the chosen APP to try the API Rest.
I am performing a HTTP:POST method invoking a REST API from the application but i am getting this error message:
{
"timestamp": 1956618364439256,
"status": 403,
"error": "Forbidden",
"message": "Invalid CSRF Token 'null' was found on the request parameter '_csrf' or header 'X-CSRF-TOKEN'.",
"path": "/api/rest/taxes"
}
This is my URl:
http://serverser45.swbc.local:9080/api/rest/orders/taxes
Do note that only the HTTP: POST is allowed to be used
I cannot perfom a HTTP: GET method and obtain the CSRF Token within a cookie or something like that. Nothing seems to be working for me.
How can i do that?

Jhipster - POST method converted to GET while enabling both HTTP & HTTPS

Jhipster version 3.2.3 - POST method converted to GET while enabling both HTTP redirect & HTTPS with the 405 error.
"type": "http://www.jhipster.tech/problem/problem-with-message",
"title": "Method Not Allowed",
"status": 405,
"detail": "Request method 'GET' not supported",
"path": "/api/registers",
"message": "error.http.405"
This is normal, when server redirects client through a 302 status code, it's the client's responsibility to handle it and the default behavior is to do a GET on new location which is safe as you may not want to post your data to an unknown URL, so it's up to the angular developer to code a different behavior in the angular service and probably using HttpClient interceptor

Issue while generating access token using OAuth2 Service Accounts

We're having an issue in generating access token using OAuth2 Service Account for Google Apps marketplace users. The token generated here would be used in accessing Google APIs(Contacts, Calendar, Mail, Admin SDK APIs) and thus all the Google Integrations within our Services are failing. This has started failing abruptly from March 9th 8AM PST. Can you please consider this as high priority and let us know the reason for the issue or if we have missed something here. We are getting API response as
{ "error": "invalid_request" }
Please find the below sample request with all the headers and params for 2 sample requests for "https://www.googleapis.com/oauth2/v4/token"(as in documentation) and "https://accounts.google.com/o/oauth2/token" endpoints. Both result in a error message with responses { "error": "internal_failure", "error_description": "Invalid Value"} and { "error": "invalid_request" } respectively.
P.S: The service email address,private key files used for generating the below signature in the sample requests works if we use respective Google Client libraries. But we are making use of Google's REST APIs. We've created a sample application in Google APIs console for testing with new service account details and this results in the same exception.
URL:
https://www.googleapis.com/oauth2/v4/token
Headers:
Content-Type:application/x-www-form-urlencoded
BODY:
grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&assertion=eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiJodHRwczovL3d3dy5nb29nbGVhcGlzLmNvbS9vYXV0aDIvdjQvdG9rZW4iLCJzdWIi
OiJqYWdzQHNvbHV0aW9udGVzdC5jb20iLCJzY29wZSI6Imh0dHBzOi8vbWFpbC5nb29nbGUuY29t
LyIsImlzcyI6IjQ2OTU3MTY1OTAxNUBkZXZlbG9wZXIuZ3NlcnZpY2VhY2NvdW50LmNvbSIsImV4
cCI6MTQ1NzU5NTkwMCwiaWF0IjoxNDU3NTkyMzAwfQ==.VrsqS0nYSUVZn_SwMi7UJEYLDqRcWLzPrF9o6av-t1IYZbRkTybEdcnwWeUfnYXl_F88gFTllmRg
LSTBahM5gqpZrEAaWrRiDEVTo6rcN3hWm7MHcmZbwgdJB8B0ObV0Ivp5aTdLC5HcqsOumJvYpDCF
SyGU8StSg9pDujERzOo=
Response:
code:400
{
"error": "internal_failure",
"error_description": "Invalid Value"
}
URL:
https://accounts.google.com/o/oauth2/token
Headers:
Content-Type:application/x-www-form-urlencoded
BODY:
grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&assertion=eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiJodHRwczovL3d3dy5nb29nbGVhcGlzLmNvbS9vYXV0aDIvdjQvdG9rZW4iLCJzdWIi
OiJqYWdzQHNvbHV0aW9udGVzdC5jb20iLCJzY29wZSI6Imh0dHBzOi8vbWFpbC5nb29nbGUuY29t
LyIsImlzcyI6IjQ2OTU3MTY1OTAxNUBkZXZlbG9wZXIuZ3NlcnZpY2VhY2NvdW50LmNvbSIsImV4
cCI6MTQ1NzU5NTkwMCwiaWF0IjoxNDU3NTkyMzAwfQ==.VrsqS0nYSUVZn_SwMi7UJEYLDqRcWLzPrF9o6av-t1IYZbRkTybEdcnwWeUfnYXl_F88gFTllmRg
LSTBahM5gqpZrEAaWrRiDEVTo6rcN3hWm7MHcmZbwgdJB8B0ObV0Ivp5aTdLC5HcqsOumJvYpDCF
SyGU8StSg9pDujERzOo=
Response:
code:400
{
"error": "invalid_request"
}
EDIT:Sample request as in the documentation. This code was working for us for the past 2 years and suddenly it stopped working yesterday.
POST /oauth2/v4/token HTTP/1.1
Host: www.googleapis.com
Content-Type: application/x-www-form-urlencoded
grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&assertion=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiI3NjEzMjY3OTgwNjktcjVtbGpsbG4xcmQ0bHJiaGc3NWVmZ2lncDM2bTc4ajVAZGV2ZWxvcGVyLmdzZXJ2aWNlYWNjb3VudC5jb20iLCJzY29wZSI6Imh0dHBzOi8vd3d3Lmdvb2dsZWFwaXMuY29tL2F1dGgvcHJlZGljdGlvbiIsImF1ZCI6Imh0dHBzOi8vYWNjb3VudHMuZ29vZ2xlLmNvbS9vL29hdXRoMi90b2tlbiIsImV4cCI6MTMyODU3MzM4MSwiaWF0IjoxMzI4NTY5NzgxfQ.ixOUGehweEVX_UKXv5BbbwVEdcz6AYS-6uQV6fGorGKrHf3LIJnyREw9evE-gs2bmMaQI5_UbabvI4k-mQE4kBqtmSpTzxYBL1TCd7Kv5nTZoUC1CmwmWCFqT9RE6D7XSgPUh_jF1qskLa2w0rxMSjwruNKbysgRNctZPln7cqQ
It worked after changing the sun.misc.BASE64Encoder encoding part in my code for generating jwt token.
byte[] encode = BASE64Encoder.encode(data).replaceAll("\n", "").getBytes();
(or)
Change your BASE64Encoder encoding part while generating jwt token from sun.misc.BASE64Encoder to org.apache.commons.codec.binary.Base64 as
Base64 encoder = new Base64();
byte[] encode = encoder.encodeBase64(data);
Add comments if you anyone need any clarifications.
This solution was provided by Google.

Google Analytics dailyUploads not working with using google-api-ruby-client

I am using the google-api-ruby-client v0.7.1, ruby 2.1.
When I upload Custom Data Sources through Google Analytics API v3 with Google Analytics API v3 > analytics.management.dailyUploads.upload :
Request
POST https: //www.googleapis.com/analytics/v3/management/accounts/**********************/webproperties/**********************/customDataSources/**********************/dailyUploads/2014-04-06/uploads?appendNumber=1&type=cost&key={YOUR_API_KEY}
Authorization: Bearer **************************
X-JavaScript-User-Agent: Google APIs Explorer
Response
400 Bad Request
{
"error": {
"errors": [{"domain": "global",
"reason": "badRequest",
"message": "Upload request url should start with https://www.googleapis.com/upload/analytics/..."}],
"code": 400,
"message": "Upload request url should start with https://www.googleapis.com/upload/analytics/..."
}
}
That response I get when call this method of api from gem google-api-ruby-client too.
But the documentation states:
HTTP request
POST https: //www.googleapis.com/upload/analytics/v3/management/accounts...
But in Google APIs Explorer and gem request is https: //www.googleapis.com/analytics/v3... , not https://www.googleapis.com/upload/analytics/v3... .
Anyone encountered this problem and how to fix it?
You need to change
user and code value
In authorize method.
You'll get,
user_ID from client_secret.json
and
run the URL, you get in the console under 'Open the following URL in the browser' for code value

Resources