@travetto/auth-web-passport 7.0.0-rc.2 → 7.0.0-rc.4

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 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, cb) =>
49
- cb(undefined, profile)
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(p: Principal) {
63
- return p;
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 './conf.ts';
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.2",
3
+ "version": "7.0.0-rc.4",
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.1",
30
- "@travetto/auth-web": "^7.0.0-rc.2",
31
- "@travetto/config": "^7.0.0-rc.1",
32
- "@travetto/web": "^7.0.0-rc.2",
33
- "@travetto/web-connect": "^7.0.0-rc.2",
29
+ "@travetto/auth": "^7.0.0-rc.3",
30
+ "@travetto/auth-web": "^7.0.0-rc.4",
31
+ "@travetto/config": "^7.0.0-rc.3",
32
+ "@travetto/web": "^7.0.0-rc.4",
33
+ "@travetto/web-connect": "^7.0.0-rc.4",
34
34
  "@types/passport": "^1.0.17",
35
35
  "passport": "^0.7.0"
36
36
  },
@@ -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 opts Extra passport options
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
- opts: passport.AuthenticateOptions | ((ctx: WebFilterContext) => passport.AuthenticateOptions) = {},
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 opts === 'function' ? opts : ((): Partial<passport.AuthenticateOptions> => opts);
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, (req, res, next) =>
65
- passport.authenticate(this.#strategyName, options, next)(req, res)
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
@@ -1,5 +1,5 @@
1
1
  import { WebFilterContext, WebRequest } from '@travetto/web';
2
- import { castTo, Util } from '@travetto/runtime';
2
+ import { castTo, JSONUtil } from '@travetto/runtime';
3
3
 
4
4
  /**
5
5
  * Passport utilities
@@ -8,15 +8,15 @@ export class PassportUtil {
8
8
 
9
9
  /**
10
10
  * Read passport state string as bas64 encoded JSON value
11
- * @param src The input src for a state read (string, or a request obj)
11
+ * @param input The input for a state read (string, or a request)
12
12
  */
13
- static readState<T = Record<string, unknown>>(src?: string | WebRequest): T | undefined {
14
- const state = (typeof src === 'string' ? src :
15
- (typeof src?.context.httpQuery?.state === 'string' ?
16
- src?.context.httpQuery?.state : ''));
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
- return Util.decodeSafeJSON(state);
19
+ return JSONUtil.parseBase64(state);
20
20
  } catch { }
21
21
  }
22
22
  }
@@ -28,7 +28,7 @@ export class PassportUtil {
28
28
  */
29
29
  static writeState(state?: Record<string, unknown>): string | undefined {
30
30
  if (state) {
31
- return Util.encodeSafeJSON(state);
31
+ return JSONUtil.stringifyBase64(state);
32
32
  }
33
33
  }
34
34
 
@@ -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 pre = this.readState(current) ?? {};
44
- const toAdd = typeof state === 'string' ? JSON.parse(state) : state;
45
- const base: Record<string, unknown> = key ? castTo(pre[key] ??= {}) : pre;
46
- for (const k of Object.keys(toAdd)) {
47
- if (k === '__proto__' || k === 'constructor' || k === 'prototype') {
43
+ const original = this.readState(current) ?? {};
44
+ const toAdd: Record<string, unknown> = typeof state === 'string' ? JSONUtil.parseSafe(state) : state;
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[k] = toAdd[k];
50
+ base[property] = toAdd[property];
51
51
  }
52
- return this.writeState(pre)!;
52
+ return this.writeState(original)!;
53
53
  }
54
54
 
55
55
  /**