add options to request.auth method (#27373)

This commit is contained in:
Adam Haglund 2018-07-21 02:50:03 +02:00 committed by Wesley Wigham
parent a43c276f2b
commit 1d4e623ccb
2 changed files with 20 additions and 2 deletions

View File

@ -5,6 +5,7 @@
// Pap Lőrinc <https://github.com/paplorinc>
// Shrey Jain <https://github.com/shreyjain1994>
// Alec Zopf <https://github.com/zopf>
// Adam Haglund <https://github.com/beeequeue>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
@ -118,7 +119,8 @@ declare namespace request {
abort(): void;
accept(type: string): this;
attach(field: string, file: MultipartValueSingle, options?: string | { filename?: string; contentType?: string }): this;
auth(user: string, name: string): this;
auth(user: string, pass: string, options?: { type: 'basic' | 'auto' }): this;
auth(token: string, options: { type: 'bearer' }): this;
buffer(val?: boolean): this;
ca(cert: Buffer): this;
cert(cert: Buffer | string): this;

View File

@ -230,13 +230,29 @@ const reqCookies: string = req.cookies;
console.log(`${reqMethod} request to ${reqUrl} cookies ${reqCookies}`);
// Basic authentication
// Authentication
request.get('http://tobi:learnboost@local').end(callback);
request
.get('http://local')
.auth('tobo', 'learnboost')
.end(callback);
request
.get('http://local')
.auth('user', 'pass', { type: 'basic' })
.end(callback);
request
.get('http://local')
.auth('user', 'pass', {type: 'auto'})
.end(callback);
request
.get('http://local')
.auth('abearertoken', { type: 'bearer' })
.end(callback);
// Following redirects
request
.get('/some.png')