loopback4-authentication
Version:
A loopback-next extension for authentication feature. Various Oauth strategies supported by this package.
70 lines (55 loc) • 2.05 kB
text/typescript
import {BindingKey, Constructor} from '@loopback/context';
import {MetadataAccessor} from '@loopback/metadata';
import {Strategy} from 'passport';
import {
AuthenticateFn,
AuthenticationConfig,
AuthenticationMetadata,
EntityWithIdentifier,
IAuthClient,
IAuthUser,
} from './types';
export * from './strategies/keys';
/**
* Binding keys used by this component.
*/
export namespace AuthenticationBindings {
export const USER_STRATEGY = BindingKey.create<Strategy | undefined>(
'sf.userAuthentication.strategy',
);
export const CLIENT_STRATEGY = BindingKey.create<Strategy | undefined>(
'sf.clientAuthentication.strategy',
);
export const USER_AUTH_ACTION = BindingKey.create<
AuthenticateFn<IAuthUser | undefined>
>('sf.userAuthentication.actions.authenticate');
export const CLIENT_AUTH_ACTION = BindingKey.create<
AuthenticateFn<IAuthClient | undefined>
>('sf.clientAuthentication.actions.authenticate');
export const USER_METADATA = BindingKey.create<
AuthenticationMetadata | undefined
>('sf.userAuthentication.operationMetadata');
export const CLIENT_METADATA = BindingKey.create<
AuthenticationMetadata | undefined
>('sf.clientAuthentication.operationMetadata');
export const CURRENT_USER = BindingKey.create<IAuthUser | undefined>(
'sf.userAuthentication.currentUser',
);
export const CURRENT_CLIENT = BindingKey.create<IAuthClient | undefined>(
'sf.clientAuthentication.currentClient',
);
export const CONFIG = BindingKey.create<AuthenticationConfig>(
'sf.userAuthentication.config',
);
export const USER_MODEL = BindingKey.create<
Constructor<EntityWithIdentifier>
>('sf.userAuthentication.userModel');
}
export const USER_AUTHENTICATION_METADATA_KEY = MetadataAccessor.create<
AuthenticationMetadata,
MethodDecorator
>('userAuthentication.operationsMetadata');
export const CLIENT_AUTHENTICATION_METADATA_KEY = MetadataAccessor.create<
AuthenticationMetadata,
MethodDecorator
>('clientAuthentication.operationsMetadata');