1.0.10 • Published 6 years ago

typescript-rest-jwt v1.0.10

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

TypeScript Rest JWT

CircleCI Coverage Status

JWT authentication for typescript-rest via decorators.

Precursor

To get started with typescript-rest-jwt, visit typescript-rest for a detailed getting started guide of the underlying library.

Usage

Install:

npm install -s typescript-rest-jwt

Update an existing controller:

import { GET, Path, PathParam } from 'typescript-rest'

@Path('/hello')
export class HelloController {

  @Path('/')
  @GET
  public sayHello(): string {
    return 'Hello, World!'
  }

  @Path('/:name')
  @GET
  public sayHelloTo (@PathParam('name') name: string): string {
    return `Hello ${name}!`
  }
}
import { Context, GET, Path } from 'typescript-rest'
import { AuthPath } from 'typescript-rest-jwt'

// You must update the class level Path to also be an AuthPath, even
// if you still have unsecured routes.
@AuthPath('/hello')
export class HelloController {
  // Inject the service context to get access to the user info
  @Context
  public context: ServiceContext

  // Still unsecured
  @Path('/')
  @GET
  public sayHello(): string {
    return 'Hello, World!'
  }

  @AuthPath('/secured')
  @GET
  public sayHelloTo (): string {
    return `Hello ${this.context.request.user.name}!`
  }
}

Before your call to typescript-rest's Server.buildServices, we need to configure our AuthHandler:

import { AuthHandler } from 'typescript-rest-jwt'

...

AuthHandler.configure(app, jwtConfig)
Server.buildServices(app, ...controllers)

AuthHandler.configure either accepts string secret or expressJWT.Options.

License

MIT

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago