1 |
|
2 | import * as http from 'http';
|
3 | import { AsyncCreatable } from '@salesforce/kit';
|
4 | import { OAuth2Options } from 'jsforce';
|
5 | import { AuthInfo } from './authInfo';
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | export declare class WebOAuthServer extends AsyncCreatable<WebOAuthServer.Options> {
|
23 | static DEFAULT_PORT: number;
|
24 | private authUrl;
|
25 | private logger;
|
26 | private webServer;
|
27 | private oauth2;
|
28 | private oauthConfig;
|
29 | constructor(options: WebOAuthServer.Options);
|
30 | /**
|
31 | * Returns the configured oauthLocalPort or the WebOAuthServer.DEFAULT_PORT
|
32 | *
|
33 | * @returns {Promise<number>}
|
34 | */
|
35 | static determineOauthPort(): Promise<number>;
|
36 | |
37 |
|
38 |
|
39 |
|
40 |
|
41 | getAuthorizationUrl(): string;
|
42 | |
43 |
|
44 |
|
45 |
|
46 |
|
47 | authorizeAndSave(): Promise<AuthInfo>;
|
48 | |
49 |
|
50 |
|
51 | start(): Promise<void>;
|
52 | protected init(): Promise<void>;
|
53 | |
54 |
|
55 |
|
56 |
|
57 |
|
58 | private executeOauthRequest;
|
59 | |
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 | private parseAuthCodeFromRequest;
|
67 | |
68 |
|
69 |
|
70 |
|
71 |
|
72 | private closeRequest;
|
73 | |
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 | private validateState;
|
80 | }
|
81 | export declare namespace WebOAuthServer {
|
82 | interface Options {
|
83 | oauthConfig: OAuth2Options;
|
84 | }
|
85 | type Request = http.IncomingMessage & {
|
86 | query: {
|
87 | code: string;
|
88 | state: string;
|
89 | };
|
90 | };
|
91 | }
|
92 |
|
93 |
|
94 |
|
95 | export declare class WebServer extends AsyncCreatable<WebServer.Options> {
|
96 | static DEFAULT_CLIENT_SOCKET_TIMEOUT: number;
|
97 | server: http.Server;
|
98 | port: number;
|
99 | host: string;
|
100 | private logger;
|
101 | private sockets;
|
102 | constructor(options: WebServer.Options);
|
103 | /**
|
104 | * Starts the http server after checking that the port is open
|
105 | */
|
106 | start(): Promise<void>;
|
107 | /**
|
108 | * Closes the http server and all open sockets
|
109 | */
|
110 | close(): void;
|
111 | /**
|
112 | * sends a response error.
|
113 | *
|
114 | * @param statusCode he statusCode for the response.
|
115 | * @param message the message for the http body.
|
116 | * @param response the response to write the error to.
|
117 | */
|
118 | sendError(status: number, message: string, response: http.ServerResponse): void;
|
119 | /**
|
120 | * sends a response redirect.
|
121 | *
|
122 | * @param statusCode the statusCode for the response.
|
123 | * @param url the url to redirect to.
|
124 | * @param response the response to write the redirect to.
|
125 | */
|
126 | doRedirect(status: number, url: string, response: http.ServerResponse): void;
|
127 | /**
|
128 | * sends a response to the browser reporting an error.
|
129 | *
|
130 | * @param error the error
|
131 | * @param response the response to write the redirect to.
|
132 | */
|
133 | reportError(error: Error, response: http.ServerResponse): void;
|
134 | protected init(): Promise<void>;
|
135 | /**
|
136 | * Make sure we can't open a socket on the localhost/host port. It's important because we don't want to send
|
137 | * auth tokens to a random strange port listener. We want to make sure we can startup our server first.
|
138 | *
|
139 | * @private
|
140 | */
|
141 | private checkOsPort;
|
142 | /**
|
143 | * check and get the socket timeout form what was set in process.env.SFDX_HTTP_SOCKET_TIMEOUT
|
144 | *
|
145 | * @returns {number} - represents the socket timeout in ms
|
146 | * @private
|
147 | */
|
148 | private getSocketTimeout;
|
149 | }
|
150 | declare namespace WebServer {
|
151 | interface Options {
|
152 | port?: number;
|
153 | host?: string;
|
154 | }
|
155 | }
|
156 | export {};
|