public static String getAccessTokenFromClientCredentialsGrantFlow(String host, String clientId, String clientSecret, String tenant, String scope) {
    final OAuth20Service service = new ServiceBuilder(clientId)
      .apiSecret(clientSecret)
      .defaultScope(scope)
      .build(new ScribeMicrosoftOauth2Api(host, tenant));
    try {
      return service.getAccessTokenClientCredentialsGrant().getAccessToken();
    } catch (IOException | ExecutionException e) {
      throw new IllegalStateException("Unable to get a token: " + e);
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
      throw new IllegalStateException("Interrupted while getting a token: " + e);
    }
  }
@Test
  void getAccessTokenFromClientCredentialsGrantFlow_throwsException() {
    assertThatThrownBy(() -> OAuthMicrosoftRestClient.getAccessTokenFromClientCredentialsGrantFlow("https://localhost", "clientId", "clientSecret", "tenant", "scope"))
      .isInstanceOf(IllegalStateException.class)
      .hasMessageStartingWith("Unable to get a token: ");
  }