UNPKG

@perfood/couch-auth

Version:

Easy and secure authentication for CouchDB/Cloudant. Based on SuperLogin, updated and rewritten in Typescript.

57 lines (56 loc) 2.66 kB
import { Router } from 'express'; import { Authenticator } from 'passport'; import { Config } from './types/config'; import { User } from './user'; export declare class OAuth { private router; private passport; private user; private config; static stateRequired: string[]; constructor(router: Router, passport: Authenticator, user: User, config: Partial<Config>); /** Function to initialize a session following authentication from a socialAuth provider */ private initSession; /** Function to initialize a session following authentication from a socialAuth provider */ private initTokenSession; /** Called after an account has been succesfully linked */ private linkSuccess; /** Called after an account has been succesfully linked using access_token provider */ private linkTokenSuccess; /** Handles errors if authentication fails */ private oauthErrorHandler; /** Handles errors if authentication from access_token provider fails */ private tokenAuthErrorHandler; /** Framework to register OAuth providers with passport */ registerProvider(provider: string, configFunction: Function): void; /** A shortcut to register OAuth2 providers that follow the exact accessToken, refreshToken pattern. */ registerOAuth2(providerName: string, Strategy: any): void; /** * Registers a provider that accepts an access_token directly from the client, skipping the popup window and callback * This is for supporting Cordova, native IOS and Android apps, as well as other devices */ registerTokenProvider(providerName: string, Strategy: any): void; /** * This is called after a user has successfully authenticated with a provider * If a user is authenticated with a bearer token we will link an account, otherwise log in * auth is an object containing 'access_token' and optionally 'refresh_token' */ private authHandler; /** * Configures the passport.authenticate for the given provider, passing in options * Operation is 'login' or 'link' */ private passportCallback; /** Configures the passport.authenticate for the given access_token provider, passing in options */ private passportTokenCallback; private getLinkCallbackURLs; /** Gets the provider name from a callback path */ private getProvider; /** Gets the provider name from a callback path for access_token strategy */ private getProviderToken; /** * Gets the template file checking if a custom template was set in the provider options * and if the testMode.oauthTest is enabled. */ private getTemplate; }