@travetto/auth-web-passport 7.0.0-rc.1 → 7.0.0-rc.3
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 +5 -5
- package/package.json +6 -6
- package/src/authenticator.ts +5 -5
- package/src/util.ts +11 -11
package/README.md
CHANGED
|
@@ -45,8 +45,8 @@ export class AppConfig {
|
|
|
45
45
|
callbackURL: 'http://localhost:3000/auth/facebook/callback',
|
|
46
46
|
profileFields: ['id', 'username', 'displayName', 'photos', 'email'],
|
|
47
47
|
},
|
|
48
|
-
(accessToken, refreshToken, profile,
|
|
49
|
-
|
|
48
|
+
(accessToken, refreshToken, profile, callback) =>
|
|
49
|
+
callback(undefined, profile)
|
|
50
50
|
),
|
|
51
51
|
(user: FbUser) => ({
|
|
52
52
|
id: user.username,
|
|
@@ -59,8 +59,8 @@ export class AppConfig {
|
|
|
59
59
|
@InjectableFactory()
|
|
60
60
|
static principalSource(): Authorizer {
|
|
61
61
|
return new class implements Authorizer {
|
|
62
|
-
async authorize(
|
|
63
|
-
return
|
|
62
|
+
async authorize(principal: Principal) {
|
|
63
|
+
return principal;
|
|
64
64
|
}
|
|
65
65
|
}();
|
|
66
66
|
}
|
|
@@ -81,7 +81,7 @@ import { Controller, Get, Post, WebRequest, ContextParam, WebResponse } from '@t
|
|
|
81
81
|
import { Login, Authenticated, Logout } from '@travetto/auth-web';
|
|
82
82
|
import { Principal } from '@travetto/auth';
|
|
83
83
|
|
|
84
|
-
import { FbAuthSymbol } from './
|
|
84
|
+
import { FbAuthSymbol } from './config.ts';
|
|
85
85
|
|
|
86
86
|
@Controller('/auth')
|
|
87
87
|
export class SampleAuth {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/auth-web-passport",
|
|
3
|
-
"version": "7.0.0-rc.
|
|
3
|
+
"version": "7.0.0-rc.3",
|
|
4
4
|
"description": "Web authentication integration support for the Travetto framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"authentication",
|
|
@@ -26,11 +26,11 @@
|
|
|
26
26
|
"directory": "module/auth-web-passport"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@travetto/auth": "^7.0.0-rc.
|
|
30
|
-
"@travetto/auth-web": "^7.0.0-rc.
|
|
31
|
-
"@travetto/config": "^7.0.0-rc.
|
|
32
|
-
"@travetto/web": "^7.0.0-rc.
|
|
33
|
-
"@travetto/web-connect": "^7.0.0-rc.
|
|
29
|
+
"@travetto/auth": "^7.0.0-rc.2",
|
|
30
|
+
"@travetto/auth-web": "^7.0.0-rc.3",
|
|
31
|
+
"@travetto/config": "^7.0.0-rc.2",
|
|
32
|
+
"@travetto/web": "^7.0.0-rc.3",
|
|
33
|
+
"@travetto/web-connect": "^7.0.0-rc.3",
|
|
34
34
|
"@types/passport": "^1.0.17",
|
|
35
35
|
"passport": "^0.7.0"
|
|
36
36
|
},
|
package/src/authenticator.ts
CHANGED
|
@@ -26,18 +26,18 @@ export class PassportAuthenticator<V extends PassportUser = PassportUser> implem
|
|
|
26
26
|
* @param strategyName Name of passport strategy
|
|
27
27
|
* @param strategy A passport strategy
|
|
28
28
|
* @param toPrincipal How to convert a user to an identity
|
|
29
|
-
* @param
|
|
29
|
+
* @param options Extra passport options
|
|
30
30
|
*/
|
|
31
31
|
constructor(
|
|
32
32
|
strategyName: string,
|
|
33
33
|
strategy: passport.Strategy,
|
|
34
34
|
toPrincipal: (user: V) => SimplePrincipal,
|
|
35
|
-
|
|
35
|
+
options: passport.AuthenticateOptions | ((ctx: WebFilterContext) => passport.AuthenticateOptions) = {},
|
|
36
36
|
) {
|
|
37
37
|
this.#strategyName = strategyName;
|
|
38
38
|
this.#strategy = strategy;
|
|
39
39
|
this.#toPrincipal = toPrincipal;
|
|
40
|
-
this.#passportOptions = typeof
|
|
40
|
+
this.#passportOptions = typeof options === 'function' ? options : ((): Partial<passport.AuthenticateOptions> => options);
|
|
41
41
|
passport.use(this.#strategyName, this.#strategy);
|
|
42
42
|
}
|
|
43
43
|
|
|
@@ -61,8 +61,8 @@ export class PassportAuthenticator<V extends PassportUser = PassportUser> implem
|
|
|
61
61
|
state: PassportUtil.enhanceState(ctx, requestOptions.state)
|
|
62
62
|
};
|
|
63
63
|
|
|
64
|
-
const user = await WebConnectUtil.invoke<V>(ctx, (
|
|
65
|
-
passport.authenticate(this.#strategyName, options, next)(
|
|
64
|
+
const user = await WebConnectUtil.invoke<V>(ctx, (request, response, next) =>
|
|
65
|
+
passport.authenticate(this.#strategyName, options, next)(request, response)
|
|
66
66
|
);
|
|
67
67
|
|
|
68
68
|
if (user) {
|
package/src/util.ts
CHANGED
|
@@ -8,12 +8,12 @@ export class PassportUtil {
|
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Read passport state string as bas64 encoded JSON value
|
|
11
|
-
* @param
|
|
11
|
+
* @param input The input for a state read (string, or a request)
|
|
12
12
|
*/
|
|
13
|
-
static readState<T = Record<string, unknown>>(
|
|
14
|
-
const state = (typeof
|
|
15
|
-
(typeof
|
|
16
|
-
|
|
13
|
+
static readState<T = Record<string, unknown>>(input?: string | WebRequest): T | undefined {
|
|
14
|
+
const state = (typeof input === 'string' ? input :
|
|
15
|
+
(typeof input?.context.httpQuery?.state === 'string' ?
|
|
16
|
+
input?.context.httpQuery?.state : ''));
|
|
17
17
|
if (state) {
|
|
18
18
|
try {
|
|
19
19
|
return Util.decodeSafeJSON(state);
|
|
@@ -40,16 +40,16 @@ export class PassportUtil {
|
|
|
40
40
|
* @returns
|
|
41
41
|
*/
|
|
42
42
|
static addToState(state: string | Record<string, unknown>, current?: string | WebRequest, key?: string): string {
|
|
43
|
-
const
|
|
43
|
+
const original = this.readState(current) ?? {};
|
|
44
44
|
const toAdd = typeof state === 'string' ? JSON.parse(state) : state;
|
|
45
|
-
const base: Record<string, unknown> = key ? castTo(
|
|
46
|
-
for (const
|
|
47
|
-
if (
|
|
45
|
+
const base: Record<string, unknown> = key ? castTo(original[key] ??= {}) : original;
|
|
46
|
+
for (const property of Object.keys(toAdd)) {
|
|
47
|
+
if (property === '__proto__' || property === 'constructor' || property === 'prototype') {
|
|
48
48
|
continue;
|
|
49
49
|
}
|
|
50
|
-
base[
|
|
50
|
+
base[property] = toAdd[property];
|
|
51
51
|
}
|
|
52
|
-
return this.writeState(
|
|
52
|
+
return this.writeState(original)!;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
/**
|