Skip to content
Augusto Crespo edited this page Jul 8, 2021 · 4 revisions

The main goal of this document is to provide developer a tutorial of how to configure some parts of the site.

Single sign-on with Google (Authentication)

Requirements:

  • A Firebase project created with Google sign-in method activated
  • Firebase installed in the project

Method

  1. Create a firebase.js file

    1. Import Firebase and firebase auth module
    2. Create the const firebaseConfigu with all credentials required in your project: apiKey, authDomain, projectId, etc.
    3. Initialize firebase and create the var provider: firebase.initializeApp(firebaseConfig); var provider = new firebase.auth.GoogleAuthProvider();
    4. Export firebase and provider
  2. In Vue component

    1. Import the firebase.js file created before
    2. Create a method signInWithPopup calling the function:
       .auth()
       .signInWithPopup(provider)
       .then((result) => {
         this.credential = result.credential;
         // This gives you a Google Access Token. You can use it to access the Google API.
         this.token = this.credential.accessToken;
         // The signed-in user info.
         this.user = result.user;
       })
       .catch((error) => {
         // Handle Errors here.
       });

In order to create user roles such as "admin", Firebase does not support this directly, but it allows to set custom user claims. We managed this through backend. More info at: https://dev.to/emeka/securing-your-express-node-js-api-with-firebase-auth-4b5f

Create issues on Github automatically

We managed this via backend

Requirements

  1. A Node.js project with Express
  2. Octokit package

Method

  1. Create a Github app to work as a middleware between the backend and the repository.
    1. Copy its App ID and Private key
    2. Install the app in the repository and copy its Installation ID.
  2. Import Octokit, and createAppAuth from @octokit/auth-app
  3. Create a const "installationOctokit" with the strategy createAppAuth and three params:
    1. App ID from the Github app
    2. Private key from the Github app
    3. Installation ID from the repository where it is installed the app
  4. Create an async await function to call Octokit to create the issue with the params you choose.

Example:

installationOctokit.request("POST /repos/*REPO-OWNER*/*REPO-NAME*/issues", { 
        owner: "*REPO-OWNER*",
        repo: "*REPO-NAME*",
        title: "",
        body: ""
    });

More info at:https://www.npmjs.com/package/octokit#authentication