private String getAuthorizationHeader()

in src/main/java/com/spotify/github/v3/clients/GitHubClient.java [817:843]


  private String getAuthorizationHeader(final String path) {
    if (isJwtRequest(path) && getPrivateKey().isEmpty()) {
      throw new IllegalStateException("This endpoint needs a client with a private key for an App");
    }
    if (getAccessToken().isPresent()) {
      return String.format("token %s", token);
    } else if (getPrivateKey().isPresent()) {
      final String jwtToken;
      try {
        jwtToken = JwtTokenIssuer.fromPrivateKey(privateKey).getToken(appId);
      } catch (Exception e) {
        throw new RuntimeException("There was an error generating JWT token", e);
      }
      if (isJwtRequest(path)) {
        return String.format("Bearer %s", jwtToken);
      }
      if (installationId == null) {
        throw new RuntimeException("This endpoint needs a client with an installation ID");
      }
      try {
        return String.format("token %s", getInstallationToken(jwtToken, installationId));
      } catch (Exception e) {
        throw new RuntimeException("Could not generate access token for github app", e);
      }
    }
    throw new RuntimeException("Not possible to authenticate. ");
  }