This feature uses delegation. By default, delegation is disabled for tenants without an add-on in use as of 8 June 2017. Legacy tenants who currently use an add-on that requires delegation may continue to use this feature. If delegation functionality is changed or removed from service at some point, customers who currently use it will be notified beforehand and given ample time to migrate. In addition, note that delegation does not support the use of custom domains so any features depending on it may not be fully functional alongside a custom domain.
Step 3 - Build the Application
In this step, you will build a single-page, serverless application using the AngularJS framework that you will serve out of an AWS S3 bucket configured to act as a static website.Step 1. Set Up Your Sample Application
For a simple starter app, download a sample project specific to this tutorial to get started. Log In to have your Auth0 credentials preconfigured. Copy the contents of this seed project to a local folder calledpets, which you will be using for the remainder of this tutorial. Within this folder, update auth0-variables.js with your Auth0 Application AUTH0_CLIENT_ID and AUTH0_CLIENT_ID (this information is available in the Management Dashboard for the application in question).
AWS S3 bucket
Be sure that you have created the AWS S3 bucket configured to act as a static website. During the setup process, copy the contents of thepets folder to your S3 bucket to provide content for the website.
If you are using a pre-existing bucket, you can move the files with the AWS CLI using the following command.
http://your-bucket.s3-website-us-east-1.amazonaws.com
If you don’t know what your URL is, you can find it listed under the Properties tab of your S3 bucket.
Before going further, test logging into your application. Open http://your-bucket-domain/index.html in your browser. After logging in, you should see an alert box pop up that says “getPets not implemented”:
You should also see the page for viewing pets.
Use Delegation to Get an AWS Token
At this point, you have authentication set up with Auth0, and you have an . Here is the directory structure for the generated code:
pets/login/login.js as follows to get an AWS delegation token from the identity token after a successful signin with auth.signin. Note that you are treating any user not logged in using a Social Connection as an admin. Later, we’ll code a second role and show better ways to enforce role selection.
Modify the role and principal Strings
To modify therole and principal strings (which are the final two lines of the if statement contained in the provided function), specify the appropriate values via Rules:
role and [principal] ARN values with the ones for your integration.
Copy the updated files to your S3 bucket for your website.
Optionally, you can set a breakpoint in the browser at store.set('awstoken', delegation.Credentials);. When you log out and and log back in, inspect delegation.Credentials when you arrive at the breakpoint. You will see a familiar values like AccessKeyId and SecretAccessKey:
Display Pets with the AWS API Service
The first thing you will do is show the pets to the end users.Add the API Code to Call Your API
To add the API code for adding a call to your service, copy the contents of apiGateway-js-sdk.zip you previously downloaded to thepets directory. The contents should include:
apiClient.js;libfolder;README.md.
README.md in the pets directory, so you will need to rename one of the files to keep both in the directory. The README.md for the API gateway explains how to use the API application from your Auth0 Application.
Open the index.html file located in the root of your pets folder to add all of the scripts listed at the top of the API readme to index.html:
apigClient.js, you can see that the downloaded library has created wrappers like petsPost and petsGet for your API methods. You do not need to modify this generated code.
Configure the getPets Method
Openhome.js in the home folder, and update the contents of getPets with a method for retrieving pets data (be sure to update the region if you are not running in us-east-1):
Update Pets with the AWS API Service
Now that you have a working Auth0 Application with the API Gateway, you will add a method for updating thepets table.
Modify the putPets method logic to update pets using your API function. This function will be used for both adding and removing pets.
- Log out and log back in.
- Enter in values for
Pet TypeandPet Price. - Click Save to post your data.
<Pet Type> for sale for <Pet Price>” with a red REMOVE button to its left.
To add security, add the getSecureApiClient function at the start of the putPets method:
getSecureApiClient function provided for you retrieves the AWS token from local storage acquired using delegation to the API, and uses the access key, secret, and session token: