title: Google calendar api - can I reuse token form google?
body: <p>Can I use token from FE, where user is authorized from Google to insert event into google calendar on backend?
  Flow is:</p>
  <ul>
  <li>user uthorized by google on frontend (firebase and google)</li>
  <li>fill form on FE and submit</li>
  <li>on backend side save data into DB and post event on calendar</li>
  </ul>
  <p>Can I reuse token from FE? How I can do that?</p>
  <p>I try few solutions using <code>GoogleAuthorizationCodeFlow</code>, and every time I get HTTP 401 or link to authorization in logs...</p>
  <p>Currently creation of service looks like:</p>
  <pre><code>    protected void initialize() {
      GoogleClientSecrets clientSecrets = createClientSecrets();
      GoogleAuthorizationCodeFlow flow = createGoogleAuthorizationCode(clientSecrets);
      LocalServerReceiver receiver = createReceiver();
      Credential credential = createCredentials(flow, receiver); // here I get link to authorization in google :(
      credential.setAccessToken(getAccessToken());
      service = createCalendarClientService(credential);
  }
  
  private GoogleAuthorizationCodeFlow createGoogleAuthorizationCode(GoogleClientSecrets clientSecrets) {
      try {
          return new GoogleAuthorizationCodeFlow.Builder(
                  HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
                  .setDataStoreFactory(new MemoryDataStoreFactory())
                  .setAccessType(&quot;online&quot;)
                  .build();
      } catch (IOException e) {
          throw new RuntimeException(e);
      }
  }
  
  private LocalServerReceiver createReceiver() {
      return new LocalServerReceiver.Builder()
              .setPort(port)
              .build();
  }
  
  private Credential createCredentials(GoogleAuthorizationCodeFlow flow, LocalServerReceiver receiver) {
      try {
          return new AuthorizationCodeInstalledApp(flow, receiver)
                  .authorize(&quot;user&quot;);
      } catch (IOException e) {
          throw new RuntimeException(e);
      }
  }
  
  private Calendar createCalendarClientService(Credential credential) {
      return new Calendar.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
              .setApplicationName(APPLICATION_NAME)
              .build();
  }
  </code></pre>