signer.d.ts 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. export class Signer {
  2. /**
  3. * A signer object can be used to generate signed URLs and cookies for granting access to content on restricted CloudFront distributions.
  4. *
  5. * @param {string} keyPairId - The ID of the CloudFront key pair being used.
  6. * @param {string} privateKey - A private key in RSA format.
  7. */
  8. constructor(keyPairId: string, privateKey: string);
  9. /**
  10. * Create a signed Amazon CloudFront Cookie.
  11. */
  12. getSignedCookie(options: Signer.SignerOptionsWithPolicy): Signer.CustomPolicy;
  13. /**
  14. * Create a signed Amazon CloudFront Cookie.
  15. */
  16. getSignedCookie(options: Signer.SignerOptionsWithoutPolicy): Signer.CannedPolicy;
  17. /**
  18. * Create a signed Amazon CloudFront Cookie.
  19. */
  20. getSignedCookie(options: Signer.SignerOptionsWithPolicy, callback: (err: Error, cookie: Signer.CustomPolicy) => void): void;
  21. /**
  22. * Create a signed Amazon CloudFront Cookie.
  23. */
  24. getSignedCookie(options: Signer.SignerOptionsWithoutPolicy, callback: (err: Error, cookie: Signer.CannedPolicy) => void): void;
  25. /**
  26. * Create a signed Amazon CloudFront URL.
  27. * Keep in mind that URLs meant for use in media/flash players may have different requirements for URL formats (e.g. some require that the extension be removed, some require the file name to be prefixed - mp4:, some require you to add "/cfx/st" into your URL).
  28. */
  29. getSignedUrl(options: Signer.SignerOptionsWithPolicy | Signer.SignerOptionsWithoutPolicy): string;
  30. /**
  31. * Create a signed Amazon CloudFront URL.
  32. * Keep in mind that URLs meant for use in media/flash players may have different requirements for URL formats (e.g. some require that the extension be removed, some require the file name to be prefixed - mp4:, some require you to add "/cfx/st" into your URL).
  33. */
  34. getSignedUrl(options: Signer.SignerOptionsWithPolicy| Signer.SignerOptionsWithoutPolicy, callback: (err: Error, url: string) => void): void;
  35. }
  36. declare namespace Signer {
  37. export interface SignerOptionsWithPolicy {
  38. /**
  39. * A CloudFront JSON policy. Required unless you pass in a url and an expiry time.
  40. */
  41. policy: string;
  42. }
  43. export interface SignerOptionsWithoutPolicy {
  44. /**
  45. * The URL to which the signature will grant access. Required unless you pass in a full policy.
  46. */
  47. url: string
  48. /**
  49. * A Unix UTC timestamp indicating when the signature should expire. Required unless you pass in a full policy.
  50. */
  51. expires: number
  52. }
  53. export interface CustomPolicy {
  54. "CloudFront-Policy": string;
  55. "CloudFront-Key-Pair-Id": string;
  56. "CloudFront-Signature": string;
  57. }
  58. export interface CannedPolicy {
  59. "CloudFront-Expires": number;
  60. "CloudFront-Key-Pair-Id": string;
  61. "CloudFront-Signature": string;
  62. }
  63. }