I would like to use Microsoft Graph API to manage Drive files, but I have some trouble with authentication...
I have the code below to get the rights to access to my account :
try(InputStream propFile = MicrosoftEngine.class.getClassLoader().getResourceAsStream("microsoft.properties")){
Properties prop = new Properties();
prop.load(propFile);
setGraphClient(GraphServiceClient.builder().authenticationProvider(request -> {
// Add the access token in the Authorization header
request.addHeader("Authorization", "Bearer " + prop.getProperty("token"));
}).buildClient());
IDriveItemCollectionPage children = graphClient.me().drive().root().children().buildRequest().get();
setDrive(children);
}
catch(IOException e) {
e.printStackTrace();
}
But for the moment, the value of the "token" property is taken from Microsoft Graph Explorer :
After a while (an hour maybe), the token expires and I need to send another request via the Graph Explorer to have a new token and copy/paste it into my Java code.
But this is not convenient... How can I get this token value in Java ? Any ideas ?
Thanks in advance for your help :)