This is the identity management service.
Be sure you've read the instructions for contributing.
-
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
-
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)
-
Clone the repository.
-
Install v1.1.3 of mehserve and complete the setup:
npm i -g mehserve@1.1.3
mehserve install
Then, figure out which port you intend to use and create the mehserve config file:
bash echo 9001 > ~/.mehserve/idm.learnersguild mehserve run
-
Set your
NODE_ENV
environment variable:export NODE_ENV=development
-
# With Homebrew on a mac: brew install rethinkdb
-
Install Redis.
brew install redis
-
Obtain your GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET (see below) by registering a new GitHub OAuth application for your development environment:
- Application name: Learners Guild IDM (dev)
- Homepage URL: http://idm.learnersguild.meh
- Authorization callback URL: http://idm.learnersguild.meh/auth/github/callback
-
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
-
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.
-
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.meh IDM_BASE_URL=http://idm.learnersguild.meh # 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>
-
Run the setup tasks:
npm install npm run db:create npm run db:migrate -- up
-
Seed your development database with test member and project data:
npm run db:copy npm run db:migrate -- up // to ensure migrations are applied to copied data
-
Run the server:
npm start
-
Visit the server in your browser:
open http://idm.learnersguild.meh
-
(OPTIONAL) Add some test users:
npm run data:users -- --verbose --role=learner some-dummy-invite-code
Perhaps your nvm is not linked, try typing into your terminal
cp $(brew --prefix nvm)/nvm.sh ~/.nvm/
If you are using bash instead of zsh, you might have a logged-in shell and you'll need to add the following code to your ~/.bash_profile
instead of your ~/.bashrc
or ~/.zshrc
because those don't always load. (To test for sure, add an echo testing
command at the top of your RC files, if you see nothing when opening new tabs, you're using bash_profile logged-in shell)
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[[ -s "$HOME/.avn/bin/avn.sh" ]] && source "$HOME/.avn/bin/avn.sh" # load avn
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
[ `uname -s` != "Darwin" ] && return
If you are receiving an error similar to the following when running npm run db:copy
you might be missing python drivers.
Error
stderr: Error when launching 'rethinkdb-restore': No such file or directory
The rethinkdb-restore command depends on the RethinkDB Python driver, which must be installed.
If the Python driver is already installed, make sure that the PATH environment variable
includes the location of the backup scripts, and that the current user has permission to
access and run the scripts.
Instructions for installing the RethinkDB Python driver are available here:
http://www.rethinkdb.com/docs/install-drivers/python/
Try installing python drivers with this command:
brew install python && sudo pip2 install rethinkdb
If you've used the db:copy script to seed the database and still aren't logged in, there isn't an idm user in the test data linked to your github account. You'll need to manually insert an invite code to the database and use it to sign up in your local idm service.
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: '0edb08e1-d8ab-4318-8363-0711a7f9edbb',
code: 'hand_crafted_artisanal_invite_code',
description: 'hand crafted artisanal invite code',
roles: ['admin', 'learner'],
active: true,
createdAt: r.now(),
updatedAt: r.now(),
})
Use the invitation code hand_crafted_artisanal_invite_code
to create an account.
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
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
If you get an error like:
Error: Failed to replace env in config: ${NPM_AUTH_TOKEN}
You'll need to set an env variable with your NPM auth token (or a blank string):
export NPM_AUTH_TOKEN=""
See the LICENSE file.