-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathconsumerCredentials.js
61 lines (52 loc) · 1.33 KB
/
consumerCredentials.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'use strict';
const schema = {
'oauth2': {
id: 'client_id'
},
'key-auth': {
id: 'key'
},
'jwt': {
id: 'key'
},
'basic-auth': {
id: 'username'
},
'hmac-auth': {
id: 'username'
}
};
export function getSupportedCredentials() {
return Object.keys(schema);
}
export function getSchema(name) {
if (false === schema.hasOwnProperty(name)) {
throw new Error(`Unknown credential "${name}"`);
}
return schema[name];
}
export function addSchema(name, val){
if (schema.hasOwnProperty(name)){
throw new Error(`There is already a schema with name '${name}'`);
}
if (!val || !val.hasOwnProperty('id')){
throw new Error(`Credential schema ${name} should have a property named "id"`);
}
schema[name] = val;
}
export function addSchemasFromOptions(opts){
if (!opts || opts.length === 0) return;
opts.forEach(val => {
var vals = val.split(':');
if (vals.length != 2) {
throw new Error(`Use <pluginname>:<keyname> format in ${val}`);
}
addSchema(vals[0], {id: vals[1]});
});
}
export function addSchemasFromConfig(config){
if (!config.credentialSchemas) return;
for (let key in config.credentialSchemas){
addSchema(key, config.credentialSchemas[key]);
}
}