@lwrjs/auth-middleware 0.12.0-alpha.9 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/build/cjs/web-server.cjs +2 -1
- package/build/es/web-server.d.ts +2 -2
- package/build/es/web-server.js +7 -2
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ import { createServer } from 'lwr';
|
|
|
20
20
|
import { platformWebServerAuthMiddleware } from '@lwrjs/auth-middleware';
|
|
21
21
|
|
|
22
22
|
const lwrApp = createServer(lwrConfig);
|
|
23
|
-
platformWebServerAuthMiddleware(lwrApp
|
|
23
|
+
platformWebServerAuthMiddleware(lwrApp); // Pass in the generic LWR server
|
|
24
24
|
```
|
|
25
25
|
|
|
26
26
|
> For more information on LWR middleware see [this recipe](https://github.com/salesforce-experience-platform-emu/lwr-recipes/tree/master/packages/custom-middleware).
|
|
@@ -75,7 +75,7 @@ The `platformWebServerAuthMiddleware` uses the [OAuth 2.0 Web Server Flow for We
|
|
|
75
75
|
|
|
76
76
|
An app developer can attach the LWR authentication middleware when they create their LWR server. The middleware takes the following arguments:
|
|
77
77
|
|
|
78
|
-
- _Required_ app
|
|
78
|
+
- _Required_ LWR app instance from `createServer()`; this is compatible with both the Express and Koa LWR server types. Do not use `LwrApp.getInternalServer()`, which returns **either** the underlying Express **or** Koa server.
|
|
79
79
|
- _Optional_ bag of options: `{ proxyEndpoint?: string; }`:
|
|
80
80
|
- proxyEndpoint: The endpoint which proxies all its requests to the Salesforce org; it defaults to `/services/data`.
|
|
81
81
|
|
|
@@ -84,7 +84,7 @@ import { createServer } from 'lwr';
|
|
|
84
84
|
import { platformWebServerAuthMiddleware } from '@lwrjs/auth-middleware';
|
|
85
85
|
|
|
86
86
|
const lwrApp = createServer(lwrConfig);
|
|
87
|
-
platformWebServerAuthMiddleware(lwrApp
|
|
87
|
+
platformWebServerAuthMiddleware(lwrApp, { proxyEndpoint: '/some/where' });
|
|
88
88
|
```
|
|
89
89
|
|
|
90
90
|
### Variables
|
package/build/cjs/web-server.cjs
CHANGED
|
@@ -27,6 +27,7 @@ __export(exports, {
|
|
|
27
27
|
platformWebServerAuthMiddleware: () => platformWebServerAuthMiddleware,
|
|
28
28
|
stateMap: () => stateMap
|
|
29
29
|
});
|
|
30
|
+
var import_core = __toModule(require("@lwrjs/core"));
|
|
30
31
|
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
31
32
|
var import_utils = __toModule(require("./utils.cjs"));
|
|
32
33
|
var stateMap = new Map();
|
|
@@ -76,7 +77,7 @@ function platformWebServerAuthMiddleware(server, {proxyEndpoint = import_utils.P
|
|
|
76
77
|
res.status(response.status).send(errorMsg);
|
|
77
78
|
}
|
|
78
79
|
});
|
|
79
|
-
server.all(`${proxyEndpoint}/${server.
|
|
80
|
+
server.all(`${proxyEndpoint}/${server.serverType === "koa" ? "(.*)" : "*"}`, async (req, res) => {
|
|
80
81
|
const oauthInfo = (0, import_utils.getOauthInfoFromCookie)(req);
|
|
81
82
|
if (oauthInfo) {
|
|
82
83
|
const {url, options} = (0, import_utils.buildProxyRequest)(req, oauthInfo, req.headers);
|
package/build/es/web-server.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { PublicAppServer, ServerTypes } from '@lwrjs/types';
|
|
2
1
|
import type { PlatformWebServerOptions, LoginState } from './types.js';
|
|
2
|
+
import { LwrApp } from '@lwrjs/core';
|
|
3
3
|
export declare const stateMap: Map<string, LoginState>;
|
|
4
4
|
/**
|
|
5
5
|
* Web Server OAuth middleware: https://help.salesforce.com/s/articleView?id=sf.remoteaccess_oauth_web_server_flow.htm&type=5
|
|
@@ -14,5 +14,5 @@ export declare const stateMap: Map<string, LoginState>;
|
|
|
14
14
|
* - login_server: an encoded string; the middleware attempts to login at this address; default is "https://login.salesforce.com"
|
|
15
15
|
* - redirect_uri: an encoded string; this is where the middleware redirects to after OAuth is done; default is calculated from the request source
|
|
16
16
|
*/
|
|
17
|
-
export declare function platformWebServerAuthMiddleware
|
|
17
|
+
export declare function platformWebServerAuthMiddleware(server: LwrApp, { proxyEndpoint }?: PlatformWebServerOptions): void;
|
|
18
18
|
//# sourceMappingURL=web-server.d.ts.map
|
package/build/es/web-server.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
|
+
// @ts-ignore - LwrApp as a type is not working correctly
|
|
3
|
+
import '@lwrjs/core';
|
|
1
4
|
import { logger } from '@lwrjs/diagnostics';
|
|
2
5
|
import { COOKIE_NAME, DEFAULT_LOGIN_SERVER, LOGIN_ENDPOINT, MESSAGE_PREFIX, PROXY_ENDPOINT, REDIRECT_ENDPOINT, REVOKE_ENDPOINT, buildProxyRequest, buildRedirectUrl, generateStateString, sanitizeAppPath, getOauthInfoFromCookie, getPlatformWebServerEnvVars, } from './utils.js';
|
|
3
6
|
export const stateMap = new Map();
|
|
@@ -78,13 +81,15 @@ export function platformWebServerAuthMiddleware(server, { proxyEndpoint = PROXY_
|
|
|
78
81
|
});
|
|
79
82
|
// Now, proxy requests using the token to authorize them
|
|
80
83
|
// e.g. /services/data/v52.0/ui-api/list-ui/Opportunity/AllOpportunities"
|
|
81
|
-
server.all(`${proxyEndpoint}/${server.
|
|
84
|
+
server.all(`${proxyEndpoint}/${server.serverType === 'koa' ? '(.*)' : '*'}`, async (req, res) => {
|
|
82
85
|
const oauthInfo = getOauthInfoFromCookie(req);
|
|
83
86
|
if (oauthInfo) {
|
|
84
87
|
const { url, options } = buildProxyRequest(req, oauthInfo, req.headers);
|
|
85
88
|
const proxyRes = await fetch(url, options);
|
|
86
89
|
const contentType = proxyRes.headers.get('Content-Type') || ''; // parse as json or text
|
|
87
|
-
const data = await (contentType.includes('application/json')
|
|
90
|
+
const data = await (contentType.includes('application/json')
|
|
91
|
+
? proxyRes.json()
|
|
92
|
+
: proxyRes.text());
|
|
88
93
|
res.status(proxyRes.status).send(data);
|
|
89
94
|
}
|
|
90
95
|
else {
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.12.0
|
|
7
|
+
"version": "0.12.0",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -30,14 +30,15 @@
|
|
|
30
30
|
"build/**/*.d.ts"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@lwrjs/
|
|
33
|
+
"@lwrjs/core": "0.12.0",
|
|
34
|
+
"@lwrjs/diagnostics": "0.12.0"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
|
-
"@lwrjs/server": "0.12.0
|
|
37
|
-
"@lwrjs/types": "0.12.0
|
|
37
|
+
"@lwrjs/server": "0.12.0",
|
|
38
|
+
"@lwrjs/types": "0.12.0"
|
|
38
39
|
},
|
|
39
40
|
"engines": {
|
|
40
41
|
"node": ">=18.0.0"
|
|
41
42
|
},
|
|
42
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "90f93604b26003e1e1eb85bb0d1f34f4fc9e9ff9"
|
|
43
44
|
}
|