Skip to content

Commit 5bcddcc

Browse files
Merge pull request #1449 from opencomponents/token
allow token pass
2 parents 2d98249 + 5fef4d6 commit 5bcddcc

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

src/cli/commands.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ export default {
127127
description:
128128
'username used to authenticate when publishing to registry'
129129
},
130+
token: {
131+
description: 'token used to authenticate when publishing to registry'
132+
},
130133
skipPackage: {
131134
boolean: true,
132135
description: 'Skip packaging step',

src/cli/domain/registry.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,15 @@ export default function registry(opts: RegistryOptions = {}) {
9191
async putComponent(options: {
9292
username?: string;
9393
password?: string;
94+
token?: string;
9495
route: string;
9596
path: string;
9697
}): Promise<void> {
97-
if (!!options.username && !!options.password) {
98+
if (options.token) {
99+
requestsHeaders = Object.assign(requestsHeaders, {
100+
Authorization: `Bearer ${options.token}`
101+
});
102+
} else if (!!options.username && !!options.password) {
98103
requestsHeaders = Object.assign(requestsHeaders, {
99104
Authorization:
100105
'Basic ' +

src/cli/facade/publish.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const publish = ({
2929
dryRun?: boolean;
3030
username?: string;
3131
password?: string;
32+
token?: string;
3233
registries?: string[];
3334
}): Promise<void> => {
3435
const componentPath = opts.componentPath;
@@ -46,9 +47,15 @@ const publish = ({
4647
fs.readJson(path.join(packageDir, 'package.json'));
4748

4849
const getCredentials = async (): Promise<{
49-
username: string;
50-
password: string;
50+
username?: string;
51+
password?: string;
52+
token?: string;
5153
}> => {
54+
if (opts.token) {
55+
logger.ok(strings.messages.cli.USING_CREDS);
56+
return { token: opts.token };
57+
}
58+
5259
if (opts.username && opts.password) {
5360
logger.ok(strings.messages.cli.USING_CREDS);
5461
const { username, password } = opts;
@@ -85,6 +92,7 @@ const publish = ({
8592
path: string;
8693
username?: string;
8794
password?: string;
95+
token?: string;
8896
}): Promise<void> => {
8997
logger.warn(strings.messages.cli.PUBLISHING(options.route, dryRun));
9098

@@ -93,7 +101,7 @@ const publish = ({
93101
logger.ok(strings.messages.cli.PUBLISHED(options.route, dryRun));
94102
} catch (err: any) {
95103
if (err === 'Unauthorized' || err.message === 'Unauthorized') {
96-
if (!!options.username || !!options.password) {
104+
if (!!options.username || !!options.password || !!options.token) {
97105
logger.err(
98106
strings.errors.cli.PUBLISHING_FAIL(
99107
strings.errors.cli.INVALID_CREDENTIALS

src/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import type { NextFunction, Request, Response } from 'express';
22
import type { StorageAdapter } from 'oc-storage-adapters-utils';
33
import type { PackageJson } from 'type-fest';
44

5+
type Middleware = (req: Request, res: Response, next: NextFunction) => void;
6+
57
export interface Author {
68
email?: string;
79
name?: string;
@@ -134,7 +136,7 @@ export type Authentication<T = any> = {
134136
isValid: boolean;
135137
message: string;
136138
};
137-
middleware: (config: T) => any;
139+
middleware: (config: T) => Middleware;
138140
};
139141

140142
export type PublishAuthConfig =

0 commit comments

Comments
 (0)