title: Get token for Microsoft Graph API in Java
body: <p>I would like to use Microsoft Graph API to manage Drive files, but I have some trouble with authentication...</p>
  <p>I have the code below to get the rights to access to my account :</p>
  <pre><code>try(InputStream propFile = MicrosoftEngine.class.getClassLoader().getResourceAsStream(&quot;microsoft.properties&quot;)){
        Properties prop = new Properties();
        prop.load(propFile);
  
        setGraphClient(GraphServiceClient.builder().authenticationProvider(request -&gt; {
          // Add the access token in the Authorization header
          request.addHeader(&quot;Authorization&quot;, &quot;Bearer &quot; + prop.getProperty(&quot;token&quot;));
        }).buildClient());
  
        IDriveItemCollectionPage children = graphClient.me().drive().root().children().buildRequest().get();
        setDrive(children);
      }
      catch(IOException e) {
        e.printStackTrace();
      }
  </code></pre>
  <p>But for the moment, the value of the &quot;token&quot; property is taken from Microsoft Graph Explorer :</p>
  <p><a href="https://i.stack.imgur.com/IWVmR.png" rel="nofollow noreferrer">Example here</a></p>
  <p>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.</p>
  <p>But this is not convenient... How can I get this token value in Java ? Any ideas ?</p>
  <p>Thanks in advance for your help :)</p>