OAuth Callback in the Glass Quick Starter Java App - java

Got my Glass last week. Working on running the Java version of the Quick Starter Glassware demo. I am having trouble with the OAuth callback. Do I need set this up myself? Or is there source included in the sample somewhere? Please help!
Clarification: I have set up my own project with the Java Quick Starter app's code, deployed it in EC2 and have set up the Client-ID and Client-secret in the Google APIs Console. I set the Redirect URI as http://<my server>/<my-app>/oauth2callback. When I visit the app in the browser, I get a 404 error that /oauth2callback is not found. I also tried setting the Redirect URI to just my app's root, i.e. http://<my server>/<my app>. Strangely, I still get the same error that /oauth2callback is not found.
Additional questions: Can you please clarify what the callback URL needs to be set to? Is the handler code already included in the quick-start-demo app or do I need to provide that code?

I think the problem is that you're not using a URL that actually maps to your server and servlet container. Try hitting the URLs directly from a browser and make sure they show up in your server and servlet container logs.
The callback url needs to be set to the oauth2callback servlet, relative to the path that leads to the server and servlet container. I don't know how you've set these up, so I can only guess, but it sounds like the <my app> portion isn't correct.
The handler code is included as part of the webapp. See the web.xml file to see the path mapping and the servlet object that it maps to. In this case, around line 53, oauth2callback is mapped to the com.google.glassware.AuthServlet class.
Update: See also the answer posted at Java Google glass starter project mapping in AWS EC2

Related

Angular 2, cannot read from localhost

I have followed the Angular 2 tour of Heroes tutorial to the T, and I have successfully implemented the displaying of the heroes (I renamed them to employees).
However, the tutorial uses an in memory mock web server. When I try to pass a localhost url (that displays json) from my spring-boot backend, I get this error:
XMLHttpRequest cannot load http://localhost:8080/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access
However, if I decide to use an online web api, for example :
https://jsonplaceholder.typicode.com/users
Then it works perfectly fine.
Any help would be greatly appreciated.
There was indeed duplicate questions (I posted since none of them seemed to have solved my problem). Turns out one of them did put me on the right track. I just had to put
#CrossOrigin(origin ="http://localhost:3000")
on top of my controller class in Spring. This enabled CORS in spring.
For more details, look here
https://spring.io/blog/2015/06/08/cors-support-in-spring-framework

using Websockets with Tomcat

I'm trying to make this example work
But when I deploy the war file to Tomcat and start it, the connection cannot be established.
In browser console I see that the client tries to connect to http://localhost:8080/Spring4WebSocket/add/info and receives 404, though the specified in start.jsp URL for connecting is /Spring4WebSocket/add (without that "/info" part in the end).
Why is this strange "/info" suffix added to the url and what can I do to change this and make this example work fine?
This solution wasn't helpful for me:
SockJs - 'info' path not found
The /info URL is called by SockJS (see docs):
...before the client starts the session. It's used to check server capabilities (websocket support, cookies requirement) and to get the value of "origin" setting (currently not used).
I looked at the example you are following and I don't see anything wrong with it. It follows closely a Spring guide: Using WebSocket to build an interactive web application so it should work.
Just one question though. Did you exactly follow the instructions or downloaded the zip file from the page or did you create it on your own? You get that error on the first SockJS request here:
var socket = new SockJS('/Spring4WebSocket/add');
Is your application also called Spring4WebSocket or something else? If it's called something else then use that instead:
var socket = new SockJS('/YourAppNameGoesHere/add');

Google OAUTH: The redirect URI in the request did not match a registered redirect URI

I am trying to make an upload to YouTube from my Java based web app, I spent a few days to understand what and where is the problem and I cannot get it, for now I am pulling my hair out off my head.
I registered my web app in Google Console, so I got a pair of Client ID and Secret and a possibility to download JSON type file with my config.
So here is the config:
{
"web":{
"auth_uri":"https://accounts.google.com/o/oauth2/auth",
"client_secret":"***",
"token_uri":"https://accounts.google.com/o/oauth2/token",
"client_email":"***",
"redirect_uris":["http://localhost:8080/WEBAPP/youtube-callback.html","http://www.WEBAPP.md/youtube-callback.html"],
"client_x509_cert_url":"***",
"client_id":"***",
"auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs",
"javascript_origins":["http://www.WEBAPP.md/"]
}
}
How is possible that I am getting the default URL from Google?
The redirect URI in the request: http://localhost:8080/Callback did not match a registered redirect URI
It always gives me the default http://localhost:8080/Callback URL instead of mine.
And IDE console shows me that:
Please open the following address in your browser:
https://accounts.google.com/o/oauth2/auth?client_id=***&redirect_uri=http://localhost:8080/Callback&response_type=code&scope=https://www.googleapis.com/auth/youtube.upload
Attempting to open that address in the default browser now...
I am using the last version of dependencies:
google-api-services-youtube v3-rev99-1.17.0-rc and google-api-services-youtubeAnalytics v1-rev35-1.17.0-rc
I think I encountered the same problem as you. I addressed this problem with the following steps:
1) Go to Google Developers Console
2) Set JavaScript origins:
http://localhost
3) Set Redirect URIs:
http://localhost:8080
http://localhost:8080/Callback
When your browser redirects the user to Google's oAuth page, are you passing as a parameter the redirect URI you want Google's server to return to with the token response? Setting a redirect URI in the console is not a way of telling Google where to go when a login attempt comes in, but rather it's a way of telling Google what the allowed redirect URIs are (so if someone else writes a web app with your client ID but a different redirect URI it will be disallowed); your web app should, when someone clicks the "login" button, send the browser to:
https://accounts.google.com/o/oauth2/auth?client_id=XXXXX&redirect_uri=http://localhost:8080/WEBAPP/youtube-callback.html&response_type=code&scope=https://www.googleapis.com/auth/youtube.upload
(the callback URI passed as a parameter must be url-encoded, btw).
When Google's server gets authorization from the user, then, it'll redirect the browser to whatever you sent in as the redirect_uri. It'll include in that request the token as a parameter, so your callback page can then validate the token, get an access token, and move on to the other parts of your app.
If you visit:
http://code.google.com/p/google-api-java-client/wiki/OAuth2#Authorization_Code_Flow
You can see better samples of the java client there, demonstrating that you have to override the getRedirectUri method to specify your callback path so the default isn't used.
The redirect URIs are in the client_secrets.json file for multiple reasons ... one big one is so that the oAuth flow can verify that the redirect your app specifies matches what your app allows.
If you visit https://developers.google.com/api-client-library/java/apis/youtube/v3 You can generate a sample application for yourself that's based directly off your app in the console, in which (again) the getRedirectUri method is overwritten to use your specific callbacks.
I was able to get mine working using the following Client Credentials:
Authorized JavaScript origins
http://localhost
Authorized redirect URIs
http://localhost:8090/oauth2callback
Note: I used port 8090 instead of 8080, but that doesn't matter as long as your python script uses the same port as your client_secret.json file.
Reference: Python Quickstart
You need to go into the developer console and set
http://localhost:8080/WEBAPP/youtube-callback.html
as your callback URL.
This video is slightly outdated, as it shows the older Developer Console instead of the new one, however, the concepts should still apply. You need to find your project in the developer console and register a callback URL.
I thought I had this configured but it turns out I set the URL in the wrong place. I followed the URL provided in the Google error page and added my URL here. Stupid mistake from my part, but easily done. Hope this helps

Beginner-jJava- Amazon Elastic Beanstalk- Unable to correctly specify health check url-also,what is base url

I have created a sample web application in Java. It has no errors, and I was able to create a WAR archive successfully. I also tested this successfully in local Tomcat 7 server.
Now, this sample web app has 2 servlets- "home" and "runsinglecrawljob". The name of the war archive is "sparkcrawler0.12.war".
So, in local Tomcat, I access the web app at
http://localhost:8080/SparkCrawler0.12/runsinglecrawljob
And the other servlet is
http://localhost:8080/SparkCrawler0.12/home
Now, when I created an Elastic Beanstalk environment, I specified health check url="/home"
But I am getting error that health check url is not responsive, and because of this the application is not running in Elastic Beanstalk- it is showing a 503 error- as per Google Chrome this is the exact message --
"HTTP Error 503 (Service Unavailable): The server is currently unable to handle the request. This code indicates this is a temporary condition, and the server will be up again after a delay."
Now, what is the correct value of health check URL?
Also, if my URL is
http://spark.elasticbeanstalk.com
as defined in Elastic Beanstalk, then do I access the web app at
http://spark.elasticbeanstalk.com/SparkCrawler0.12/runsinglecrawljob
Or do I access the web app at
http://spark.elasticbeanstalk.com/runsinglecrawljob ?
I don't know if this is related or not, but I have a very similar issue but with a PHP codeigniter application.
I uploaded the application, and 'index.php' is the normal starting point of the application.
I also have a simple "phpinfo.php" that sits parallel to the index.php.
So, the URL is myApp.elasticbeanstalk.com which hits index.php and it is fine.
However, for my health check, I set it to /phpinfo.php because I want myApp.elasticbeanstalk.com/phpinfo.php to be used as the health check.
If I do this, the health check always fails, and so my application does not run and I see the glaring red box of doom.
This has been driving me crazy.
(Why do I want to do this? -- it's because I wanted to add an .htaccess file to the application root that requires a password for everything except the phpinfo.php file, and I tested this locally and it works. I did not add the .htaccess file yet -- I just wanted to see if I could point the health check to something besides "/" and have it work.
UPDATE --
I sorted out my issue. It turns out that when I launch one of these elastic beanstalk environments, I have to set up the healthcheck url right then and there to be /phpinfo.php and then upload my application. When I was fussing with this earlier, I would try to edit the configuration later to change the health check url and that never worked and the instance would never come alive again.

question on regular servlets within GWT (working in dev mode ,not working in deployment in tomcat)

i am having trouble with my web application developed in GWT. the application allows users to upload and download using an upload servlet and a download servlet, the upload servlet was created using the gwtUpload library. the download servlet is using regular HTTPServlet.
when i run the application within eclipse the download servlet works fine, when i deploy it to tomcat, when a user selects to upload a file, the file does not download, when a user selects a link to download a file, this error is returned
type Status report
message /testhibernategilead/downloadServlet
description The requested resource (/testhibernategilead/downloadServlet) is not available.
can anyone explain why this is
The requested resource (/testhibernategilead/downloadServlet) is not available.
This is the same as a 404 Page Not Found. In other words, the URL is wrong, or the requested resource is indeed actually not there where you expect it to be.
If you are certain that the URL is correct, then you need to read the server logs if the server and the servlets started without problems. If a servlet fails during startup, then it will be unavailable that way.
I think this is due to the application's root directory misconfiguration in tomcat.
You can try adding the module base to your URL like this:
String servlet_url = GWT.getModuleBaseURL()+"testhibernategilead/downloadServlet";
Remember: GWT.getModuleBaseURL() puts a "/" at the end of the returned string.

Categories

Resources