1 | import * as http from 'node:http';
|
2 | import { AsyncCreatable } from '@salesforce/kit';
|
3 | import { AuthInfo } from './org/authInfo';
|
4 | import { JwtOAuth2Config } from './org/authInfo';
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | export declare class WebOAuthServer extends AsyncCreatable<WebOAuthServer.Options> {
|
22 | static DEFAULT_PORT: number;
|
23 | private authUrl;
|
24 | private logger;
|
25 | private webServer;
|
26 | private oauth2;
|
27 | private oauthConfig;
|
28 | private oauthError;
|
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 | type Options = {
|
83 | oauthConfig: JwtOAuth2Config;
|
84 | };
|
85 | type Request = http.IncomingMessage & {
|
86 | query: {
|
87 | code: string;
|
88 | state: string;
|
89 | error?: string;
|
90 | error_description?: string;
|
91 | };
|
92 | };
|
93 | }
|
94 |
|
95 |
|
96 |
|
97 | export declare class WebServer extends AsyncCreatable<WebServer.Options> {
|
98 | static DEFAULT_CLIENT_SOCKET_TIMEOUT: number;
|
99 | server: http.Server;
|
100 | port: number;
|
101 | host: string;
|
102 | private logger;
|
103 | private sockets;
|
104 | private redirectStatus;
|
105 | constructor(options: WebServer.Options);
|
106 | /**
|
107 | * Starts the http server after checking that the port is open
|
108 | */
|
109 | start(): Promise<void>;
|
110 | /**
|
111 | * Closes the http server and all open sockets
|
112 | */
|
113 | close(): void;
|
114 | /**
|
115 | * sends a response error.
|
116 | *
|
117 | * @param status the statusCode for the response.
|
118 | * @param message the message for the http body.
|
119 | * @param response the response to write the error to.
|
120 | */
|
121 | sendError(status: number, message: string, response: http.ServerResponse): void;
|
122 | /**
|
123 | * sends a response redirect.
|
124 | *
|
125 | * @param status the statusCode for the response.
|
126 | * @param url the url to redirect to.
|
127 | * @param response the response to write the redirect to.
|
128 | */
|
129 | doRedirect(status: number, url: string, response: http.ServerResponse): void;
|
130 | /**
|
131 | * sends a response to the browser reporting an error.
|
132 | *
|
133 | * @param error the oauth error
|
134 | * @param response the HTTP response.
|
135 | */
|
136 | reportError(error: Error, response: http.ServerResponse): void;
|
137 | /**
|
138 | * sends a response to the browser reporting the success.
|
139 | *
|
140 | * @param response the HTTP response.
|
141 | */
|
142 | reportSuccess(response: http.ServerResponse): void;
|
143 | /**
|
144 | * Preflight request:
|
145 | *
|
146 | * https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request
|
147 | * https://www.w3.org/TR/2020/SPSD-cors-20200602/#resource-preflight-requests
|
148 | */
|
149 | handlePreflightRequest(response: http.ServerResponse): void;
|
150 | handleSuccess(response: http.ServerResponse): Promise<void>;
|
151 | handleError(response: http.ServerResponse): Promise<void>;
|
152 | protected init(): Promise<void>;
|
153 | private handleRedirect;
|
154 | /**
|
155 | * Make sure we can't open a socket on the localhost/host port. It's important because we don't want to send
|
156 | * auth tokens to a random strange port listener. We want to make sure we can startup our server first.
|
157 | *
|
158 | * @private
|
159 | */
|
160 | private checkOsPort;
|
161 | /**
|
162 | * check and get the socket timeout form what was set in process.env.SFDX_HTTP_SOCKET_TIMEOUT
|
163 | *
|
164 | * @returns {number} - represents the socket timeout in ms
|
165 | * @private
|
166 | */
|
167 | private getSocketTimeout;
|
168 | }
|
169 | declare namespace WebServer {
|
170 | type Options = {
|
171 | port?: number;
|
172 | host?: string;
|
173 | };
|
174 | }
|
175 | export {};
|