/idm

identity management service

Primary LanguageJavaScriptMIT LicenseMIT

idm

Codeship Status for LearnersGuild/idm Code Climate GPA Code Climate Issue Count Test Coverage

This is the identity management service.

Getting Started

Be sure you've read the instructions for contributing.

  1. Globally install nvm, avn, and avn-nvm.

    curl -o- https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
    npm install -g avn avn-nvm
    avn setup
  2. Create an npm account if you don't have one, then setup your NPM_AUTH_TOKEN:

    npm login
    # in your current shell as well as in ~/.bashrc (or ~/.zshrc, etc)
    export NPM_AUTH_TOKEN=$(cat $HOME/.npmrc | grep _authToken | cut -d '=' -f2)
  3. Clone the repository.

  4. Setup and run mehserve. Then figure out which port you intend to use and create the mehserve config file:

    echo 9001 > ~/.mehserve/idm.learnersguild
    mehserve run
  5. Set your NODE_ENV environment variable:

    export NODE_ENV=development
  6. Install RethinkDB.

    # With Homebrew on a mac:
    brew install rethinkdb
  7. Install Redis.

    brew install redis
  8. Obtain your GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET (see below) by registering a new GitHub OAuth application for your development environment:

  9. Generate a key-pair for JWT token signing / verifying:

    openssl genrsa -out /tmp/private-key.pem 2048
    openssl rsa -in /tmp/private-key.pem -outform PEM -pubout -out /tmp/public-key.pem
  10. Create a free AWS account: https://aws.amazon.com

Make a copy of your access key ID and secret access key. You'll need to include these in your environment variables in the next step.

  1. Create your .env.development file for your environment. Example:

    PORT=9001
    REDIS_URL=redis://localhost:6379
    RETHINKDB_URL=rethinkdb://localhost:28015/idm_development
    GITHUB_CLIENT_ID=<from above>
    GITHUB_CLIENT_SECRET=<from above>
    # Both of the URLs below are needed and remove this commented line
    APP_BASE_URL=http://idm.learnersguild.dev
    IDM_BASE_URL=http://idm.learnersguild.dev
    # For JWT string data below, replace all linebreaks with \n
    # and include -----BEGIN RSA PRIVATE KEY----- and -----END RSA PRIVATE KEY-----
    # remove these three commented lines
    JWT_PRIVATE_KEY="<quoted string data from /tmp/private-key.pem >"
    JWT_PUBLIC_KEY="<quoted string data from /tmp/public-key.pem replace all linebreaks with \n >"
    S3_BUCKET=guild-development
    S3_KEY_PREFIX=db
    AWS_ACCESS_KEY_ID=<YOUR_AWS_ACCESS_KEY_ID>
    AWS_SECRET_ACCESS_KEY=<YOUR_AWS_SECRET_ACCESS_KEY>
  2. Run the setup tasks:

    npm install
    npm run db:create
    npm run db:migrate -- up
  3. Run the server:

    npm start
  4. Visit the server in your browser:

    open http://idm.learnersguild.dev
  5. Create an IDM Account

    Go to localhost:8080 and use the Data Explorer to run the following command to issue yourself an invitation code.

    r.db('idm_development').table('inviteCodes').insert({
      id: '58abd2aa-3826-4604-bf7c-f8f2cf7eaad9',
      code: 'hand_crafted_artisanal_invite_code',
      description: 'hand crafted artisanal invite code',
      roles: ['admin', 'member'],
      active: true,
      createdAt: r.now(),
      updatedAt: r.now(),
    })
    
  6. Sign In

    Use the invitation code hand_crafted_artisanal_invite_code to create an account.

  7. (OPTIONAL) Add some test users:

    npm run data:users -- --verbose --role=member some-dummy-invite-code

Gotchas

Node version

In the event that you see Javascript and C compilation errors when running npm start, ensure that your installed node version matches the node version in package.json:

➜ cat package.json | grep node\"
    "node": "5.6.x",
➜ node -v
v5.6.0

To run multiple versions of node on your machine, install nvm and then use 5.6

TypeErrors

If you see errors that look like this:

TypeError:
          method: GET /
          params: {}
          TypeError: An internal server error occurred
    at Strategy.OAuth2Strategy (/Users/jrob/workspace/learners-guild/idm/node_modules/passport-oauth2/lib/strategy.js:82:34)
    at new Strategy (/Users/jrob/workspace/learners-guild/idm/node_modules/passport-github/lib/strategy.js:62:18)

or

TypeError: OAuth2Strategy requires a clientID option

Ensure that your NODE_ENV is set:

export NODE_ENV=development

NPM_AUTH_TOKEN Error Message

When attempting to npm login, was seeing Error: Failed to replace env in config: ${NPM_AUTH_TOKEN}.

export NPM_AUTH_TOKEN=""

License

See the LICENSE file.