Elli middleware to manage CloudFront signed cookies.
rebar3 compile
# rebar3 compile
lfe priv/example.lfe
HTTP/1.1 302 Found
Date: Wed, 30 Mar 2016 01:02:46 GMT
Expires: Wed, 30 Mar 2016 02:02:46 GMT
Location: https://d123456789abcde.cloudfront.net
Set-Cookie: CloudFront-Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiaHR0cDovL2V4YW1wbGUuY29tLyoiLCJDb25kaXRpb24iOnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjE0NTkyODUzNjZ9fX1dfQ__
Set-Cookie: CloudFront-Signature=QgpGJ04j48DNbLdaC5bRJBQNzwPSQvtkY-y-VosdRaQ0RS5yLd~JA34VD~G5OsroUJPNChN4ptCTFPfdEazcxbmrAfHvpY~NW-3UWXJYqQ~8ZqnOApUnoooH89T~6N8ul4Ss1y6bSFH9pAq2MQVELupmtW359hd~-4oC7kKJrP-4TJrrGA6OwNQ-~JKRDpapA0E8OR8Ns-8OOh3FUQruwrWuR6edZUuq02WvhyNLVkLE8O5avLl7EwVNSx2bNXkTrIsI4gGB7sBOFbaW62RkSb~dmYu~Db06ytzYfW61R49WkXzAVgzsu2SDsI6KMX6jayA9UTnt40OFgbuQZkE34g__
Set-Cookie: CloudFront-Key-Pair-Id=AKEXAMPLE123
(defmodule example-cf-handler
(behaviour elli_cloudfront_handler)
;; elli_cloudfront_handler callbacks
(export (is_authorized 3)
(store_ticket 2) (validate_ticket 2) (delete_ticket 1)))
;; Defines #ticket{} and includes elli.hrl
(include-lib "elli_cloudfront/include/elli_cloudfront.hrl")
(defun is_authorized (_req _service _args)
;; TODO:
;; - Parse req for user info
;; - Confirm or deny user is authorized to view service
;; - Return a user id
#(ok #"USERID"))
(defun store_ticket (_user _ticket)
;; TODO: Store user's ticket
'ok)
(defun validate_ticket (_req _token)
;; TODO:
;; - Parse req for user info
;; - Fetch ticket by token
;; - Confirm or deny that it belongs to the user
;; - Return the "service" associated with the ticket
#(ok #"https://d123456789abcde.cloudfront.net"))
(defun delete_ticket (_token)
;; TODO: Delete the ticket with the given token
'ok)