From b3f841cd991b643b454b73be4576e828c6d59a13 Mon Sep 17 00:00:00 2001 From: Steve Date: Tue, 18 Oct 2016 15:56:59 +1300 Subject: [PATCH] feat(http): support SSL certificate authentication You can now pass an agent object on a request with the properties "key" and "cert". These will be passed to superagent. This feature is primarily useful on Node.js servers. --- http/README.md | 2 ++ http/src/http-driver.ts | 4 ++++ http/src/interfaces.ts | 6 ++++++ 3 files changed, 12 insertions(+) diff --git a/http/README.md b/http/README.md index 2f4bdaf40..cc21f98a6 100644 --- a/http/README.md +++ b/http/README.md @@ -174,6 +174,8 @@ on the response Observable. `path`, and `filename` of a resource to upload. - `withCredentials` *(Boolean)*: enables the ability to send cookies from the origin. +- `agent` *(Object)*: an object specifying `cert` and `key` for SSL certificate +authentication. - `redirects` *(Number)*: number of redirects to follow. - `lazy` *(Boolean)*: whether or not this request runs lazily, which means the request happens if and only if its corresponding response stream from the diff --git a/http/src/http-driver.ts b/http/src/http-driver.ts index 02199b2c5..f5a1b0902 100644 --- a/http/src/http-driver.ts +++ b/http/src/http-driver.ts @@ -45,6 +45,10 @@ export function optionsToSuperagent(rawReqOptions: RequestOptions) { if (reqOptions.withCredentials) { request = request.withCredentials(); } + if (reqOptions.agent) { + request = request.key(reqOptions.agent.key); + request = request.cert(reqOptions.agent.cert); + } if (typeof reqOptions.user === 'string' && typeof reqOptions.password === 'string') { request = request.auth(reqOptions.user, reqOptions.password); } diff --git a/http/src/interfaces.ts b/http/src/interfaces.ts index 343e5dfae..b020145f5 100644 --- a/http/src/interfaces.ts +++ b/http/src/interfaces.ts @@ -4,6 +4,11 @@ export interface Attachment { filename?: string; } +export interface AgentOptions { + key: string; + cert: string; +} + export interface RequestOptions { url: string; method?: string; @@ -17,6 +22,7 @@ export interface RequestOptions { field?: Object; progress?: boolean; attach?: Array; + agent?: AgentOptions; withCredentials?: boolean; redirects?: number; category?: string;