Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
import {Context, inject} from '@loopback/context';
import {
FindRoute,
InvokeMethod,
ParseParams,
Reject,
RequestContext,
RestBindings,
Send,
SequenceHandler,
} from '@loopback/rest';
const SequenceActions = RestBindings.SequenceActions;
export class MySequence implements SequenceHandler {
constructor(
@inject(RestBindings.Http.CONTEXT) public ctx: Context,
@inject(SequenceActions.FIND_ROUTE) protected findRoute: FindRoute,
@inject(SequenceActions.PARSE_PARAMS) protected parseParams: ParseParams,
@inject(SequenceActions.INVOKE_METHOD) protected invoke: InvokeMethod,
@inject(SequenceActions.SEND) public send: Send,
@inject(SequenceActions.REJECT) public reject: Reject,
) {}
async handle(context: RequestContext) {
try {
const {request, response} = context;
const route = this.findRoute(request);
const args = await this.parseParams(request, route);
RestBindings,
RestComponent,
RestServer,
Send,
SequenceHandler,
} from '@loopback/rest';
import {Client, createClientForHandler} from '@loopback/testlab';
import {
authenticate,
AuthenticateFn,
AuthenticationBindings,
AuthenticationComponent,
UserProfile,
} from '../..';
const SequenceActions = RestBindings.SequenceActions;
describe.skip('Basic Authentication', () => {
let app: Application;
let server: RestServer;
let users: UserRepository;
beforeEach(givenAServer);
beforeEach(givenUserRepository);
beforeEach(givenControllerInApp);
beforeEach(givenAuthenticatedSequence);
beforeEach(givenProviders);
it('authenticates successfully for correct credentials', async () => {
const client = whenIMakeRequestTo(server);
const credential =
users.list.joe.profile.id + ':' + users.list.joe.password;
const hash = Buffer.from(credential).toString('base64');
import {
FindRoute,
InvokeMethod,
ParseParams,
Reject,
RequestContext,
RestBindings,
RestComponent,
RestServer,
Send,
SequenceHandler,
} from '@loopback/rest';
import {Client, createClientForHandler} from '@loopback/testlab';
import {BasicStrategy} from 'passport-http';
import {StrategyAdapter} from '../../strategy-adapter';
const SequenceActions = RestBindings.SequenceActions;
const AUTH_STRATEGY_NAME = 'basic';
describe('Basic Authentication', () => {
let app: Application;
let server: RestServer;
let users: UserRepository;
beforeEach(givenAServer);
beforeEach(givenUserRepository);
beforeEach(givenControllerInApp);
beforeEach(givenAuthenticatedSequence);
it('authenticates successfully for correct credentials', async () => {
const client = whenIMakeRequestTo(server);
const credential =
users.list.joe.profile.id + ':' + users.list.joe.password;
const hash = Buffer.from(credential).toString('base64');
SequenceHandler,
} from '@loopback/rest';
import {Client, createClientForHandler, expect, sinon} from '@loopback/testlab';
import chalk from 'chalk';
import {
EXAMPLE_LOG_BINDINGS,
HighResTime,
log,
LogFn,
LogMixin,
LOG_LEVEL,
} from '../..';
import {logToMemory, resetLogs} from '../in-memory-logger';
import {AddSpy, createLogSpy, restoreLogSpy} from '../log-spy';
const SequenceActions = RestBindings.SequenceActions;
describe('log extension acceptance test', () => {
let app: LogApp;
let spy: AddSpy;
class LogApp extends LogMixin(RestApplication) {}
const debugMatch: string = chalk.white(
'DEBUG: /debug :: MyController.debug() => debug called',
);
const infoMatch: string = chalk.green(
'INFO: /info :: MyController.info() => info called',
);
const warnMatch: string = chalk.yellow(
'WARN: /warn :: MyController.warn() => warn called',
);
InvokeMethod,
ParseParams,
Reject,
RequestContext,
RestApplication,
RestBindings,
RestServer,
Send,
SequenceHandler,
} from '@loopback/rest';
import {SecurityBindings, securityId, UserProfile} from '@loopback/security';
import {Client, createClientForHandler} from '@loopback/testlab';
import {BasicStrategy, BasicVerifyFunction} from 'passport-http';
import {StrategyAdapter} from '../../strategy-adapter';
const SequenceActions = RestBindings.SequenceActions;
const AUTH_STRATEGY_NAME = 'basic';
const INVALID_USER_CREDENTIALS_MESSAGE = 'Invalid credentials';
const INVALID_USER_CREDENTIALS_CODE = 'INVALID_USER_CREDENTIALS';
const USERS_REPOSITORY_BINDING_KEY = 'repositories.users';
const VERIFY_FUNCTION_BASIC_AUTHENTICATION_BINDING_KEY =
'authentication.basic.verify';
const BASIC_STRATEGY_BINDING_KEY =
'authentication.strategies.basicAuthStrategy';
enum ScenarioEnum {
WithoutProviders,
WithProviders,
}
describe('Basic Authentication', () => {
let app: RestApplication;
SequenceHandler,
} from '@loopback/rest';
import {Client, createClientForHandler, expect, sinon} from '@loopback/testlab';
import * as chalk from 'chalk';
import {
EXAMPLE_LOG_BINDINGS,
HighResTime,
log,
LogFn,
LogMixin,
LOG_LEVEL,
} from '../..';
import {logToMemory, resetLogs} from '../in-memory-logger';
import {AddSpy, createLogSpy, restoreLogSpy} from '../log-spy';
const SequenceActions = RestBindings.SequenceActions;
describe('log extension acceptance test', () => {
let app: LogApp;
let spy: AddSpy;
class LogApp extends LogMixin(RestApplication) {}
const debugMatch: string = chalk.white(
'DEBUG: /debug :: MyController.debug() => debug called',
);
const infoMatch: string = chalk.green(
'INFO: /info :: MyController.info() => info called',
);
const warnMatch: string = chalk.yellow(
'WARN: /warn :: MyController.warn() => warn called',
);
import {
FindRoute,
InvokeMethod,
ParseParams,
Reject,
RequestContext,
RestBindings,
Send,
SequenceHandler,
} from '@loopback/rest';
import {AuthenticateFn, AuthenticationBindings} from '../../../';
import {
AUTHENTICATION_STRATEGY_NOT_FOUND,
USER_PROFILE_NOT_FOUND,
} from '../../../types';
const SequenceActions = RestBindings.SequenceActions;
export class MyAuthenticationSequence implements SequenceHandler {
constructor(
@inject(SequenceActions.FIND_ROUTE) protected findRoute: FindRoute,
@inject(SequenceActions.PARSE_PARAMS)
protected parseParams: ParseParams,
@inject(SequenceActions.INVOKE_METHOD) protected invoke: InvokeMethod,
@inject(SequenceActions.SEND) protected send: Send,
@inject(SequenceActions.REJECT) protected reject: Reject,
@inject(AuthenticationBindings.AUTH_ACTION)
protected authenticateRequest: AuthenticateFn,
) {}
async handle(context: RequestContext) {
try {
const {request, response} = context;
import {
FindRoute,
InvokeMethod,
ParseParams,
Reject,
RequestContext,
RestBindings,
Send,
SequenceHandler,
} from '@loopback/rest';
import {
AuthenticationBindings,
AuthenticateFn,
} from '@loopback/authentication';
const SequenceActions = RestBindings.SequenceActions;
export class MySequence implements SequenceHandler {
constructor(
@inject(SequenceActions.FIND_ROUTE) protected findRoute: FindRoute,
@inject(SequenceActions.PARSE_PARAMS) protected parseParams: ParseParams,
@inject(SequenceActions.INVOKE_METHOD) protected invoke: InvokeMethod,
@inject(SequenceActions.SEND) public send: Send,
@inject(SequenceActions.REJECT) public reject: Reject,
//add
@inject(AuthenticationBindings.AUTH_ACTION)
protected authenticateRequest: AuthenticateFn,
) {}
async handle(context: RequestContext) {
try {
const {request, response} = context;
RequestContext,
RestBindings,
Send,
SequenceHandler,
} from '@loopback/rest';
import {AuthenticateFn, AuthenticationBindings} from 'loopback4-authentication';
import {
AuthorizationBindings,
AuthorizeErrorKeys,
AuthorizeFn,
} from 'loopback4-authorization';
import {AuthClient} from './models';
import {AuthUser} from './modules/auth';
const SequenceActions = RestBindings.SequenceActions;
export class MySequence implements SequenceHandler {
constructor(
@inject(SequenceActions.FIND_ROUTE) protected findRoute: FindRoute,
@inject(SequenceActions.PARSE_PARAMS) protected parseParams: ParseParams,
@inject(SequenceActions.INVOKE_METHOD) protected invoke: InvokeMethod,
@inject(SequenceActions.SEND) public send: Send,
@inject(SequenceActions.REJECT) public reject: Reject,
@inject(AuthenticationBindings.USER_AUTH_ACTION)
protected authenticateRequest: AuthenticateFn,
@inject(AuthenticationBindings.CLIENT_AUTH_ACTION)
protected authenticateRequestClient: AuthenticateFn,
@inject(AuthorizationBindings.AUTHORIZE_ACTION)
protected checkAuthorisation: AuthorizeFn,
) {}
InvokeMethod,
ParseParams,
Reject,
RequestContext,
RestBindings,
Send,
SequenceHandler,
} from '@loopback/rest';
import {
AuthenticationBindings,
AuthenticateFn,
AUTHENTICATION_STRATEGY_NOT_FOUND,
USER_PROFILE_NOT_FOUND,
} from '@loopback/authentication';
const SequenceActions = RestBindings.SequenceActions;
export class MyAuthenticationSequence implements SequenceHandler {
constructor(
@inject(SequenceActions.FIND_ROUTE) protected findRoute: FindRoute,
@inject(SequenceActions.PARSE_PARAMS)
protected parseParams: ParseParams,
@inject(SequenceActions.INVOKE_METHOD) protected invoke: InvokeMethod,
@inject(SequenceActions.SEND) protected send: Send,
@inject(SequenceActions.REJECT) protected reject: Reject,
@inject(AuthenticationBindings.AUTH_ACTION)
protected authenticateRequest: AuthenticateFn,
) {}
async handle(context: RequestContext) {
try {
const {request, response} = context;