All files utils.ts

100% Statements 10/10
100% Branches 2/2
100% Functions 3/3
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 401x                     7x 7x     3x     4x             4x     1x 3x               3x    
import querystring from 'querystring';
import { Application } from '@feathersjs/feathers';
import { AuthenticationService, AuthenticationResult } from '@feathersjs/authentication';
 
export interface OauthSetupSettings {
  path?: string;
  authService?: string;
  linkStrategy?: string;
  getRedirect? (service: AuthenticationService, data: AuthenticationResult|Error): Promise<string>;
}
 
export const getRedirect = async (service: AuthenticationService, data: AuthenticationResult|Error) => {
  const { redirect } = service.configuration.oauth;
 
  if (!redirect) {
    return null;
  }
  
  const authResult: AuthenticationResult = data;
  const query = authResult.accessToken ? {
    access_token: authResult.accessToken
  } : {
    error: data.message || 'OAuth Authentication not successful'
  };
 
  return `${redirect}#${querystring.stringify(query)}`;
};
 
export const getDefaultSettings = (app: Application, other?: OauthSetupSettings) => {
  const defaults: OauthSetupSettings = {
    path: '/auth',
    authService: app.get('defaultAuthentication'),
    linkStrategy: 'jwt',
    getRedirect,
    ...other
  };
 
  return defaults;
};