Options
All
  • Public
  • Public/Protected
  • All
Menu

Class PassportAuth

Default implementation for passport authentication

Hierarchy

  • PassportAuth

Implements

  • EndpointSecurity

Index

Constructors

constructor

Properties

Protected jwtOpts

jwtOpts: JwtOptions

Protected passport

passport: Passport = new passport.Passport()

Protected userRepo

userRepo: UserRepository

Protected userService

userService: UserService

Methods

Protected accessDenied

  • accessDenied(req: any, res: express.Response): void
  • Handler for access denied responses in the event that a user is not authorized to access a resource. This method can be overridden to provide a custom access denied handler

    Parameters

    • req: any
    • res: express.Response

    Returns void

authenticate

  • authenticate(strategy: string, options?: AuthenticateOptions): (Anonymous function)
  • Creates a middleware for authentication purposes. This method wraps passport.authenticate to provide a middleware for authenticating users. It also includes a check if the user is already authenticated. If the user is already authenticated, it redirects back to the application, otherwise, it proceeds to authenticate the user.

    Parameters

    • strategy: string

      Strategy to be used by Passport's authenticate function

    • Optional options: AuthenticateOptions

    Returns (Anonymous function)

authenticateWithToken

  • Creates a middleware for authentication purposes that will base on JWT tokens. This will send back a status of 200 with the token and user profile on successful authentcation, otherwise it sends a status of 401.

    Parameters

    • secret: string

      secret used to sign the JWT token

    • userService: UserService

      UserService custom implementation

    • userRepo: UserRepository

      UserRepository custom implementation

    Returns (Anonymous function)

init

  • init(app: express.Router, sessionOpts?: SessionOptions, secret?: any): void
  • Initializes an Express application to use passport. Note: If the session options are not defined, session based authentication will not be used.

    Parameters

    • app: express.Router

      An express application

    • Optional sessionOpts: SessionOptions

      Session options to be used by express-session

    • Optional secret: any

      Secret to be used for Passport's JWT strategy

    Returns void

protect

  • protect(role?: undefined | string): (Anonymous function)
  • Function which checks if the user requesting access to the resource is authenticated and authorized to access the resource. Returns a status of 401 if the user is not authenticated and returns a status of 403 if the user does not have the required role.

    Parameters

    • Optional role: undefined | string

      Role which the user needs in order to access this resource

    Returns (Anonymous function)

Protected setReturnToUrl

  • setReturnToUrl(req: any): any
  • Sets the url to return to after successful login. This method can be overridden to provide a custom URL to return to

    Parameters

    • req: any

    Returns any

Protected setupCookie

  • setupCookie(passportApi: Passport): void
  • Sets up the local strategy, serializer and deserializer to be used by Passport's cookie based authentication. Method can be overridden to provide custom passport setup

    Parameters

    • passportApi: Passport

      passport.js instance

    Returns void

Protected setupToken

  • setupToken(passportApi: Passport, jwtOpts: JwtOptions): void
  • Sets up the JWT strategy, serializer and deserializer to be used by Passport's token based authentication. Method can be overridden to provide custom passport setup

    Parameters

    • passportApi: Passport

      passport.js instance

    • jwtOpts: JwtOptions

      Options used for Passport's JWT strategy

    Returns void

Generated using TypeDoc