Google Drive revokes my token - java

I am new to google drive and started with the tutorial quickstart.
After numerous attampts I run the program successfully.
However I had permission and authorisation problems when I was trying to delete files.
Drive service = getDriveService();
service.files().delete("FileId").execute();
So I decide to change the URL in the client_secret.json,
From: "auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs"
To: "auth_provider_x509_cert_url":"https://www.googleapis.com/auth/drive"
in the hope that I would now get the permission to delete files. However after executing the program again I didn't get the authorization tab of the internet browser like before.
As an example of the mentioned tab, here an image from google playground:
That's the reason why I delted the connection from my app to google drive website:
In addition i recreated also the client_secret.json file. However when I now execute the program I get only this error, independent what I am doing.
Exception in thread "main" com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad Request
{
"error" : "invalid_grant",
"error_description" : "Token has been revoked."
}
at com.google.api.client.auth.oauth2.TokenResponseException.from(TokenResponseException.java:105)
at com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:287)
at com.google.api.client.auth.oauth2.TokenRequest.execute(TokenRequest.java:307)
at com.google.api.client.auth.oauth2.Credential.executeRefreshToken(Credential.java:570)
at com.google.api.client.auth.oauth2.Credential.refreshToken(Credential.java:489)
at com.google.api.client.auth.oauth2.Credential.intercept(Credential.java:217)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:859)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
at main.java.DriveQuickstart.main(DriveQuickstart.java:101)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
So the two questions are what should i do to get the tutorial running again and how to set the permissions so that i can delete files?

Now I find out the problem:
I had to delete the directory "user.home/.credentials/drive-api-quickstart".
After that I can give the program the authorisation, which it needs.
Hope that someone will help this post ;)

I had a slightly different case. After getting the example in the Quick Start Guide to work a few months ago, I got the following error today when rerunning it.
Exception in thread "main" com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad Request
{
"error" : "invalid_grant",
"error_description" : "Bad Request"
}
Since the tokens were stored in TOKENS_DIRECTORY_PATH ("tokens"), the token stored there probably became invalid. Deleting directory tokens allowed me to once again get the browser page to select a gmail account to proceed with. Everything worked from there.

Related

Getting 403 error trying to access to Pastebin from Java code

I was trying to return every lines that a raw pastebin link has.
Everything was going great when suddenly I started receiving this error on console:
java.io.IOException: Server returned HTTP response code: 403 for URL: https://pastebin.com/raw/mBSbY97k
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1993)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1585)
at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:224)
at java.base/java.net.URL.openStream(URL.java:1162)
at App.execute(App.java:185)
at App.<init>(App.java:164)
at Main.main(Main.java:8)
Link is public and there is no need to log in or authenticate to read it. Probably, the captcha just blocked it but I really don't know when I will be able again to continue with my code.
EDIT: I realized that if I change my IP (I connect to another WIFI) it works. So the question is: what can I do to be able to connect there from my Wifi and, it's needed to force-change my IP?.

Google Sheet API Update tokens?

For god's sake I'm out of my mind right now.
I can't get to seemingly an extremely easy point, I've travelled through hundreds of web pages, but couldn't succeed in finding an answer.
I've been using Google Sheet API (Java lang), and when I started it was all fine and working. And is still working, but the problem is - I need to change my account. Because of reasons, no other way
I'm copying all the new credentials, doing step-by-step what the Quickstart says, but yet every time I try to get access to the spreadsheet I get this:
Exception in thread "main" com.google.api.client.auth.oauth2.TokenResponseException: 401 Unauthorized
at com.google.api.client.auth.oauth2.TokenResponseException.from(TokenResponseException.java:105)
at com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:287)
at com.google.api.client.auth.oauth2.TokenRequest.execute(TokenRequest.java:307)
at com.google.api.client.auth.oauth2.Credential.executeRefreshToken(Credential.java:576)
at com.google.api.client.auth.oauth2.Credential.refreshToken(Credential.java:493)
at com.google.api.client.auth.oauth2.Credential.intercept(Credential.java:217)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:868)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
I've tried deleting tokens folder. Even tried to create a totally new project. Nothing works.
Where does the problem hide? In browsers? What browser? I'm using Safari (which is default), but I've got Chrome on my Mac too.
Please help, I'm desperate, it's deadline today

Docusign OAuth getAccessToken failing for Java app

I have a Java application which has been Docusigning away nicely until it broke sometime last week (might have been anytime in the last couple of weeks) .
Nothing has changed on my side, so I suspect some change on the Docusign front.
The symptoms are very puzzling and are as follows :
Sign-in with OAuth works fine up to the stage when it attempts to get the access token, at which point it hangs until it times out. The initial phases (log in, call callback with generated oauth code which then calls the getAccesCode component ) work fine, and here's the kicker - if I plug the exact values from the hanging getAccessToken call into curl and execute it from the same server, it works fine.
Here are the details of the hanging call :
getAccessToken request location='https://account-d.docusign.com/oauth/token'
getAccessToken request body=grant_type=authorization_code&code=<many characters>'
getAccessToken Request header : Authorization:Basic Y2E1ZWM3N2UtMGQ4 + MORE
So it is definitely something to do with the Java libraries, however it is not possible to get a debug trace of the OAuth part on the Docusing server (although I know you can trace the actual API calls by enabling the Docusign logs it does not appear to trace the oauth steps )
What is puzzling is that it was working fine for months. And now works fine with curl, but just hangs in Java. I suspected SSL , but if that were the case why do the initial steps work ?
This is the Java stacktrace , interestingly does not always get dumped (but the hang always happens)
java.net.SocketException: Connection timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:152)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at sun.security.ssl.InputRecord.readFully(InputRecord.java:442)
at sun.security.ssl.InputRecord.read(InputRecord.java:480)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:927)
at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:884)
at sun.security.ssl.AppInputStream.read(AppInputStream.java:102)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:275)
at java.io.BufferedInputStream.read(BufferedInputStream.java:334)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:687)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:633)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:658)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1323)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:468)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:338)
at org.apache.oltu.oauth2.client.URLConnectionClient.execute(URLConnectionClient.java:98)
As mentioned , running curl against https://account-d.docusign.com/oauth/token with parameters grant_type=authorization_code and the generated code=blah with the appropriate auth header works fine, returning the correct json response.
Any ideas anyone ? How can I trace the Docusign side to find out why it is hanging ? What has changed of late ? New SSL certs ? I'm stumped.
Per Amit and DS Support, DocuSign has ended support for TLS1.0 in Demo from May 29th, 2018 and will soon end the support in PROD as well. Please test the connection on your end if you are using TLS1.0, if yes then you need to upgrade it to TLS1.1+ to again start using DS APIs. I am assuming if you have not done any code changes then this is the issue which you are seeing in your application.

Android Volley - Strange Error with HTTP code 401- java.io.IOException: No authentication challenges found

I meet this error when send a request and get back response with code 401:
com.android.volley.NoConnectionError: java.io.IOException: No authentication challenges found
Some people say that:
This error happens beause the server sends a 401 (Unauthorized) but does not give a "WWW-Authenticate" which is a hint for the client what to do next. The "WWW-Authenticate" Header tells the client which kind of authentication is needed (either Basic or Digest). This is usually not very useful in headless http clients, but thats how the standard is defined. The error occurs because the lib tries to parse the "WWW-Authenticate" header but can't.
( android - volley error No authentication challenges found )
But it's quite weird for me because I don't want to use WWW-authenticate things, I just want to get the code 401, but I always get the exception.
How can I bypass this problem? Any suggestion is really appreciated.
I have do some research and come to conclusion that, this is a server issue, that did not follow the convention.
From wiki:
401 Unauthorized (RFC 7235)
Similar to 403 Forbidden, but specifically for use when authentication is required and has failed or has not yet been provided. The response must include a WWW-Authenticate header field containing a challenge applicable to the requested resource. See Basic access authentication and Digest access authentication.
I think the best way to solve this problem is to solve in the server by add the header (something like:
WWW-Authenticate: xBasic realm=""
For me, I cannot change the server, so I have to check the error message to detect that a 401 error:
if (error.getMessage().equalsIgnoreCase("java.io.IOException: No authentication challenges found")){
showLoginError();
}
Not very elegant solution but work for now.

Apns: Connection closed by remote host

I have a Java app, which works with Apple Push Notification Server (APNS). I use lib: JavaPNS.jar for sendings push messages to iDevices.
But, sometimes Push Notification doesn't work, I've found such error:
[16:35:40] Andrew Balakhanov: 2012-10-27 04:00:00,616 WARN
[com.notnoop.apns.internal.ApnsConnectionImpl] Failed to send message
com.notnoop.apns.EnhancedApnsNotification#af310b99... trying again
java.net.SocketException: Connection closed by remote host at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.checkWrite(SSLSocketImpl.java:1339)
at
com.sun.net.ssl.internal.ssl.AppOutputStream.write(AppOutputStream.java:44)
at java.io.OutputStream.write(OutputStream.java:58) at
com.notnoop.apns.internal.ApnsConnectionImpl.sendMessage(ApnsConnectionImpl.java:161)
at
com.notnoop.apns.internal.ApnsServiceImpl.push(ApnsServiceImpl.java:46)
at
com.notnoop.apns.internal.AbstractApnsService.push(AbstractApnsService.java:52)
at
com.notnoop.apns.internal.ApnsServiceImpl.push(ApnsServiceImpl.java:36)
at com.clinics.core.api.util.APN.sendReminderAlert(APN.java:55) at
com.clinics.core.api.services.schedule.reminder.impl.ReminderSenderMobile.prepareAndSend(ReminderSenderMobile.java:190)
at
com.clinics.core.api.services.schedule.reminder.impl.ReminderSenderMobile.send(ReminderSenderMobile.java:132)
at
com.clinics.core.api.services.schedule.reminder.AbstractReminderFacade.generateAndSendReports(AbstractReminderFacade.java:53)
at
com.clinics.core.api.services.schedule.reminder.ReminderJob.doIt(ReminderJob.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597) at
org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:273)
at
org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:264)
at
org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:86)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202) at
org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:525)
Could you please tell me, what the error means? Is it mean, that Apple server banned me, is it mean that I send too many requests to it?
The most likely cause of this error is that you are sending production tokens to the sandbox server or sandbox tokens to the production server.
I got this exact behavior today until I figured out I had signed my app with an Ad Hoc profile, which makes the app use the production push server for generating the token, while my server was talking to the sandbox push server.
This error could also appear when the payload is too long.
You can check by calling PayloadBuilder's isTooLong() function.
PayloadBuilder payload = APNS.newPayload();
// build your payload
if (payload.isTooLong())
{
// your payload is too long, a push() will result in the above exception
}
The problem I was facing was that the instructions I was using to generate my .p12 certificate file were incorrect. I ended up following the instructions from NWPusher and those worked for me.

Categories

Resources