[Feature Request] POST Request from Frontend to Github App
emsesc opened this issue · comments
Is your proposal related to a problem?
In order to trigger the cloning of the template repository, the frontend must make a POST request with the needed auth information to the HTTP route endpoint on the Github App.
Dependent on #134
Describe the solution you'd like
An HTTP Route should be created so that an endpoint is available for a POST request to be made from the frontend with auth information. A POST request that will be called from the frontend when a user chooses to begin a course. The user's Github authentication information along with the course details (template repo name) will be sent in the request to the HTTP route endpoint on the Github App.
camp.dev --> POST request with user information --> Github App HTTP route endpoint
After the MVP is complete, consider adding Authentication headers for secure transmission of information
Describe alternatives you've considered
A considered alternative could be to listen for a webhook event from Hasura on the Github App HTTP route instead of a POST request from the frontend.
Additional context
camp.dev --> POST Request --> Github App HTTP route endpoint --> clone repository with POST request to Github API --> template repository created on student account
The Github Oauth app from issue #134 was integrated
An HTTP route was opened on the Github App as shown here:
module.exports = (app, { getRouter }) => {
// Get an express router to expose new HTTP endpoints
const router = getRouter("/api");
// Use any middleware
router.use(require("express").static("public"));
router.use(bodyParser.urlencoded({
extended: true
}));
router.use(bodyParser.json());
router.use(cors());
// Add a new route
router.post("/post", (req, res) => {
const accessToken = req.body.accesstoken
var lab = req.body.lab
console.log("Starting!")
cloneRepo(accessToken, lab)
res.json({status: 'cloning started'});
});
};
This allowed the next.js (next-auth) frontend to make a POST request to the Github App, passing the accessToken
and course information to be used to clone the template repository.
next-auth
was implemented to authenticate the user through Github using a template and JSON web tokens.- A simple react.js form was placed here to trigger the POST request to the Github App.
- To retrieve the
accessToken
, a request is made to this API route - A successfully implemented next-auth frontend with the POST request can be found here