I have users who SSO with Azure AD. The users receive a SAML token at the end of that exchange. I now want the users to access an authenticated API on API gateway. Is there anyway i can make use of the existing SAML token? How can i make this work?
Sure - you use Cognito as your authenticator, which supports SAML. Check here for an example:
https://github.com/aws-samples/amazon-cognito-example-for-external-idp
Well thats the problem. The application ALREADY uses SSO with AAD. we have now developed the API on API GW and need to use the already existing SAML token to authenticate the user on API GW. Im trying to avoid changing how the application works currently.
/u/coinclink I just noticed this is something you may have dealt with? Did you find a solution to this?
You can configure API Gateway to use a custom authorizer instead of using Cognito. My team created a custom Lambda authorizer that handles the validation of the an auth token manually in code.
SOrry for the dumb question, but if i have received a SAML response from AAD, will i be able to access it to send it to a different domain (API Gateway)? Wont that violate the same origin policy?
If the application itself is already validating the token, just turn off all of the API gateway Auth features and let your app take care of it. Set up a greedy proxy rule so that everything goes though to your app for any method and any path. I have done this myself with c# (which I assume you are using).
what you are looking for is to validate that the saml token given to you is valid.
if you know how to decode the token, then i would do this via an authorizer lambda attached to your apigateway endpoint. you can validate the token from there. (you do not need cognito to do this)
No, you can’t use saml without cognito. What you can do is openid connect against AAD at api gateway. It will be seamless for your users . ( Technically they’ll authenticate twice , but that doesn’t mean that they will see login prompts )
I think this is the way. Once you get the response from the IdP, You can use a “request parameter-based” lambda authorizer like SAML redirect bindings. Then use some custom code to validate the SAML response.
https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-use-lambda-authorizer.html
If you want make sure the SAML documents are proper (i feel like no one does! Lol), you should be able to add your api as an “audience” in AD. This is an array of urls or entity ids that include the sites that can utilize that response for authorization.
Ok, if you already have authentication code that your app uses, and you can reuse for your API, then do as others suggested and use a custom Lambda authorizer to leverage it. If you didn’t have that authentication code then you could plug in Cognito to provide it. That wasn’t something you mentioned in your original post.
I don’t think you’ll be able to use the same exact token but you can almost certainly use your Azure AD SAML Identity Provider to log into your API. It’s not trivial and will require some custom coding for your app, but you’re trying to enable IdP Initiated Login. For Service Provider initiated, you would have to use something like Cognito.
These blog posts are a good starting point. They use MS ADFS and JavaScript, but the concepts are all the same for any SAML IdP or coding language.
https://aws.amazon.com/blogs/compute/saml-for-your-serverless-javascript-application-part-i/
https://aws.amazon.com/blogs/compute/saml-for-your-serverless-javascript-application-part-ii/