java - Getting authentication token when calling a get url from google app engine -
i trying connect compute engine app app engine using app identity feature of google cloud.
i not sure need extract accesstoken can used authentication. getting invalid access token currently, below code using getting access token:
url url = new url("http://104.197.5.2/myapp/route?tn=12402735"); arraylist < string > scopes = new arraylist < string > (); scopes.add("http://104.197.5.2/myapp/route?tn=12402735"); appidentityservice appidentity = appidentityservicefactory.getappidentityservice(); appidentityservice.getaccesstokenresult accesstoken = appidentity.getaccesstoken(scopes); httpurlconnection connection = (httpurlconnection) url.openconnection(); connection.setdooutput(true); connection.setrequestmethod("get"); connection.addrequestproperty("content-type", "application/json"); connection.addrequestproperty("authorization", "bearer " + accesstoken.getaccesstoken()); connection.setinstancefollowredirects(false); bufferedreader in = new bufferedreader(new inputstreamreader( connection.getinputstream())); string inputline; while ((inputline = in .readline()) != null) resp.getwriter().println(inputline); in .close();
on server code ( hosted on compute engine), how should validate incoming token ie should compare
below excerpt of server log when call reaches it
2015-04-29 07:12:52+0000 [httpchannel,0,98.188.155.163] { 'host':'104.197.53.229', 'content-type':'application/json', 'connection':'keep-alive', 'authorization':'bearer invalidtoken:http://104.197.5.2/myapp/route?tn=12402735:2123' }
Comments
Post a Comment