Access Task Queue from GCE via cUrl - google-compute-engine

I'am trying to assess my GAE Task Queue from an GCE instant in the same project.
I have started the instant with the correct scoop and billing is enabled:
"serviceAccounts": [
{
"email": "949416733789-compute#developer.gserviceaccount.com",
"scopes": [
"https://www.googleapis.com/auth/datastore",
"https://www.googleapis.com/auth/devstorage.full_control",
"https://www.googleapis.com/auth/taskqueue"
]
}
]
And i can generate an access token via this curl command:
curl "http://metadata/computeMetadata/v1/instance/service-accounts/default/token" -H "Metadata-Flavor: Google"
But when I try to curl to get the tasks using this curl I get an 403:
curl "https://www.googleapis.com/taskqueue/v1beta2/projects/propane-****/taskqueues/default/tasks" -H "Authorization":"Bearer ya29.lABIrcEaJi0ItloNb62Lg_***************"
Generates this output
"error": {
"errors":
[
{
"domain": "global",
"reason": "forbidden",
"message": "you are not allowed to make this api call"
}
],
"code": 403,
"message": "you are not allowed to make this api call"

The problem was that i was using the default taskqueue, apparently that dose not work.
Changes the taskqueue name to demo, and it all works.

Related

google drive API verified domain not working with changes watch

According to https://developers.google.com/drive/api/v3/reference/changes/watch,
you need an https address to make it works if you need to watch over a change of resources.
I've configured the domain successfully by going to Google Cloud Console > Domain Verification > Add Domain.
Then I use Postman to make a call to test it:
https://www.googleapis.com/drive/v3/changes/watch?pageToken=nextPageToken
{
// "kind": "api#channel",
"id": "1234231",
"expiration": 1656402233000,
"type": "webhook",
"payload": true,
"address": "https://mrnoc.blogspot.com",
"params": {
"pageToken": "nextPageToken"
}
}
However, it failed and generated this error message:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "push.webhookUrlUnauthorized",
"message": "Unauthorized WebHook callback channel: https://mrnoc.blogspot.com"
}
],
"code": 401,
"message": "Unauthorized WebHook callback channel: https://mrnoc.blogspot.com"
}
}
I have no idea how it doesn't work, I've tried to look around but it a dead end as it seems like I've configured everything properly.
Please help if you know what might stop it from working.
Thank you

Google Drive API - Files stored in a GSuite Shared Drive (only) get a 404 error

My application has scopes drive.file, drive.readonly and drive.metadata.readonly.
Using https://github.com/googleapis/google-api-php-client v2.2.2
It works fine fetching files when authenticated as a Google Drive user, but only when those files are owned by another user (or the same user).
Files stored on a Shared Drive (G Suite Business feature) and shared with the user result in a 404 error:
"error": {
"errors": [
{
"domain": "global",
"reason": "notFound",
"message": "File not found: 1gasqkgWcabla8sksT5FUtZGzlfIwGbc_aI4g2gl9bla.",
"locationType": "parameter",
"location": "fileId"
}
],
"code": 404,
"message": "File not found: 1gasqkgWcabla8sksT5FUtZGzlfIwGbc_aI4g2gl9bla."
}
I have verified that the file in question is indeed readable by that user via Drive/Docs etc.
I have been into the API Console and checked the "Shared Drives support" under Drive UI integration - this made no difference.
Neither did it help to add the wider 'drive' scope.
After testing I found the same issue.
When I tried to get a file from a Shared Drive with the following HTTP Request
GET /drive/v3/files/<ID-file> HTTP/1.1
Host: www.googleapis.com
Content-length: 0
Authorization: Bearer <access Token>
I got the same error as you did:
{
"error": {
"code": 404,
"message": "File not found: 1DIM-vS4058e0X5eutNmOqSr3z0rA1Nqh.",
"errors": [
{
"locationType": "parameter",
"domain": "global",
"message": "File not found: 1DIM-vS4058e0X5eutNmOqSr3z0rA1Nqh.",
"reason": "notFound",
"location": "fileId"
}
]
}
}
But upon reading the documentation it's clear that you need to include the supportsAllDrives paramater to the HTTP request.
So now adding supportsAllDrives=true my request is the following:
GET /drive/v3/files/<File ID>?supportsAllDrives=true HTTP/1.1
Host: www.googleapis.com
Content-length: 0
Authorization: Bearer <access Token>>
And then I got to retrieve the file in the response:
{
"mimeType": "image/jpeg",
"kind": "drive#file",
"name": "file.jpg",
"driveId": "<Drive Id>",
"teamDriveId": "<Team Drive ID>",
"id": "<File ID>"
}

FeathersJs authenticate returning NotAuthenticated: Invalid login

I am following the official guide of feathers js authenticate https://docs.feathersjs.com/guides/chat/authentication.html but it seems like even after following the guide step by step I am unable to generate tokens. Here is the body of my request to http://localhost:3030/authentication
{
"strategy": "local",
"email": "abc#foo.com",
"password": "12345678"
}
and here is the response I got
{
"name": "NotAuthenticated",
"message": "Invalid login",
"code": 401,
"className": "not-authenticated",
"data": {
"message": "Invalid login"
},
"errors": {}
}
I am using Sequilize with MySQL and I have tested my services using postman and they all are working fine (get/post data from the database)
I figured it out. It was not working because the verify method in authentication-local was verifying the password assuming that the password was hashed using their hashing utility method.
Starting the server with debug mode on have helped to figure out this issue

Google Compute Engine: Unable to query API from gcloud terminal

I have many vm's created inside my project, from which I want to query api's from gcloud terminal.
I am getting 401 - "Login Required" error while I am trying to query any API, even though I am authorized/logged-in to gcloud terminal.
C:\..\Google\Cloud SDK>gcloud config list
[core]
account = remis.haroon#*****.com
disable_usage_reporting = True
project = <proj-id>
[meta]
active_config = default
C:\..\Google\Cloud SDK>curl https://www.googleapis.com/compute/v1/projects/<proj-id>/aggregated/disks
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Login Required"
}
}
You need to carry authorization token when using the REST API:
gcloud auth login
TOKEN=$(gcloud auth print-access-token)
curl -H "Authorization: Bearer $TOKEN" <url>
As the error mentions:
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
Since you are doing an HTTP API call to google apis, you need to put the OAuth access token in the header of your HTTP request.
GET compute/v1/projects/<proj-id>/aggregated/disks HTTP/1.1
Host: www.googleapis.com
Authorization: Bearer XXXXXXXXXXXXXXXXXXX
There are several ways to obtain the OAuth access token. One easy way is through google's oauthplayground.
Choose your required API scopes
Click on Authorize APIs button
Click on "Exchange authorization code for tokens"
You will have your access token to use it in the curl request header

Parse error on Google GeoLocate API sample JSON

Has Google changed their GeoLocation api and not updated the documentation?
I have been following their example code verbatim off of the following page
https://developers.google.com/maps/documentation/geolocation/intro
I pasted the sample request into a file on my system called ex.json. I double checked that my Google Maps Geolocation API is set to on and executed the following curl command
curl -d ex.json -H "Content-Type: application/json" -i "https://www.googleapis.com/geolocation/v1/geolocate?key=[My key, yes I pasted my actual key in]"
I received the following response
{
"error": {
"errors": [
{
"domain": "global",
"reason": "parseError",
"message": "Parse Error"
}
],
"code": 400,
"message": "Parse Error"
}
}
Which according to the documentation means that there is something wrong with the example json they provided. Just for completeness the sample json looks like
{
"homeMobileCountryCode": 310,
"homeMobileNetworkCode": 260,
"radioType": "gsm",
"carrier": "T-Mobile",
"cellTowers": [
{
"cellId": 39627456,
"locationAreaCode": 40495,
"mobileCountryCode": 310,
"mobileNetworkCode": 260,
"age": 0,
"signalStrength": -95
}
],
"wifiAccessPoints": [
{
"macAddress": "01:23:45:67:89:AB",
"signalStrength": 8,
"age": 0,
"signalToNoiseRatio": -65,
"channel": 8
},
{
"macAddress": "01:23:45:67:89:AC",
"signalStrength": 4,
"age": 0
}
]
}
JsonLint verified that it is proper Json, and the documentation says that all fields are optional. What am I missing, was some required field added after the documentation was written?
Curl needs "-X POST" as extra parameter. Works like this:
curl 'https://www.googleapis.com/geolocation/v1/geolocate?key=YOURKEY' -X POST -H "Content-Type: application/json" -d #yourjsonfile.json
Found the solution, it was a silly mistake :-
my file name was "sampledata.json" i changed this to "#sampledata.json"
I tried with three different curl commands. I got response.