Purchase
. Click Create Resource.
Add an OPTIONS method for the purchase
resource as outlined previously for pets
in the Set Up Cors and Deploy the API section of Step 2 - Securing and Deploying the Amazon API Gateway.
Create a new AWS Lambda function for purchasing a pet called PetPurchase
, which adds isSold
and soldTo
attributes to a pet as follows:
purchase
resource that calls the PetPurchase
Lambda. Be sure to also add the Access-Control-Allow-Origin
header with a value of *
to the POST method using the method response/integration response configuration found in Set Up Cors and Deploy the API section of Step 2 - Securing and Deploying the Amazon API Gateway.
Test the API gateway method, providing the following as an input message:
auth0-api-social-role
.
The ARN for the method you will secure in the IAM policy should look something like:
/pets/purchase
resource. Select Method Request and change Authorization Type to AWS_IAM. Click the check to save the setting.
At this point, you have defined two roles that you can use with the API gateway:
auth0-api-role
: permits updating petsauth0-api-social-role
: permits purchasing a petClient ID
and Client Secret
from your social identity provider, select the Attributes (and Permissions, where applicable), and click Save.https://johndoe.auth0.com/login/callback
. The Auth0 help page will show you specifically what to enter.
Navigate to Auth0 Dashboard > Applications > Applications, and select your Application to view its settings. Select the Connections view, locate the Social section, and ensure that Amazon is enabled.
pets
folder, as well as your Amazon S3 bucket.
getOptionsForRole
to select different roles for different users. When you obtain the delegation token, you can tell Auth0 which role to use (that is, the user is an admin or not).
In the pets/login/login.js
file, modify the role
and principal
values for the non-admin user for the social user IAM role you just created.
At this point, you should be able to log in using Amazon credentials or the database user you previously created. Notice that the UI lets a social user buy pets, while an admin user can add and remove pets.
To test this functionality, you can temporarily hide the remove button in the UI by removing ng-show="isAdmin"
in /pets/home/home.html
:
home.js
, modify the buyPet
function to enable pet purchases: