@travetto/auth 7.0.0-rc.1 → 7.0.0-rc.2

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
@@ -126,11 +126,11 @@ export class AuthService {
126
126
  /**
127
127
  * Manage expiry state, renewing if allowed
128
128
  */
129
- manageExpiry(p?: Principal): void;
129
+ manageExpiry(principal?: Principal): void;
130
130
  /**
131
131
  * Enforce expiry, invalidating the principal if expired
132
132
  */
133
- enforceExpiry(p?: Principal): Principal | undefined;
133
+ enforceExpiry(principal?: Principal): Principal | undefined;
134
134
  }
135
135
  ```
136
136
 
@@ -155,7 +155,7 @@ export class AuthContext {
155
155
  /**
156
156
  * Set principal
157
157
  */
158
- set principal(p: Principal | undefined);
158
+ set principal(value: Principal | undefined);
159
159
  /**
160
160
  * Get the authentication token, if it exists
161
161
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/auth",
3
- "version": "7.0.0-rc.1",
3
+ "version": "7.0.0-rc.2",
4
4
  "description": "Authentication scaffolding for the Travetto framework",
5
5
  "keywords": [
6
6
  "authentication",
@@ -23,7 +23,7 @@
23
23
  "directory": "module/auth"
24
24
  },
25
25
  "dependencies": {
26
- "@travetto/context": "^7.0.0-rc.1"
26
+ "@travetto/context": "^7.0.0-rc.2"
27
27
  },
28
28
  "travetto": {
29
29
  "displayName": "Authentication"
package/src/context.ts CHANGED
@@ -30,8 +30,8 @@ export class AuthContext {
30
30
  /**
31
31
  * Set principal
32
32
  */
33
- set principal(p: Principal | undefined) {
34
- this.#principal.set(p);
33
+ set principal(value: Principal | undefined) {
34
+ this.#principal.set(value);
35
35
  }
36
36
 
37
37
  /**
package/src/service.ts CHANGED
@@ -27,9 +27,9 @@ export class AuthService {
27
27
  // Find all authenticators
28
28
  const AuthenticatorTarget = toConcrete<Authenticator>();
29
29
  for (const source of DependencyRegistryIndex.getCandidates(AuthenticatorTarget)) {
30
- const qual = source.qualifier || getDefaultQualifier(source.class);
31
- const dep = DependencyRegistryIndex.getInstance(AuthenticatorTarget, qual);
32
- this.#authenticators.set(qual, dep);
30
+ const qualifier = source.qualifier || getDefaultQualifier(source.class);
31
+ const instance = DependencyRegistryIndex.getInstance(AuthenticatorTarget, qualifier);
32
+ this.#authenticators.set(qualifier, instance);
33
33
  }
34
34
  }
35
35
 
@@ -51,28 +51,28 @@ export class AuthService {
51
51
  /**
52
52
  * Attempt to authenticate, checking with multiple authentication sources
53
53
  */
54
- for (const idp of await this.getAuthenticators<T, C>(authenticators)) {
54
+ for (const authenticator of await this.getAuthenticators<T, C>(authenticators)) {
55
55
  try {
56
- const principal = await idp.authenticate(payload, context);
56
+ const principal = await authenticator.authenticate(payload, context);
57
57
 
58
- if (idp.getState) {
59
- this.authContext.authenticatorState = await idp.getState(context);
58
+ if (authenticator.getState) {
59
+ this.authContext.authenticatorState = await authenticator.getState(context);
60
60
  }
61
61
 
62
62
  if (!principal) { // Multi-step login process
63
63
  return;
64
64
  }
65
65
  return this.authContext.principal = (await this.authorizer?.authorize(principal)) ?? principal;
66
- } catch (err) {
67
- if (!(err instanceof Error)) {
68
- throw err;
66
+ } catch (error) {
67
+ if (!(error instanceof Error)) {
68
+ throw error;
69
69
  }
70
- lastError = err;
70
+ lastError = error;
71
71
  }
72
72
  }
73
73
 
74
74
  if (lastError) {
75
- console.warn('Failed to authenticate', { error: lastError, sources: authenticators.map(x => x.toString()) });
75
+ console.warn('Failed to authenticate', { error: lastError, sources: authenticators.map(symbol => symbol.toString()) });
76
76
  }
77
77
 
78
78
  // Take the last error and return
@@ -82,23 +82,23 @@ export class AuthService {
82
82
  /**
83
83
  * Manage expiry state, renewing if allowed
84
84
  */
85
- manageExpiry(p?: Principal): void {
86
- if (!p) {
85
+ manageExpiry(principal?: Principal): void {
86
+ if (!principal) {
87
87
  return;
88
88
  }
89
89
 
90
90
  if (this.config.maxAgeMs) {
91
- p.expiresAt ??= TimeUtil.fromNow(this.config.maxAgeMs);
91
+ principal.expiresAt ??= TimeUtil.fromNow(this.config.maxAgeMs);
92
92
  }
93
93
 
94
- p.issuedAt ??= new Date();
94
+ principal.issuedAt ??= new Date();
95
95
 
96
- if (p.expiresAt && this.config.maxAgeMs && this.config.rollingRenew) { // Session behavior
97
- const end = p.expiresAt.getTime();
96
+ if (principal.expiresAt && this.config.maxAgeMs && this.config.rollingRenew) { // Session behavior
97
+ const end = principal.expiresAt.getTime();
98
98
  const midPoint = end - this.config.maxAgeMs / 2;
99
99
  if (Date.now() > midPoint) { // If we are past the half way mark, renew the token
100
- p.issuedAt = new Date();
101
- p.expiresAt = TimeUtil.fromNow(this.config.maxAgeMs); // This will trigger a re-send
100
+ principal.issuedAt = new Date();
101
+ principal.expiresAt = TimeUtil.fromNow(this.config.maxAgeMs); // This will trigger a re-send
102
102
  }
103
103
  }
104
104
  }
@@ -106,10 +106,10 @@ export class AuthService {
106
106
  /**
107
107
  * Enforce expiry, invalidating the principal if expired
108
108
  */
109
- enforceExpiry(p?: Principal): Principal | undefined {
110
- if (p && p.expiresAt && p.expiresAt.getTime() < Date.now()) {
109
+ enforceExpiry(principal?: Principal): Principal | undefined {
110
+ if (principal && principal.expiresAt && principal.expiresAt.getTime() < Date.now()) {
111
111
  return undefined;
112
112
  }
113
- return p;
113
+ return principal;
114
114
  }
115
115
  }