mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-16 21:56:25 -05:00
fix: add RemoteUser type for auth
This commit is contained in:
parent
5c2c414e03
commit
2f4dbe8564
6 changed files with 21 additions and 9 deletions
|
@ -52,7 +52,7 @@
|
|||
"devDependencies": {
|
||||
"@commitlint/cli": "6.1.3",
|
||||
"@commitlint/config-conventional": "6.1.3",
|
||||
"@verdaccio/types": "3.3.3",
|
||||
"@verdaccio/types": "3.4.0",
|
||||
"babel-cli": "6.26.0",
|
||||
"babel-core": "6.26.0",
|
||||
"babel-eslint": "8.2.2",
|
||||
|
|
|
@ -10,7 +10,7 @@ import {getDefaultPlugins} from './auth-utils';
|
|||
|
||||
import {getMatchedPackagesSpec} from './config-utils';
|
||||
|
||||
import type {Config, Logger, Callback, IPluginAuth} from '@verdaccio/types';
|
||||
import type {Config, Logger, Callback, IPluginAuth, RemoteUser} from '@verdaccio/types';
|
||||
import type {$Response, NextFunction} from 'express';
|
||||
import type {$RequestExtend, JWTPayload} from '../../types';
|
||||
import type {IAuth} from '../../types';
|
||||
|
@ -118,7 +118,7 @@ class Auth implements IAuth {
|
|||
/**
|
||||
* Allow user to access a package.
|
||||
*/
|
||||
allow_access(packageName: string, user: string, callback: Callback) {
|
||||
allow_access(packageName: string, user: RemoteUser, callback: Callback) {
|
||||
let plugins = this.plugins.slice(0);
|
||||
// $FlowFixMe
|
||||
let pkg = Object.assign({name: packageName}, getMatchedPackagesSpec(packageName, this.config.packages));
|
||||
|
|
|
@ -67,7 +67,7 @@ export const API_MESSAGE = {
|
|||
};
|
||||
|
||||
export const API_ERROR = {
|
||||
BAD_USERNAME_PASSWORD: 'bad username/password, access denied {APP}',
|
||||
BAD_USERNAME_PASSWORD: 'bad username/password, access denied',
|
||||
NO_PACKAGE: 'no such package available',
|
||||
NOT_ALLOWED: 'not allowed to access package',
|
||||
INTERNAL_SERVER_ERROR: 'internal server error',
|
||||
|
|
|
@ -9,6 +9,7 @@ import type {
|
|||
Config as AppConfig,
|
||||
PackageAccess,
|
||||
IPluginAuth,
|
||||
RemoteUser,
|
||||
Logger,
|
||||
PluginOptions
|
||||
} from '@verdaccio/types';
|
||||
|
@ -30,11 +31,11 @@ class ExampleAuthPlugin implements IPluginAuth {
|
|||
cb();
|
||||
}
|
||||
|
||||
allow_access(user: string, pkg: PackageAccess, cb: verdaccio$Callback): void {
|
||||
allow_access(user: RemoteUser, pkg: PackageAccess, cb: verdaccio$Callback): void {
|
||||
cb();
|
||||
}
|
||||
|
||||
allow_publish(user: string, pkg: PackageAccess, cb: verdaccio$Callback): void {
|
||||
allow_publish(user: RemoteUser, pkg: PackageAccess, cb: verdaccio$Callback): void {
|
||||
cb();
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +51,12 @@ const options: PluginOptions = {
|
|||
}
|
||||
|
||||
const auth = new ExampleAuthPlugin(config1, options);
|
||||
const remoteUser: RemoteUser = {
|
||||
groups: [],
|
||||
real_groups: [],
|
||||
name: 'test'
|
||||
};
|
||||
|
||||
auth.authenticate('user', 'pass', () => {});
|
||||
auth.allow_access('packageName', {}, () => {});
|
||||
auth.allow_publish('packageName', {}, () => {});
|
||||
auth.allow_access(remoteUser, {}, () => {});
|
||||
auth.allow_publish(remoteUser, {}, () => {});
|
||||
|
|
|
@ -11,14 +11,20 @@ import type {
|
|||
Config as AppConfig,
|
||||
IPluginMiddleware,
|
||||
IStorageManager,
|
||||
RemoteUser,
|
||||
IBasicAuth,
|
||||
} from '@verdaccio/types';
|
||||
import type { IUploadTarball, IReadTarball } from '@verdaccio/streams';
|
||||
|
||||
export default class ExampleMiddlewarePlugin implements IPluginMiddleware {
|
||||
register_middlewares(app: any, auth: IBasicAuth, storage: IStorageManager): void {
|
||||
const remoteUser: RemoteUser = {
|
||||
groups: [],
|
||||
real_groups: [],
|
||||
name: 'test'
|
||||
};
|
||||
auth.authenticate('user', 'password', () => {});
|
||||
auth.allow_access('packageName', 'user', () => {});
|
||||
auth.allow_access('packageName', remoteUser, () => {});
|
||||
auth.add_user('user', 'password', () => {});
|
||||
auth.aesEncrypt(new Buffer('pass'));
|
||||
// storage
|
||||
|
|
BIN
yarn.lock
BIN
yarn.lock
Binary file not shown.
Loading…
Reference in a new issue