lab06 : Spring Boot OAuth Hello World

num ready? description assigned MW lect due MW lect assigned TR lect due TR lect
lab06 true Spring Boot OAuth Hello World Wed 02/05 12:30PM Thu 02/13 11:59PM Tue 02/04 05:00PM Thu 02/13 11:59PM

Look here for formatted version: http://ucsb-cs56.github.io/w20/lab/lab06

This is an individual lab on the topic of Java web apps on Heroku.

You may cooperate with one or more pair partners from your team to help in debugging and understanding the lab, but each person should complete the lab separately for themselves.

What are we trying to accomplish again in this lab?

See lab02 for information about Heroku.

If you are working on your own machine, revisit lab02 for software that you will need on your machine (Maven and the Heroku CLI).

Step 1: Create your repo

Create a new repo

Clone that repo somewhere and cd into.

Then add this remote:

git remote add starter https://github.com/ucsb-cs56-w20/STARTER_lab06

Then do:

git pull starter master
git push origin master

Step 2: Get OAuth working on Localhost

  1. You must first configure a GitHub OAuth app for http://localhost:8080 and obtain the client-id and client-secret.

    Follow the instructions here: https://ucsb-cs56.github.io/topics/oauth_github_setup.

  2. You must then copy the file localhost.json.SAMPLE to the file localhost.json.

    • Note that you SHOULD NOT edit localhost.json.SAMPLE directly.
    • The copied file localhost.json will NOT be commited to GitHub; it’s in the .gitignore
  3. Then, edit the localhost.json file and put in your client id and client secret in the places indicated.

  4. Finally, IN EACH terminal session where you are going to run mvn spring-boot:run, and EACH TIME after you change the values in localhost.json, execute this command to load those values into the Unix environment:

    . env.sh
    

    That’s a dot followed by a space followed by env.sh, not a typo. That means to source the contents of env.sh into the current shell. That loads the contents of localhost.json into the environment variable SPRING_APPLICATION_JSON, which causes those values to override those in the application.properties file.

  5. Now you are ready to do mvn spring-boot:run as usual, and see the application on http://localhost:8080.

    Try logging in with your GitHub account.

Step 3: Get OAuth working on Heroku

To run on Heroku, you must go BACK to GitHub and set up a DIFFERENT client id and client secret than the one you used for localhost.

  1. Go to the heroku.com dashboard and create a new Heroku app with the name cs56-w20-lab06-githubid, replacing githubid with your github id.

    If that name is too long, abbreviate as needed.

  2. Now you must create an GitHub OAuth app for cs56-w20-lab06-githubid.herokuapp.com and obtain the client-id and client-secret.

    Follow the instructions here: https://ucsb-cs56.github.io/topics/oauth_github_setup.

    In the urls below, substitute your actual Heroku app name in place of cs56-w20-lab06-githubid—if you shortened it in the step above, you need to be sure that what you put in matches your shortened name. Do not literally put in githubid.

    • For the application url, use cs56-w20-lab06-githubid.herokuapp.com
    • For the callback url, also use cs56-w20-lab06-githubid.herokuapp.com
    • Note that on Heroku, you typically need use https not http
  3. You must then copy the file heroku.json.SAMPLE to the file heroku.json.

    • Note that you SHOULD NOT edit heroku.json.SAMPLE directly.
    • The copied file heroku.json will NOT be commited to GitHub; it’s in the .gitignore
  4. Then, edit the heroku.json file and put in your client id and client secret in the places indicated.

  5. Now, you need either to be logged into CSIL where you can run the heroku command line tool, or you need the heroku command line (CLI) installed on your local system.

    Use heroku login to login to the command line tool.

    The run the following script from the repo. You need to do this in the same directory where you entered the client id and client secret values into the heroku.json file.

    The name of the Heroku app should match yours (e.g. change githubid to your githubid)

    ./setHerokuEnv.py –app cs56-w20-lab06-githubid

    • Note that it may be difficult to read, but –app is two hyphens followed by app
    • You can also just use -a which is a single hyphen followed by the letter a

    You should now be able to go to the Heroku Dashboard for your app online, e.g. this link (replacing app-name-here with your appname, e.g. cs56-w20-lab06-githubid)

    Click “Reveal Config Vars”. You should see a configuration variable called SPRING_APPLICATION_JSON that contains the values that you entered for client id and client secret (i.e the contents of heroku.json).

  6. Now you are ready to do the steps you did in lab02 to connect your Heroku App to your Github repo, and deploy your app to Heroku and see it running.

    Try logging in with your github account.

If you get all of that running, you are done with lab06, with the exception of doing some documentation on your links on Gauchospace (as you did for lab02.)

Lab06 only requires you to get this up and running on Heroku and gets you used to configuring an OAuth app.

The next Spring Boot labs will move us into working with APIs and creating database tables.

Step 4: Submitting your work for grading

When you have a running web app that you can login to and logout from, visit https://gauchospace.ucsb.edu/courses/mod/assign/view.php?id=3183791 and make a submission.

In the text area, enter something like this, substituting your repo name and your Heroku app name:

repo name: https://github.com/chrislee123/spring-boot-minimal-webapp
on heroku: https://cs56-w20-lab06-chrislee123.herokuapp.com

Then, and this is super important, please make both of those URLs clickable urls.

The instructions for doing so are here: https://ucsb-cs56.github.io/topics/gauchospace_clickable_urls/

Grading Rubric: