Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] POST Request from Frontend to Github App #135

Closed
emsesc opened this issue Jan 31, 2021 · 1 comment · May be fixed by #136
Closed

[Feature Request] POST Request from Frontend to Github App #135

emsesc opened this issue Jan 31, 2021 · 1 comment · May be fixed by #136

Comments

@emsesc
Copy link
Collaborator

emsesc commented Jan 31, 2021

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

image

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

@emsesc emsesc changed the title [Feature Request] POST Request [Feature Request] POST Request from Frontend to Github App Feb 2, 2021
@emsesc emsesc added the high label Feb 2, 2021
@emsesc
Copy link
Collaborator Author

emsesc commented Feb 6, 2021

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

@emsesc emsesc closed this as completed Feb 6, 2021
@emsesc emsesc linked a pull request Feb 6, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant