How to prevent a token created with OAuth 2.0 from expiring?

65
June 27, 2022, at 11:30 AM

I am using the google drive API and am running into a problem. I have a JAVA application that follows the documentation steps to implement the service, my problem is with the token that expires every so often. What I need is that it does not have an expiration time or that it can be done automatically to avoid manipulating the browser, since I plan to use my program to create automatic backups and the user does not have to participate. I have already tried with update tokens:

    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
            HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
            .setDataStoreFactory(new FileDataStoreFactory(new java.io.File(TOKENS_DIRECTORY_PATH)))
            .setAccessType("offline")
            .setApprovalPrompt("force")
            .build();
    
    LocalServerReceiver receiver = new LocalServerReceiver.Builder().setPort(8888).build();
    Credential cr =  new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
    boolean refresToken = cr.refreshToken();
    logger.info("Token is refresh: "+refresToken);

but they only last up to 7 days, from there I have the following message:

Google Drive: com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad Request POST https://oauth2.googleapis.com/token { "error" : "invalid_grant", "error_description" : "Token has been expired or revoked." }

Any comment is appreciated, thank you.

Rent Charter Buses Company
READ ALSO
Let all instances of object call method at same time (java)

Let all instances of object call method at same time (java)

So I have a superclass called Tile and many subclasses like BlueTile, GreenTile etc

68
change the time interval in spring app using the code

change the time interval in spring app using the code

I have a spring boot applicate that is using many types of date objects it like:

38
How to move table row to the top within a loop - React

How to move table row to the top within a loop - React

I have a loop which goes through an array (files) of objects (person)If the person works as a doctor or a vet I would like to display their row at the top of the table, if not, they should be displayed under the doctors and vets

33
Can we create an object in Java with out class like in js or python with random key and values

Can we create an object in Java with out class like in js or python with random key and values

Like in other programing languages - python or JS, when we create a rest api specifically post for the request body we attract some JSON Object

33