Skip to content

Latest commit

 

History

History
254 lines (195 loc) · 7.42 KB

File metadata and controls

254 lines (195 loc) · 7.42 KB

Configure the Example

This section describes how to configure the example.

Create a GitHub OAuth application

The Accounts app supports account creation and authentication via GitHub only. In order to complete an OAuth flow with GitHub as the identity provider, you need to create a new GitHub OAuth app and configure it to connect to the web-auth-endpoint node.

  1. Visit github.com and log into your account.

    The GitHub home page

  2. Navigate to Settings > Developer Settings > OAuth Apps.

    The OAuth apps screen on GitHub

  3. The Register a new application button on GitHub Click the Register a new application button. The Register a new OAuth application screen is displayed:

    The Register a new OAuth application screen on GitHub

  4. In the Application name field, enter a name of your choice. For example, Interbit Test App.

  5. In the Homepage URL field, enter a URL. Any URL works since we are running the example locally.

  6. In the Authorization callback URL field, enter http://localhost:8888/oauth/github.

    Note
    The callback URL is case sensitive, and the port specified is for running the web-auth-endpoint node locally.
  7. The Register app button on GitHub Click the Register application button to finish creating the OAuth app.

    Important
    Leave this browser tab open as we are going to copy values from this tab in subsequent steps.

Clone the interbit repository and install interbit-cli

  1. Open a terminal and clone the interbit repository from GitHub:

    git clone https://github.com/interbit/interbit.git
  2. Install the interbit-cli package globally:

    npm i -g interbit-cli

Generate a set of private and public keys for the platform-deploy and web-auth-endpoint hypervisors

  1. Create a secrets directory at the root of the interbit repository.

    The secrets directory is included in this repository’s .gitignore file and is not tracked by git. We don’t want to commit the files we are going to add here because they include private keys for our Interbit nodes.

  2. Change the current working directory to the secrets directory:

    cd secrets
  3. Generate Interbit key pairs.

    Both the platform-deploy and web-auth-endpoint apps require public and private keys. The following commands generate them and store them in JSON files:

    interbit keys --filename platform-deploy-keys.json
    interbit keys --filename web-auth-endpoint-keys.json

Configure environment variables for platform-deploy

  1. Create the file platform-deploy.sh in the secrets directory with the following content:

    #!/bin/bash
    # Secrets for Accounts app GitHub OAuth chain
    export GITHUB_CLIENT_ID=""
    export GITHUB_CLIENT_SECRET=""
    export GITHUB_REDIRECT_URL=""
    export OAUTH_CALLBACK_URL="http://localhost:3025/account/oauth/gitHub"
    # Key pair for the platform node
    export PUBLIC_KEY=""
    export PRIVATE_KEY=""
    # Peer list override
    export PORT=5025
    export CONNECT_TO_PEERS="localhost:8888"
  2. Update the configuration in platform-deploy.sh:

    1. Copy the Client ID value from the GitHub browser tab and paste it into the GITHUB_CLIENT_ID definition in platform-deploy.sh.

    2. Copy the Client Secret value from the GitHub browser tab and paste it into the GITHUB_CLIENT_SECRET definition in platform-deploy.sh.

    3. In the GITHUB_REDIRECT_URL definition in platform-deploy.sh, specify: http://localhost:8888/oauth/github. This should be the same URL provided in the Authorization callback URL field to the GitHub OAuth app configuration.

    4. Copy the publicKey value from platform-deploy-keys.json and paste it into the PUBLIC_KEY definition in platform-deploy.sh.

    5. Copy the privateKey value from platform-deploy-keys.json and paste it into the PRIVATE_KEY definition in platform-deploy.sh.

  3. Save the updated platform-deploy.sh file.

Configure environment variables for web-auth-endpoint

  1. Create the file web-auth-endpoint.sh in the secrets directory with the following content:

    #!/bin/bash
    # Secrets for Accounts app GitHub OAuth chain
    export GITHUB_CLIENT_ID=""
    export GITHUB_CLIENT_SECRET=""
    # Key pair for the web auth node
    export PUBLIC_KEY=""
    export PRIVATE_KEY=""
    # Peer list override
    export PORT=8888
    export CONNECT_TO_PEERS="localhost:5025"
  2. Update the configuration in web-auth-endpoint.sh:

    1. Copy the Client ID value from the GitHub browser tab and paste it into the GITHUB_CLIENT_ID definition in web-auth-endpoint.sh.

    2. Copy the Client Secret value from the GitHub browser tab and paste it into the GITHUB_CLIENT_SECRET definition in web-auth-endpoint.sh.

    3. Copy the publicKey value from web-auth-endpoint-keys.json and paste it into the PUBLIC_KEY definition in web-auth-endpoint.sh.

    4. Copy the privateKey value from web-auth-endpoint-keys.json and paste it into the PRIVATE_KEY definition in web-auth-endpoint.sh.

  3. Save the updated web-auth-endpoint.sh file.

Update the configuration file for the Accounts app

  1. Navigate to the Accounts app directory:

    cd ../packages/app-account
  2. Open the file interbit.config.js. The first few lines of this file are:

    const path = require('path')
    const chainAliases = require('./src/constants/chainAliases')
    const { controlActionTypes } = require('./src/constants/actionTypes')
    
    const PUB_KEY = ''
    const WEB_AUTH_PUB_KEY = ''
    
    const config = {
        ...
  3. Copy the publicKey value from platform-deploy-keys.json and paste it into the PUB_KEY definition in interbit.config.js.

  4. Copy the publicKey value from web-auth-endpoint-keys.json and paste it into the WEB_AUTH_PUB_KEY definition in interbit.config.js.

  5. Save the updated interbit.config.js file.

Update the configuration file for the Template app

  1. Navigate to the Template app directory:

    cd ../interbit-template
  2. Open the file interbit.config.js. The first few lines of this file are:

    const path = require('path')
    const chainAliases = require('./src/constants/chainAliases')
    
    const PUBLIC_KEY = ''
    
    const config = {
        ...
  3. Copy the publicKey value from platform-deploy-keys.json and paste it into the PUBLIC_KEY definition in interbit.config.js.

  4. Save the updated interbit.config.js file.

Delete the platform-deploy manifest file

The manifest file must be deleted when new Interbit key pairs are generated, as we did in our setup. If there is a pre-existing manifest, the genesis blocks are not overwritten and our new keys do not work. Note that when we generate a new manifest, we create new genesis blocks which results in new chain IDs (which are hashes of the genesis blocks).

cd ../platform-deploy
rm platform/interbit.manifest.json

Configuration complete

At this point, all of the apps are configured. See the next section to see how to start the platform-deploy and web-auth-endpoint nodes and the Accounts and Template apps.