Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to POST an issue stub on GitHub using the GitHub API using the logged in user, without authentification keys?

Users of my web application are expected to provide bug reports as a GitHub issue, with a pregenerated title and body.

This works perfectly fine using GET for small bodies:

const title = getLastErrorTitle();
const body = getAllTheLogMessages();
window.open(`https://github.com/theuser/therepo/issues/new?title=${encodeURIComponent(title)}&body=${encodeURIComponent(body)}`);

If the user is logged in, GitHub presents the user with a new issue with the title and body already filled out, perfect. If not, GitHub prompts the user to log in and it works the next time.

However, if the body is too large, the GET request fails because the URL becomes too long.

After consulting the manual I tried doing the same with POST but I get a 404 from GitHub with the following test request (jQuery for brevity):

 $.ajax({
  type: "POST",
  url: "https://api.github.com/repos/theuser/therepo/issues",
  data: data = {title: "Test", body: "Test Body"},
});

My suspicion is, that the GitHub API was not designed with my use case in mind, but that POST always requires authentication and creates the full issue in one go, without letting the user change it beforehand like it is possible with GET.

How can I transfer the functionality of the GET method over to the POST method? I just want GitHub to present the user, that is currently logged in inside the browser, with a prefilled issue, without needing a token.

like image 229
Konrad Höffner Avatar asked Jun 05 '20 15:06

Konrad Höffner


1 Answers

You can't. Otherwise, it would be a major CSRF exploit.

However, you can use OAuth authentication that will allow your application to use some features : https://developer.github.com/apps/building-oauth-apps/authorizing-oauth-apps/

Or simply, redirect the user to a new issue page (for exemple with a simple HTML link <a>) with some automatic content, using this pattern :

https://github.com/{theUser}/{theRepo}/issues/new?body={theContentYouWhant}&title={theTitleYouWhant}

Example : https://github.com/CristalTeam/php-api-wrapper/issues/new?body=Hi,%20this%20is%20the%20body%20you%20want&title=Hello,%20this%20is%20a%20prefill%20issue

like image 149
Camille Avatar answered Sep 17 '22 23:09

Camille