I am trying to upload images to buckets in Google Cloud Storage using the JSON API using a Javascript example: Api Javascript Sample
I can upload photos, but he asks me to log in to my google account.
There is an authorization button in the sample, which, as I understand it, manages OAuth credentials.
function checkAuth() { gapi.auth.authorize({ client_id: clientId, scope: scopes, immediate: true }, handleAuthResult); }
The problem is this:
I want to authenticate without a pop-up screen, which means without logging in to Google. Since my client does not know the email address or password, I want it to be automatic.
How can i achieve this?
Thanks!
----------------------------- UPDATE ----------------- ---
So, after Brandon's answer, I did the following:
I created my political document and signed it as follows:
var http = require('http'); var fs = require('fs'); var crypto = require('crypto'); var express = require('express'); var app = express(); var p12ToPem = require("./node_modules/p12-to-pem/p12ToPem.js"); var p12File = fs.readFileSync("./KEY.p12"); var pemKey = p12ToPem(p12File, "notasecret"); var policyJson={"expiration": "2050-06-16T11:11:11Z", "conditions": [["starts-with", "$key", "" ], {"acl": "bucket-owner-read" }, {"bucket": "my-bucket'name"}, {"success_action_redirect":"http://www.example.com/success_notification.html" }, ["eq", "$Content-Type", "image/jpeg" ], ["content-length-range", 0, 1000000] ] }; var policyJson64 = new Buffer(''+policyJson).toString('base64'); var sign = crypto.createSign('RSA-SHA256'); sign.update(policyJson64); var sig = sign.sign(pemKey, 'base64') console.log("policyJson64:"+policyJson64); console.log("sig:"+sig);
And my message form is as follows:
<form action="http://my-bucket-name.storage.googleapis.com" method="post" enctype="multipart/form-data"> <input type="text" name="key" value=""> <input type="hidden" name="bucket" value="my-bucket-name"> <input type="hidden" name="Content-Type" value="image/jpeg"> <input type="hidden" name="GoogleAccessId" value=" 884257827820-so77htet9tafrcjjp83m7api9lh12qsn@developer.gservice account.com"> <input type="hidden" name="acl" value="bucket-owner-read"> <input type="hidden" name="success_action_redirect" value="http://www.example.com/success_notification.html"> <input type="hidden" name="policy" value="DONT KNOW WHAT TO PUT HERE"> <input type="hidden" name="signature" value="NEITHER HERE"> <input name="file" type="file"> <input type="submit" value="Upload">
No matter what combinations received in javascrypt, I canβt understand what is included in the policy and what is included in the signature, and YES! I read the API, but it is not clear what happens in these two inputs. I tried to include PolicyJson64 and sig in the policy. And I tried to sign the sig value and pemKey too.
I get this error:
<Error> <Code>SignatureDoesNotMatch</Code> <Message> The request signature we calculated does not match the signature you provided. Check your Google secret key and signing method. </Message> <StringToSign> a/vDHoeJ1jIZibjgLnS/ZfMftmyz8IaISJiVt1b2wDNbDjnSR+0HyEDW9/Lew7ufMjU9xdtX/Uld06IJbeYz3OWGHnH4osJNS614RoDVd7lq2qft+bSCqYPtkagJiUWs9SNOPvuQzISthqloPQOwJ1LLXHYmV52c73OpexAnSR4= </StringToSign> </Error> Lew7ufMjU9xdtX / Uld06IJbeYz3OWGHnH4osJNS614RoDVd7lq2qft + bSCqYPtkagJiUWs9SNOPvuQzISthqloPQOwJ1LLXHYmV52c73OpexAnSR4 = <Error> <Code>SignatureDoesNotMatch</Code> <Message> The request signature we calculated does not match the signature you provided. Check your Google secret key and signing method. </Message> <StringToSign> a/vDHoeJ1jIZibjgLnS/ZfMftmyz8IaISJiVt1b2wDNbDjnSR+0HyEDW9/Lew7ufMjU9xdtX/Uld06IJbeYz3OWGHnH4osJNS614RoDVd7lq2qft+bSCqYPtkagJiUWs9SNOPvuQzISthqloPQOwJ1LLXHYmV52c73OpexAnSR4= </StringToSign> </Error>
What should I do?
------ UPDATE ------
Please do not copy the folder documentation, which does not help. Bounty Added