diff --git a/README.md b/README.md index 697f724..89ecad1 100644 --- a/README.md +++ b/README.md @@ -64,16 +64,20 @@ available in as a request header in a proxy forward would work as well. ### Noa Playground -There is a companion Github Repo [Noa Playground](https://github.com/handnot2/noa_playground). This is very -similar to Google OAuth2 Playground. Once Noa is setup and running +There is a companion Github Repo [Noa Playground](https://github.com/handnot2/noa_playground). +This is very similar to Google OAuth2 Playground. Once Noa is setup and running you can use Noa Playground to try-out Authorization Code Grant flow -end-to-end without writing any code! Make sure to get Noa installed before you follow the instructions on setting up the playground. +end-to-end without writing any code! + +Make sure to get Noa installed before you follow the instructions on setting up the playground. ## Installation Make sure that you have Elixir 1.5.0/Erlang 20.0.x, Nodejs, npm and Docker installed. +### Build Docker Image + ``` git clone https://github.com/handnot2/noa cd noa @@ -90,26 +94,20 @@ sudo mix docker.release --no-cache > `docker.release` commands, insert `env "PATH=$PATH"` between sudo > and mix in the above commands. -Continue with installation with the following commands: - -``` -./noa_docker_setup.sh -``` - -This will prompt you to make credential file for the end-user -authentication. Just follow the simple instructions you see on the -console. The next part is to prep the database with migration and -seeding. (The database instance is automatically created from the -earlier step.) +### Noa Installation using Docker Image ``` +./noa_docker_init.sh ${HOME}/mynoa +cd ${HOME}/mynoa +vim seeds/ro_quickstart.creds ./noa_docker_seed.sh ``` -You will have to restart the Noa Docker Containers at the end. -Console output from the above command will tell you exactly what to do. +Checkout the `README.md` file in `${HOME}/mynoa` for instructions on +`seeds/ro_quickstart.creds` file. -At the end of this you will have a docker base instance of Noa running. +At the end of this you will have a docker based instance of Noa running. +From this point out, you simply use `docker-compose` to manage Noa. > Make sure to add > @@ -117,5 +115,6 @@ At the end of this you will have a docker base instance of Noa running. > > To your `/etc/hosts` file. -Once this done, you can quickly get `Noa Playground` (OAuth2 Playground) -up and running to try out Noa. +Head over to [Noa Playground](https://github.com/handnot2/noa_playground). +Instructions over there show how to setup your own local OAuth2 Playground +to work with Noa. diff --git a/README.tmpl b/README.tmpl new file mode 100644 index 0000000..04083e4 --- /dev/null +++ b/README.tmpl @@ -0,0 +1,53 @@ +# Noa OAuth2 Server Setup + +### Create Resource Owner Credentials file + +Edit `seeds/ro_quickstart.creds` file and add the end user +credentials - one line per user. The format is `signin-name:password`. + +You might want to keep a copy of this somewhere else in case you end up +recreating this Noa try-out setup. + +### Seed Noa Setup + +Before you can start using this setup, you need to bootstrap +it with Ecto migration and a set of authorization providers, +OAuth2 clients, definitions of protected resources +(with scope and registered redirect URIs etc). The definitions are +available in `seeds/demo_seed_data.yml` file. + +``` +./noa_docker_seed.sh +``` + +This will use docker-compose to bring up a Postgresql database, Noa +and perform the seeding activities. Upon completion this creates +`seed_output.txt` file. Keep this file around. It contains +the authorization provider URLs and for OAuth2 client IDs. + +> OOTB the secret for the OAuth2 clients created during +> this seeding process is the same as their name. You can +> explicitly specify it by adding `client_secret: value`. +> When you are initially trying out, simply go with the +> OOTB setup and use the client name as the `client_secret`, +> `rs1client1` for example. + +The OAuth2 clients in the `yml` file are already setup with +callback `redirect_uri` for Noa Playground, Google OAuth2 +Playground as well as Postman. + +> http://localhost:4004 +> https://developers.google.com/oauthplayground +> https://www.getpostman.com/oauth2/callback + +All setup ready to go. + +### Trying out this Noa instance + +You can setup your own OAuth2 Playground by following instructions in +[Noa Playground](https://github.com/handnot2/noa_playground). + +### Getting rid of Noa setup + +First make sure that the docker containers are stopped and removed. +Then use `sudo` to remove the Noa tryout directory. diff --git a/docker-compose.yml b/docker-compose.tmpl similarity index 73% rename from docker-compose.yml rename to docker-compose.tmpl index 526a991..2063f1a 100644 --- a/docker-compose.yml +++ b/docker-compose.tmpl @@ -6,18 +6,18 @@ services: - 8.8.8.8 - 8.8.4.4 env_file: - - ${HOME}/.noa/noa.env + - ./noa.env ports: - "5432:5432" volumes: - - ${HOME}/.noa/pgdc/pgdata:/var/lib/postgresql/data + - ./pgdc/pgdata:/var/lib/postgresql/data noa: image: noa:release dns: - 8.8.8.8 - 8.8.4.4 env_file: - - ${HOME}/.noa/noa.env + - ./noa.env environment: - NOA_HOST=my.noa - NOA_PORT=4000 @@ -37,8 +37,8 @@ services: links: - db volumes: - - ${HOME}/.noa/ssl:/opt/app/ssl - - ${HOME}/.noa/seeds:/opt/app/seeds + - ./ssl:/opt/app/ssl + - ./seeds:/opt/app/seeds command: ["foreground"] nginx: image: nginx:alpine @@ -50,6 +50,6 @@ services: links: - noa volumes: - - ${HOME}/.noa/nxdc/etc/nginx:/etc/nginx:ro - - ${HOME}/.noa/nxdc/var/log/nginx:/var/log/nginx - - ${HOME}/.noa/ssl:/ssl:ro + - ./nxdc/etc/nginx:/etc/nginx:ro + - ./nxdc/var/log/nginx:/var/log/nginx + - ./ssl:/ssl:ro diff --git a/mix.exs b/mix.exs index f7d9e82..7787dd0 100644 --- a/mix.exs +++ b/mix.exs @@ -1,7 +1,7 @@ defmodule Noa.Mixfile do use Mix.Project - @version "0.7.2-alpha" + @version "0.7.3-alpha" @description "OAuth2" @source_url "https://github.com/handnot2/noa" @playground_url "https://github.com/handnot2/noa_playground" diff --git a/noa_docker_setup.sh b/noa_docker_init.sh similarity index 53% rename from noa_docker_setup.sh rename to noa_docker_init.sh index 39e25fc..684e28c 100755 --- a/noa_docker_setup.sh +++ b/noa_docker_init.sh @@ -1,15 +1,15 @@ #!/bin/sh -NOA_HOME=${HOME}/.noa - -if [ -d ${NOA_HOME}/pgdc/pgdata ]; +if [ "x$1" = "x" -o -e "$1" ]; then - echo "Noa Docker setup already exists at ${NOA_HOME}" - echo "Run noa_docker_cleanup.sh first" + echo "Provide name of a new directory to create" + echo "Usage: noa_docker_init.sh new-directory-to-create" exit 1 fi -echo "> Creating ${HOME}" +NOA_HOME="$1" + +echo "> Creating ${NOA_HOME}" mkdir -p ${NOA_HOME} mkdir -p ${NOA_HOME}/seeds @@ -23,29 +23,22 @@ echo "> Copying seed data from priv/repo" cp priv/repo/seed_data.yml ${NOA_HOME}/seeds/demo_seed_data.yml echo "> Creating an empty resource owner credential file - ro_quickstart.creds" touch ${NOA_HOME}/seeds/ro_quickstart.creds - -echo "> Bringing up Postgresql" -sudo docker-compose up -d db - -echo "> Twiddling while postgres starts up" -sleep 6 - -echo "> Bringup up Noa" -sudo docker-compose up -d noa - -echo "> Bit more twiddling" -sleep 3 +echo "> Creating docker-compose.yml" +cp docker-compose.tmpl ${NOA_HOME}/docker-compose.yml +echo "> Copying seeding script: noa_docker_seed.sh" +cp noa_docker_seed.sh ${NOA_HOME}/ +echo "> Copying README file" +cp README.tmpl ${NOA_HOME}/README.md echo "" -echo "Next Steps:" -echo "1. Goto ${NOA_HOME}/seeds" -echo "2. Edit ro_quickstart.creds file and add end user credentials one per line." -echo " Format is username:password" +echo "Next Steps: (covered in ${NOA_HOME}/README.md)" +echo "1. cd ${NOA_HOME}" +echo "2. Edit seeds/ro_quickstart.creds file and add end user credentials" +echo " one per line. Format is: username:password" echo " Make sure each is a minimum of 4 characters." echo " **Keep a copy** of this ro_quickstart.creds somewhere else" -echo " So you copy that back here next time." -echo "3. Optional. Take a look at ${NOA_HOME}/seeds/demo_seed_data.yml" +echo " so you can copy that back here next time." +echo "3. Optional. Take a look at seeds/demo_seed_data.yml" echo " Hold off on making any changes to this yet. You can try making" echo " changes after you have played with the setup." -echo "4. After you completed the above steps, come back to this directory" -echo " and run ./noa_docker_seed.sh" +echo "4. After you completed the above steps, run ./noa_docker_seed.sh" diff --git a/noa_docker_seed.sh b/noa_docker_seed.sh index 1b9935a..5619b6d 100755 --- a/noa_docker_seed.sh +++ b/noa_docker_seed.sh @@ -1,33 +1,44 @@ #!/bin/sh -NOA_HOME=${HOME}/.noa - -if [ ! -d ${NOA_HOME}/pgdc/pgdata ]; +if [ -f seed_output.txt ]; then - echo "Run noa_docker_setup.sh before using this." - echo "This is supposed to be run once after setup." + echo "noa_docker_seed.sh can be run only once." + echo "If you faced problems earlier and are trying" + echo "run again, it is better to remove this directory" + echo "and start over. Just keep a copy of seeds/ro_quickstart.creds" + echo "somewhere else you can quickly copy it over when you" + echo "start afresh. Just make sure that any partially created" + echo "Docker containers are removed." exit 1 fi +echo "> Bringing up Postgresql" +sudo docker-compose up -d db + +echo "> Twiddling while postgres starts up" +sleep 6 + +echo "> Bringup up Noa" +sudo docker-compose up -d noa + +echo "> Bit more twiddling" +sleep 5 + echo "> Performing Ecto migration" sudo docker-compose exec noa bin/noa migrate echo "> Seeding data" sudo docker-compose exec noa bin/noa seed seeds/demo_seed_data.yml > \ - ${NOA_HOME}/seed_output.txt + seed_output.txt echo "> Done. Hopefully things worked without any issues!" -echo "> The seed results are made available in" -echo "> ${NOA_HOME}/seed_output.txt file. Keep this file." -echo "> You will need it later." echo "" echo "Next Steps:" -echo "1. Run: sudo docker-compose down" -echo "2. Bring it back up again: sudo docker-compose up -d" -echo " Noa should be up and running. Confirm this." -echo "3. Run: sudo docker-compose logs noa" +echo "1. Run: sudo docker-compose logs noa" echo " You should see that Phoenix is listening on port 4000" -echo "4. Time to fire up Noa Playground to checkout your own OAuth2 server" +echo "2. Keep the generated seed_output.txt file. It has information" +echo " you need to work with Noa." +echo "3. Time to fire up Noa Playground to checkout your own OAuth2 server." echo " Head over to https://github.com/handnot2/noa_playground" echo " for further instructions on Noa Playground." echo "" @@ -35,4 +46,4 @@ echo "At this point you can use the standard docker-compose commands" echo "to work with this setup." echo "" echo "If you want to stop Noa, just run: sudo docker-compose down." -echo "Use ./noa_docker_cleanup.sh to wipe off this Noa setup." +echo "If you want to wipe off this setup use sudo rm -rf shell command."