From c6ec6463c294fe3f14e258036e494d8e61ca328d Mon Sep 17 00:00:00 2001 From: Yanick Dickbauer Date: Tue, 11 Jan 2022 21:41:09 +0100 Subject: [PATCH] Add Authentication Headers to Auth Config --- Gruntfile.js | 6 +++++- README.md | 10 +++++++++- tasks/lib/index.js | 12 ++++++++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index ee52679..c331c4c 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -17,7 +17,11 @@ module.exports = function (grunt) { packaging: 'zip', auth: { username: auth.username, - password: auth.password + password: auth.password, + headers: { + 'Authorization': 'Bearer token123', + 'Private-Token': 'secret-api-token' + } }, pomDir: 'test/actual/releases', url: 'http://localhost:8081/nexus/content/repositories/releases', diff --git a/README.md b/README.md index e9976c5..e5804ad 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,14 @@ Default value: `''` Username to be used for authentication against nexus server +#### options.auth.headers +Type: `Object` +Default value: `{}` + +A key-value pair where each will be passed as Http Request Header to authenticate against nexus server. +E.g. Personal Access Token instead of username/password: +`{Authorization: 'Bearer secret-token'}` + #### options.insecure Type: `boolean` Default value: `false` @@ -166,4 +174,4 @@ Whether to upload artifacts in parallel. Type: `Boolean` Default value: `'false'` -Chatty flag. \ No newline at end of file +Chatty flag. diff --git a/tasks/lib/index.js b/tasks/lib/index.js index 8157cd9..def4949 100644 --- a/tasks/lib/index.js +++ b/tasks/lib/index.js @@ -83,8 +83,16 @@ var createAndUploadArtifacts = function (options, done) { curlOptions.push('/dev/stderr'); } if (options.auth) { - curlOptions.push('-u'); - curlOptions.push('"'+options.auth.username + ":" + options.auth.password+'"'); + if (options.auth.username && options.auth.password) { + curlOptions.push('-u'); + curlOptions.push('"' + options.auth.username + ":" + options.auth.password + '"'); + } + if (options.auth.headers) { + Object.keys(options.auth.headers).map(function (key) { + curlOptions.push('--header'); + curlOptions.push('"' + key + ': ' + options.auth.headers[key] + '"'); + }); + } } if (options.insecure) {