[simple-oauth2] Allow http options for getToken (#39940)

* [simple-oauth2] Allow http options for getToken

According to the docs of simple-oauth2 the getToken function optionally accepts an httpOptions object:
https://www.npmjs.com/package/simple-oauth2#authorization-code-flow

```
// Optional per-call http options
const httpOptions = {};
 
// Save the access token
try {
  const result = await oauth2.authorizationCode.getToken(tokenConfig, httpOptions);
  const accessToken = oauth2.accessToken.create(result);
} catch (error) {
  console.log('Access Token Error', error.message);
}
```

* [simple-oauth2] Allow scope in getToken config

According to the docs of simple-oauth2 a scope property is allowed:
https://www.npmjs.com/package/simple-oauth2#authorization-code-flow

```
// Get the access token object (the authorization code is given from the previous step).
const tokenConfig = {
  code: '<code>',
  redirect_uri: 'http://localhost:3000/callback',
  scope: '<scope>', // also can be an array of multiple scopes, ex. ['<scope1>, '<scope2>', '...']
};
 
// Optional per-call http options
const httpOptions = {};
 
// Save the access token
try {
  const result = await oauth2.authorizationCode.getToken(tokenConfig, httpOptions);
  const accessToken = oauth2.accessToken.create(result);
} catch (error) {
  console.log('Access Token Error', error.message);
}
```

* [simple-oauth2] Fix missing type for scope

* [simple-oauth2] Add http options to all func

* [simple-oauth2] Update interface for WreckHttpOptions

* [simple-oauth2] bump version to trigger rebuild

* [simple-oauth2] Fix build errors

Error in simple-oauth2
Error: /home/travis/build/DefinitelyTyped/DefinitelyTyped/types/simple-oauth2/index.d.ts:1:25
ERROR: 1:25    dt-header                        Error parsing header. Expected: foo MAJOR.MINOR (patch version not allowed). See: https://github.com/Microsoft/dtslint/blob/master/docs/dt-header.md
ERROR: 97:11   strict-export-declare-modifiers  All declarations in this module are exported automatically. Prefer to explicitly write 'export' for clarity. If you have a good reason not to export this declaration, add 'export {}' to the module to shut off automatic exporting. See: https://github.com/Microsoft/dtslint/blob/master/docs/strict-export-declare-modifiers.md
ERROR: 99:13   typedef-whitespace               expected nospace before colon in property-declaration
ERROR: 110:10  no-any-union                     Including `any` in a union will override all other members of the union. See: https://github.com/Microsoft/dtslint/blob/master/docs/no-any-union.md
This commit is contained in:
Bert Verhelst
2019-11-05 01:35:00 +01:00
committed by Nathan Shively-Sanders
parent b4f18cc47a
commit c21ee1885d

View File

@@ -1,4 +1,4 @@
// Type definitions for simple-oauth2 2.2
// Type definitions for simple-oauth2 2.5
// Project: https://github.com/lelylan/simple-oauth2
// Definitions by: Michael Müller <https://github.com/mad-mike>,
// Troy Lamerton <https://github.com/troy-lamerton>
@@ -76,6 +76,8 @@ export interface AuthorizationTokenConfig {
code: AuthorizationCode;
/** A string that represents the callback uri */
redirect_uri: string;
/** A string or array of strings that represents the application privileges */
scope: string | string[];
}
export interface PasswordTokenConfig {
@@ -92,6 +94,27 @@ export interface ClientCredentialTokenConfig {
scope?: string | string[];
}
export interface WreckHttpOptions {
baseUrl?: string;
socketPath?: string;
payload?: any;
headers?: { [key: string]: any };
redirects?: number;
redirect303?: boolean;
beforeRedirect?: (redirectMethod: string, statusCode: number, location: string, resHeaders: { [key: string]: any }, redirectOptions: any, next: () => {}) => void;
redirected?: (statusCode: number, location: string, req: any) => void;
timeout?: number;
maxBytes?: number;
rejectUnauthorized?: boolean;
downstreamRes?: any;
agent?: any;
secureProtocol?: string;
ciphers?: string;
events?: boolean;
json?: true | "strict" | "force";
gunzip?: boolean | "force";
}
export interface OAuthClient<ClientIdName extends string = 'client_id'> {
authorizationCode: {
/**
@@ -113,21 +136,21 @@ export interface OAuthClient<ClientIdName extends string = 'client_id'> {
): string,
/** Returns the Access Token object */
getToken(params: AuthorizationTokenConfig): Promise<Token>;
getToken(params: AuthorizationTokenConfig, httpOptions?: WreckHttpOptions): Promise<Token>;
};
ownerPassword: {
/** Returns the Access Token Object */
getToken(params: PasswordTokenConfig): Promise<Token>;
getToken(params: PasswordTokenConfig, httpOptions?: WreckHttpOptions): Promise<Token>;
};
clientCredentials: {
/** Returns the Access Token Object */
getToken(params: ClientCredentialTokenConfig): Promise<Token>;
getToken(params: ClientCredentialTokenConfig, httpOptions?: WreckHttpOptions): Promise<Token>;
};
accessToken: {
/** Creates an OAuth2.AccessToken instance */
create(tokenToUse: Token): AccessToken;
create(tokenToUse: Token, httpOptions?: WreckHttpOptions): AccessToken;
};
}