We are currently building a web app using a full serverless stack on AWS. So far we have been very successful using AWS Lambda, AWS DynamoDB and Cognito User Pools. This application is intended to be an enterprise application and one of my clients wants to be able to log all users in using their current Active Directory credentials. I have used AD FS in the past on other applications but it has always turned out to be a bit of a hack to get it working.
Now, I want to send the customer instructions on how to configure their AD FS relying party trust to authenticate against my application.
I have read that the best way to do this is to create a Cognito Identity Provider that links to a Cognito User Pool. In the User Pool you should create a SAML provider and upload the metadata.xml from the AD FS server.
I have set up a lab server with AD FS and I can get that working. Now I am not sure what I am doing wrong in terms of the Relying Party Trust setup or the Cognito setup. I have been at this for ages and read just about every blog article I can find. If anyone can help me out or point me in the right direction that would be greatly appreciated.
Amazon Cognito allows you to use groups to create a collection of users, which is often done to set the permissions for those users. In this post, I show you how to build fine-grained authorization to protect your APIs using Amazon Cognito, API Gateway, and AWS Identity and Access Management (IAM).
Go to AWS Cognito service and click “Manage Identity Pools”. 2. Enter “Identity pool name”, expand the “Authentication providers” section and select “Cognito” tab. This is where the Cognito authentication provider will be registered with the Identity pool.
After much frustration, I can now answer this question so I decided to put together an easy step-by-step answer for beginners with these struggles.
I am only going into the authentication setup and not the authorisation. Authorisation requires IAM roles and some other logic that is architecture specific. I'm happy to discuss that elsewhere.
There are 2 components to this kind of a setup:
In the Cognito User Pool under General Settings, select App clients and add one if there are none (you will need the ID later).
Then go to Domain Name under App Integration and choose a valid domain prefix and save it.
You will need to get the company to setup a relying party trust. The steps required are as follows:
https://<domain_prefix>.auth.<region>.amazoncognito.com/saml2/idpresponse
(domain prefix is set in the previous step)urn:amazon:cognito:sp:<pool-id>
where pool-id
is the AWS Cognito User Pool id found in the General Settings of the user poolNow you need to add claims to the relying party trust.
So as the application developer, you need to setup the Cognito User pool. Go through the wizard and choose your prefered settings. The federated identities don't necessarily play by the same rules as the user pool itself anyway.
The steps to setup the federated identity are:
https://<fqdn>/FederationMetadata/2007-06/FederationMetadata.xml
). If you can't then download that file and upload it by clicking "Select File"The last step before testing is to setup the app client that you created earlier.
To test, you can try a few different URLs in the form of: -
https://<domain_prefix>.auth.<region>.amazoncognito.com/authorize?idp_identifier=<idp_identifier>&response_type=token&client_id=<app_client_id>&redirect_uri=<app_client_callback_URL>
to go directly to the authorize endpointhttps://<domain_prefix>.auth.<region>.amazoncognito.com/login?response_type=token&client_id=<app_client_id>&redirect_uri=<app_client_callback_URL>
to go to the AWS hosted login UIThe idp_identifier
is the optional field defined when creating the federated identity. This is not required in the URL either.
This one page webapp is a good tool to use to test that things are working and you are getting the desired response.
I hope this helps other people.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With