Skip to content

Commit

Permalink
feat(http): support SSL certificate authentication
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
stevenmathews authored and staltz committed Oct 27, 2016
1 parent 1e9ee15 commit b3f841c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions http/README.md
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions http/src/http-driver.ts
Expand Up @@ -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);
}
Expand Down
6 changes: 6 additions & 0 deletions http/src/interfaces.ts
Expand Up @@ -4,6 +4,11 @@ export interface Attachment {
filename?: string;
}

export interface AgentOptions {
key: string;
cert: string;
}

export interface RequestOptions {
url: string;
method?: string;
Expand All @@ -17,6 +22,7 @@ export interface RequestOptions {
field?: Object;
progress?: boolean;
attach?: Array<Attachment>;
agent?: AgentOptions;
withCredentials?: boolean;
redirects?: number;
category?: string;
Expand Down

0 comments on commit b3f841c

Please sign in to comment.