Skip to content

Commit 2019cfd

Browse files
authored
Merge pull request #174 from luca-nardelli/hydra-basic-auth
Allow to specify http Basic auth credentials for hydra endpoint
2 parents 1f65850 + f1e0d9f commit 2019cfd

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module.exports = {
33
'es6': true,
44
'jest': true,
55
'node': true,
6+
'browser': true
67
},
78
'parser': 'babel-eslint',
89
'parserOptions': {

src/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ program
2323
"The hydra prefix used by the API",
2424
"hydra:"
2525
)
26+
.option("--username [username]", "Username for basic auth (Hydra only)")
27+
.option("--password [password]", "Password for basic auth (Hydra only)")
2628
.option(
2729
"-g, --generator [generator]",
2830
'The generator to use, one of "react", "react-native", "vue", "admin-on-rest", "typescript", "next"',
@@ -67,13 +69,21 @@ const resourceToGenerate = program.resource
6769
const serverPath = program.serverPath ? program.serverPath.toLowerCase() : null;
6870

6971
const parser = entrypointWithSlash => {
72+
const options = {};
73+
if (program.username && program.password) {
74+
const encoded = Buffer.from(
75+
`${program.username}:${program.password}`
76+
).toString("base64");
77+
options.headers = new Headers();
78+
options.headers.set("Authorization", `Basic ${encoded}`);
79+
}
7080
switch (program.format) {
7181
case "swagger":
7282
return parseSwaggerDocumentation(entrypointWithSlash);
7383
case "openapi3":
7484
return parseOpenApi3Documentation(entrypointWithSlash);
7585
default:
76-
return parseHydraDocumentation(entrypointWithSlash);
86+
return parseHydraDocumentation(entrypointWithSlash, options);
7787
}
7888
};
7989

0 commit comments

Comments
 (0)