3.1.10 • Published 12 months ago

@travetto/auth-rest-context v3.1.10

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

Rest Auth Context

Rest authentication context integration support for the Travetto framework

Install: @travetto/auth-rest-context

npm install @travetto/auth-rest-context

# or

yarn add @travetto/auth-rest-context

This module exposes a service AuthContextService that is @Injectable, and will provide access to the user's authentication context without access to the request object. This is extremely useful for auditing, logging, and other enforcement patterns.

This module intercepts the auth field on the http request object, and persists it using the Async Context module, meaning this information is now able to be retrieved outside of the normal execution flow, while the http request is still processing.

Code: AuthContextService

import { Principal } from '@travetto/auth';
import { AsyncContext } from '@travetto/context';
import { Inject, Injectable } from '@travetto/di';

const PrincipalⲐ = Symbol.for('@travetto/auth:principal');

/**
 * Provides global context to accessing principal
 */
@Injectable()
export class AuthContextService {

  @Inject()
  context: AsyncContext;

  /**
   * Set principal
   * @param p The auth principal
   */
  set = (p: Principal | undefined): void => this.context.set(PrincipalⲐ, p);

  /**
   * Get the principal from the context
   * @returns principal if authenticated
   * @returns undefined if not authenticated
   */
  get = <T = { [key: string]: unknown }>(): (Principal<T> | undefined) => this.context.get<Principal<T>>(PrincipalⲐ);
}
3.1.10

12 months ago

3.1.9

12 months ago

3.1.8

1 year ago

3.1.7

1 year ago

3.1.6

1 year ago

3.1.5

1 year ago

3.1.4

1 year ago

3.0.3

1 year ago

3.1.0-rc.10

1 year ago

3.1.3

1 year ago

3.1.2

1 year ago

3.1.1

1 year ago

3.1.0

1 year ago

3.1.0-rc.2

1 year ago

3.1.0-rc.3

1 year ago

3.1.0-rc.0

1 year ago

3.1.0-rc.1

1 year ago

3.1.0-rc.6

1 year ago

3.1.0-rc.7

1 year ago

3.1.0-rc.4

1 year ago

3.1.0-rc.5

1 year ago

3.1.0-rc.9

1 year ago

3.0.0-rc.26

1 year ago

3.0.0-rc.27

1 year ago

3.0.1-rc.1

1 year ago

3.0.2

1 year ago

3.0.1

1 year ago

3.0.0

1 year ago

3.0.2-rc.1

1 year ago

3.0.2-rc.0

1 year ago

3.0.0-rc.24

1 year ago

3.0.0-rc.23

1 year ago

3.0.0-rc.25

1 year ago

3.0.0-rc.20

1 year ago

3.0.0-rc.22

1 year ago

3.0.0-rc.21

1 year ago

3.0.0-rc.15

1 year ago

3.0.0-rc.17

1 year ago

3.0.0-rc.16

1 year ago

3.0.0-rc.19

1 year ago

3.0.0-rc.18

1 year ago

3.0.0-rc.13

1 year ago

3.0.0-rc.12

1 year ago

3.0.0-rc.14

1 year ago

3.0.0-rc.6

1 year ago

3.0.0-rc.11

1 year ago

3.0.0-rc.10

1 year ago

3.0.0-rc.9

1 year ago

3.0.0-rc.8

1 year ago

3.0.0-rc.7

1 year ago

3.0.0-rc.4

2 years ago

3.0.0-rc.3

2 years ago

3.0.0-rc.2

2 years ago

3.0.0-rc.1

2 years ago

3.0.0-rc.0

2 years ago