HttpOnly Cookies with AWS Cognito
Asked Answered
P

4

6

I am using the amazon-cognito-identity-js SDK for user authentication. The CookieStorage object only takes domain, path, expires, and secure configurations. Is it possible to configure the authentication response to set the tokens in an HttpOnly cookie?

Pettaway answered 24/4, 2018 at 20:10 Comment(1)
I'd ask an open question like "how can I...." Otherwise people may answer with just 'yes'Prent
Q
2

You can set HttpOnly cookie via express js or any other server.

I created a wrapper, an "identity service" sor of for AWS Cognito, that returns HttpOnly Cookies, it is easily achieveable since cognito comes with jwt authentication out of the box.

Note that the project was originally created to support, nuxt/next js in case you want other structure just change the endpoints. https://github.com/cnikolov/aws-cognito-http

Quotha answered 15/2, 2021 at 11:54 Comment(0)
Q
1

See Set a cookie to HttpOnly via Javascript. It is not possible for JavaScript to set httpOnly cookies, so amazon-cognito-identity-js can't do that either.

If you use the hosted sign-in/up pages, then Cognito will put httpOnly cookies on your client (server side). But those cookies don't contain JWT's.

Quarterback answered 29/12, 2018 at 13:12 Comment(0)
G
1

Found this, from the discussion it looks like httpOnly cookies are not something AWS Cognito currently supports (which is really surprising)

https://github.com/aws-amplify/amplify-js/issues/3224

Note: the discussion is around AWS amplify but httpOnly cookies can only be set by the server for the client, so it shouldn't matter what client library is being used.

Giorgia answered 21/7, 2020 at 21:33 Comment(0)
G
0

You might find my official AWS blog post helpful: Reduce risk by implementing HttpOnly cookie authentication in Amazon API Gateway

It's also using Amazon Cognito.

Gigue answered 2/3, 2023 at 8:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.