Try to fix Node 12 Buffer() deprecation errors.

Thanks to xet7 !
This commit is contained in:
Lauri Ojansivu 2020-01-18 16:01:02 +02:00
parent 7efbf30af6
commit 9b905c2833
8 changed files with 147 additions and 217 deletions

View file

@ -1,7 +1,8 @@
import ldapjs from 'ldapjs'; import ldapjs from 'ldapjs';
import util from 'util'; import util from 'util';
import Bunyan from 'bunyan'; import Bunyan from 'bunyan';
import { log_debug, log_info, log_warn, log_error } from './logger'; import {log_debug, log_info, log_warn, log_error} from './logger';
export default class LDAP { export default class LDAP {
constructor() { constructor() {
@ -10,66 +11,35 @@ export default class LDAP {
this.connected = false; this.connected = false;
this.options = { this.options = {
host: this.constructor.settings_get('LDAP_HOST'), host : this.constructor.settings_get('LDAP_HOST'),
port: this.constructor.settings_get('LDAP_PORT'), port : this.constructor.settings_get('LDAP_PORT'),
Reconnect: this.constructor.settings_get('LDAP_RECONNECT'), Reconnect : this.constructor.settings_get('LDAP_RECONNECT'),
timeout: this.constructor.settings_get('LDAP_TIMEOUT'), timeout : this.constructor.settings_get('LDAP_TIMEOUT'),
connect_timeout: this.constructor.settings_get('LDAP_CONNECT_TIMEOUT'), connect_timeout : this.constructor.settings_get('LDAP_CONNECT_TIMEOUT'),
idle_timeout: this.constructor.settings_get('LDAP_IDLE_TIMEOUT'), idle_timeout : this.constructor.settings_get('LDAP_IDLE_TIMEOUT'),
encryption: this.constructor.settings_get('LDAP_ENCRYPTION'), encryption : this.constructor.settings_get('LDAP_ENCRYPTION'),
ca_cert: this.constructor.settings_get('LDAP_CA_CERT'), ca_cert : this.constructor.settings_get('LDAP_CA_CERT'),
reject_unauthorized: reject_unauthorized : this.constructor.settings_get('LDAP_REJECT_UNAUTHORIZED') || false,
this.constructor.settings_get('LDAP_REJECT_UNAUTHORIZED') || false, Authentication : this.constructor.settings_get('LDAP_AUTHENTIFICATION'),
Authentication: this.constructor.settings_get('LDAP_AUTHENTIFICATION'), Authentication_UserDN : this.constructor.settings_get('LDAP_AUTHENTIFICATION_USERDN'),
Authentication_UserDN: this.constructor.settings_get( Authentication_Password : this.constructor.settings_get('LDAP_AUTHENTIFICATION_PASSWORD'),
'LDAP_AUTHENTIFICATION_USERDN', Authentication_Fallback : this.constructor.settings_get('LDAP_LOGIN_FALLBACK'),
), BaseDN : this.constructor.settings_get('LDAP_BASEDN'),
Authentication_Password: this.constructor.settings_get( Internal_Log_Level : this.constructor.settings_get('INTERNAL_LOG_LEVEL'),
'LDAP_AUTHENTIFICATION_PASSWORD', User_Authentication : this.constructor.settings_get('LDAP_USER_AUTHENTICATION'),
), User_Authentication_Field : this.constructor.settings_get('LDAP_USER_AUTHENTICATION_FIELD'),
Authentication_Fallback: this.constructor.settings_get( User_Attributes : this.constructor.settings_get('LDAP_USER_ATTRIBUTES'),
'LDAP_LOGIN_FALLBACK', User_Search_Filter : this.constructor.settings_get('LDAP_USER_SEARCH_FILTER'),
), User_Search_Scope : this.constructor.settings_get('LDAP_USER_SEARCH_SCOPE'),
BaseDN: this.constructor.settings_get('LDAP_BASEDN'), User_Search_Field : this.constructor.settings_get('LDAP_USER_SEARCH_FIELD'),
Internal_Log_Level: this.constructor.settings_get('INTERNAL_LOG_LEVEL'), Search_Page_Size : this.constructor.settings_get('LDAP_SEARCH_PAGE_SIZE'),
User_Authentication: this.constructor.settings_get( Search_Size_Limit : this.constructor.settings_get('LDAP_SEARCH_SIZE_LIMIT'),
'LDAP_USER_AUTHENTICATION', group_filter_enabled : this.constructor.settings_get('LDAP_GROUP_FILTER_ENABLE'),
), group_filter_object_class : this.constructor.settings_get('LDAP_GROUP_FILTER_OBJECTCLASS'),
User_Authentication_Field: this.constructor.settings_get( group_filter_group_id_attribute : this.constructor.settings_get('LDAP_GROUP_FILTER_GROUP_ID_ATTRIBUTE'),
'LDAP_USER_AUTHENTICATION_FIELD', group_filter_group_member_attribute: this.constructor.settings_get('LDAP_GROUP_FILTER_GROUP_MEMBER_ATTRIBUTE'),
), group_filter_group_member_format : this.constructor.settings_get('LDAP_GROUP_FILTER_GROUP_MEMBER_FORMAT'),
User_Attributes: this.constructor.settings_get('LDAP_USER_ATTRIBUTES'), group_filter_group_name : this.constructor.settings_get('LDAP_GROUP_FILTER_GROUP_NAME'),
User_Search_Filter: this.constructor.settings_get(
'LDAP_USER_SEARCH_FILTER',
),
User_Search_Scope: this.constructor.settings_get(
'LDAP_USER_SEARCH_SCOPE',
),
User_Search_Field: this.constructor.settings_get(
'LDAP_USER_SEARCH_FIELD',
),
Search_Page_Size: this.constructor.settings_get('LDAP_SEARCH_PAGE_SIZE'),
Search_Size_Limit: this.constructor.settings_get(
'LDAP_SEARCH_SIZE_LIMIT',
),
group_filter_enabled: this.constructor.settings_get(
'LDAP_GROUP_FILTER_ENABLE',
),
group_filter_object_class: this.constructor.settings_get(
'LDAP_GROUP_FILTER_OBJECTCLASS',
),
group_filter_group_id_attribute: this.constructor.settings_get(
'LDAP_GROUP_FILTER_GROUP_ID_ATTRIBUTE',
),
group_filter_group_member_attribute: this.constructor.settings_get(
'LDAP_GROUP_FILTER_GROUP_MEMBER_ATTRIBUTE',
),
group_filter_group_member_format: this.constructor.settings_get(
'LDAP_GROUP_FILTER_GROUP_MEMBER_FORMAT',
),
group_filter_group_name: this.constructor.settings_get(
'LDAP_GROUP_FILTER_GROUP_NAME',
),
}; };
} }
@ -88,13 +58,14 @@ export default class LDAP {
} }
connectSync(...args) { connectSync(...args) {
if (!this._connectSync) { if (!this._connectSync) {
this._connectSync = Meteor.wrapAsync(this.connectAsync, this); this._connectSync = Meteor.wrapAsync(this.connectAsync, this);
} }
return this._connectSync(...args); return this._connectSync(...args);
} }
searchAllSync(...args) { searchAllSync(...args) {
if (!this._searchAllSync) { if (!this._searchAllSync) {
this._searchAllSync = Meteor.wrapAsync(this.searchAllAsync, this); this._searchAllSync = Meteor.wrapAsync(this.searchAllAsync, this);
} }
@ -107,19 +78,19 @@ export default class LDAP {
let replied = false; let replied = false;
const connectionOptions = { const connectionOptions = {
url: `${this.options.host}:${this.options.port}`, url : `${this.options.host}:${this.options.port}`,
timeout: this.options.timeout, timeout : this.options.timeout,
connectTimeout: this.options.connect_timeout, connectTimeout: this.options.connect_timeout,
idleTimeout: this.options.idle_timeout, idleTimeout : this.options.idle_timeout,
reconnect: this.options.Reconnect, reconnect : this.options.Reconnect,
}; };
if (this.options.Internal_Log_Level !== 'disabled') { if (this.options.Internal_Log_Level !== 'disabled') {
connectionOptions.log = new Bunyan({ connectionOptions.log = new Bunyan({
name: 'ldapjs', name : 'ldapjs',
component: 'client', component: 'client',
stream: process.stderr, stream : process.stderr,
level: this.options.Internal_Log_Level, level : this.options.Internal_Log_Level,
}); });
} }
@ -129,12 +100,10 @@ export default class LDAP {
if (this.options.ca_cert && this.options.ca_cert !== '') { if (this.options.ca_cert && this.options.ca_cert !== '') {
// Split CA cert into array of strings // Split CA cert into array of strings
const chainLines = this.constructor const chainLines = this.constructor.settings_get('LDAP_CA_CERT').split('\n');
.settings_get('LDAP_CA_CERT') let cert = [];
.split('\n'); const ca = [];
let cert = []; chainLines.forEach((line) => {
const ca = [];
chainLines.forEach(line => {
cert.push(line); cert.push(line);
if (line.match(/-END CERTIFICATE-/)) { if (line.match(/-END CERTIFICATE-/)) {
ca.push(cert.join('\n')); ca.push(cert.join('\n'));
@ -145,7 +114,7 @@ export default class LDAP {
} }
if (this.options.encryption === 'ssl') { if (this.options.encryption === 'ssl') {
connectionOptions.url = `ldaps://${connectionOptions.url}`; connectionOptions.url = `ldaps://${connectionOptions.url}`;
connectionOptions.tlsOptions = tlsOptions; connectionOptions.tlsOptions = tlsOptions;
} else { } else {
connectionOptions.url = `ldap://${connectionOptions.url}`; connectionOptions.url = `ldap://${connectionOptions.url}`;
@ -158,7 +127,7 @@ export default class LDAP {
this.bindSync = Meteor.wrapAsync(this.client.bind, this.client); this.bindSync = Meteor.wrapAsync(this.client.bind, this.client);
this.client.on('error', error => { this.client.on('error', (error) => {
log_error('connection', error); log_error('connection', error);
if (replied === false) { if (replied === false) {
replied = true; replied = true;
@ -202,7 +171,7 @@ export default class LDAP {
} }
}); });
} else { } else {
this.client.on('connect', response => { this.client.on('connect', (response) => {
log_info('LDAP connected'); log_info('LDAP connected');
this.connected = true; this.connected = true;
if (replied === false) { if (replied === false) {
@ -232,9 +201,7 @@ export default class LDAP {
} }
} }
const usernameFilter = this.options.User_Search_Field.split(',').map( const usernameFilter = this.options.User_Search_Field.split(',').map((item) => `(${item}=${username})`);
item => `(${item}=${username})`,
);
if (usernameFilter.length === 0) { if (usernameFilter.length === 0) {
log_error('LDAP_LDAP_User_Search_Field not defined'); log_error('LDAP_LDAP_User_Search_Field not defined');
@ -248,6 +215,7 @@ export default class LDAP {
} }
bindUserIfNecessary(username, password) { bindUserIfNecessary(username, password) {
if (this.domainBinded === true) { if (this.domainBinded === true) {
return; return;
} }
@ -256,6 +224,7 @@ export default class LDAP {
return; return;
} }
if (!this.options.BaseDN) throw new Error('BaseDN is not provided'); if (!this.options.BaseDN) throw new Error('BaseDN is not provided');
const userDn = `${this.options.User_Authentication_Field}=${username},${this.options.BaseDN}`; const userDn = `${this.options.User_Authentication_Field}=${username},${this.options.BaseDN}`;
@ -275,27 +244,23 @@ export default class LDAP {
log_info('Binding UserDN', this.options.Authentication_UserDN); log_info('Binding UserDN', this.options.Authentication_UserDN);
this.bindSync( this.bindSync(this.options.Authentication_UserDN, this.options.Authentication_Password);
this.options.Authentication_UserDN,
this.options.Authentication_Password,
);
this.domainBinded = true; this.domainBinded = true;
} }
searchUsersSync(username, page) { searchUsersSync(username, page) {
this.bindIfNecessary(); this.bindIfNecessary();
const searchOptions = { const searchOptions = {
filter: this.getUserFilter(username), filter : this.getUserFilter(username),
scope: this.options.User_Search_Scope || 'sub', scope : this.options.User_Search_Scope || 'sub',
sizeLimit: this.options.Search_Size_Limit, sizeLimit: this.options.Search_Size_Limit,
}; };
if (!!this.options.User_Attributes) if (!!this.options.User_Attributes) searchOptions.attributes = this.options.User_Attributes.split(',');
searchOptions.attributes = this.options.User_Attributes.split(',');
if (this.options.Search_Page_Size > 0) { if (this.options.Search_Page_Size > 0) {
searchOptions.paged = { searchOptions.paged = {
pageSize: this.options.Search_Page_Size, pageSize : this.options.Search_Page_Size,
pagePause: !!page, pagePause: !!page,
}; };
} }
@ -314,9 +279,7 @@ export default class LDAP {
getUserByIdSync(id, attribute) { getUserByIdSync(id, attribute) {
this.bindIfNecessary(); this.bindIfNecessary();
const Unique_Identifier_Field = this.constructor const Unique_Identifier_Field = this.constructor.settings_get('LDAP_UNIQUE_IDENTIFIER_FIELD').split(',');
.settings_get('LDAP_UNIQUE_IDENTIFIER_FIELD')
.split(',');
let filter; let filter;
@ -327,13 +290,11 @@ export default class LDAP {
}); });
} else { } else {
const filters = []; const filters = [];
Unique_Identifier_Field.forEach(item => { Unique_Identifier_Field.forEach((item) => {
filters.push( filters.push(new this.ldapjs.filters.EqualityFilter({
new this.ldapjs.filters.EqualityFilter({ attribute: item,
attribute: item, value : new Buffer(id, 'hex'),
value: new Buffer(id, 'hex'), }));
}),
);
}); });
filter = new this.ldapjs.filters.OrFilter({ filters }); filter = new this.ldapjs.filters.OrFilter({ filters });
@ -366,7 +327,7 @@ export default class LDAP {
const searchOptions = { const searchOptions = {
filter: this.getUserFilter(username), filter: this.getUserFilter(username),
scope: this.options.User_Search_Scope || 'sub', scope : this.options.User_Search_Scope || 'sub',
}; };
log_info('Searching user', username); log_info('Searching user', username);
@ -380,13 +341,7 @@ export default class LDAP {
} }
if (result.length > 1) { if (result.length > 1) {
log_error( log_error('Search by username', username, 'returned', result.length, 'records');
'Search by username',
username,
'returned',
result.length,
'records',
);
} }
return result[0]; return result[0];
@ -404,12 +359,9 @@ export default class LDAP {
} }
if (this.options.group_filter_group_member_attribute !== '') { if (this.options.group_filter_group_member_attribute !== '') {
const format_value = const format_value = ldapUser[this.options.group_filter_group_member_format];
ldapUser[this.options.group_filter_group_member_format];
if (format_value) { if (format_value) {
filter.push( filter.push(`(${this.options.group_filter_group_member_attribute}=${format_value})`);
`(${this.options.group_filter_group_member_attribute}=${format_value})`,
);
} }
} }
@ -417,7 +369,7 @@ export default class LDAP {
const searchOptions = { const searchOptions = {
filter: filter.join('').replace(/#{username}/g, username), filter: filter.join('').replace(/#{username}/g, username),
scope: 'sub', scope : 'sub',
}; };
log_debug('Group list filter LDAP:', searchOptions.filter); log_debug('Group list filter LDAP:', searchOptions.filter);
@ -429,12 +381,13 @@ export default class LDAP {
} }
const grp_identifier = this.options.group_filter_group_id_attribute || 'cn'; const grp_identifier = this.options.group_filter_group_id_attribute || 'cn';
const groups = []; const groups = [];
result.map(item => { result.map((item) => {
groups.push(item[grp_identifier]); groups.push(item[grp_identifier]);
}); });
log_debug(`Groups: ${groups.join(', ')}`); log_debug(`Groups: ${groups.join(', ')}`);
return groups; return groups;
} }
isUserInGroup(username, ldapUser) { isUserInGroup(username, ldapUser) {
@ -451,25 +404,20 @@ export default class LDAP {
} }
if (this.options.group_filter_group_member_attribute !== '') { if (this.options.group_filter_group_member_attribute !== '') {
const format_value = const format_value = ldapUser[this.options.group_filter_group_member_format];
ldapUser[this.options.group_filter_group_member_format];
if (format_value) { if (format_value) {
filter.push( filter.push(`(${this.options.group_filter_group_member_attribute}=${format_value})`);
`(${this.options.group_filter_group_member_attribute}=${format_value})`,
);
} }
} }
if (this.options.group_filter_group_id_attribute !== '') { if (this.options.group_filter_group_id_attribute !== '') {
filter.push( filter.push(`(${this.options.group_filter_group_id_attribute}=${this.options.group_filter_group_name})`);
`(${this.options.group_filter_group_id_attribute}=${this.options.group_filter_group_name})`,
);
} }
filter.push(')'); filter.push(')');
const searchOptions = { const searchOptions = {
filter: filter.join('').replace(/#{username}/g, username), filter: filter.join('').replace(/#{username}/g, username),
scope: 'sub', scope : 'sub',
}; };
log_debug('Group filter LDAP:', searchOptions.filter); log_debug('Group filter LDAP:', searchOptions.filter);
@ -487,7 +435,7 @@ export default class LDAP {
_raw: entry.raw, _raw: entry.raw,
}; };
Object.keys(values._raw).forEach(key => { Object.keys(values._raw).forEach((key) => {
const value = values._raw[key]; const value = values._raw[key];
if (!['thumbnailPhoto', 'jpegPhoto'].includes(key)) { if (!['thumbnailPhoto', 'jpegPhoto'].includes(key)) {
@ -510,12 +458,11 @@ export default class LDAP {
// Force LDAP idle to wait the record processing // Force LDAP idle to wait the record processing
this.client._updateIdle(true); this.client._updateIdle(true);
page(null, entries, { page(null, entries, {
end, end, next: () => {
next: () => {
// Reset idle timer // Reset idle timer
this.client._updateIdle(); this.client._updateIdle();
next && next(); next && next();
}, }
}); });
}; };
@ -526,7 +473,7 @@ export default class LDAP {
return; return;
} }
res.on('error', error => { res.on('error', (error) => {
log_error(error); log_error(error);
page(error); page(error);
return; return;
@ -534,19 +481,16 @@ export default class LDAP {
let entries = []; let entries = [];
const internalPageSize = const internalPageSize = options.paged && options.paged.pageSize > 0 ? options.paged.pageSize * 2 : 500;
options.paged && options.paged.pageSize > 0
? options.paged.pageSize * 2
: 500;
res.on('searchEntry', entry => { res.on('searchEntry', (entry) => {
entries.push(this.extractLdapEntryData(entry)); entries.push(this.extractLdapEntryData(entry));
if (entries.length >= internalPageSize) { if (entries.length >= internalPageSize) {
processPage({ processPage({
entries, entries,
title: 'Internal Page', title: 'Internal Page',
end: false, end : false,
}); });
entries = []; entries = [];
} }
@ -558,14 +502,14 @@ export default class LDAP {
processPage({ processPage({
entries, entries,
title: 'Final Page', title: 'Final Page',
end: true, end : true,
}); });
} else if (entries.length) { } else if (entries.length) {
log_info('Page'); log_info('Page');
processPage({ processPage({
entries, entries,
title: 'Page', title: 'Page',
end: false, end : false,
next, next,
}); });
entries = []; entries = [];
@ -577,7 +521,7 @@ export default class LDAP {
processPage({ processPage({
entries, entries,
title: 'Final Page', title: 'Final Page',
end: true, end : true,
}); });
entries = []; entries = [];
} }
@ -595,7 +539,7 @@ export default class LDAP {
return; return;
} }
res.on('error', error => { res.on('error', (error) => {
log_error(error); log_error(error);
callback(error); callback(error);
return; return;
@ -603,7 +547,7 @@ export default class LDAP {
const entries = []; const entries = [];
res.on('searchEntry', entry => { res.on('searchEntry', (entry) => {
entries.push(this.extractLdapEntryData(entry)); entries.push(this.extractLdapEntryData(entry));
}); });
@ -632,7 +576,7 @@ export default class LDAP {
} }
disconnect() { disconnect() {
this.connected = false; this.connected = false;
this.domainBinded = false; this.domainBinded = false;
log_info('Disconecting'); log_info('Disconecting');
this.client.unbind(); this.client.unbind();

View file

@ -1,12 +1,13 @@
Oidc = {}; Oidc = {};
OAuth.registerService('oidc', 2, null, function(query) { OAuth.registerService('oidc', 2, null, function (query) {
var debug = process.env.DEBUG || false; var debug = process.env.DEBUG || false;
var token = getToken(query); var token = getToken(query);
if (debug) console.log('XXX: register token:', token); if (debug) console.log('XXX: register token:', token);
var accessToken = token.access_token || token.id_token; var accessToken = token.access_token || token.id_token;
var expiresAt = +new Date() + 1000 * parseInt(token.expires_in, 10); var expiresAt = (+new Date) + (1000 * parseInt(token.expires_in, 10));
var userinfo = getUserInfo(accessToken); var userinfo = getUserInfo(accessToken);
if (debug) console.log('XXX: userinfo:', userinfo); if (debug) console.log('XXX: userinfo:', userinfo);
@ -21,14 +22,12 @@ OAuth.registerService('oidc', 2, null, function(query) {
if (accessToken) { if (accessToken) {
var tokenContent = getTokenContent(accessToken); var tokenContent = getTokenContent(accessToken);
var fields = _.pick( var fields = _.pick(tokenContent, getConfiguration().idTokenWhitelistFields);
tokenContent,
getConfiguration().idTokenWhitelistFields,
);
_.extend(serviceData, fields); _.extend(serviceData, fields);
} }
if (token.refresh_token) serviceData.refreshToken = token.refresh_token; if (token.refresh_token)
serviceData.refreshToken = token.refresh_token;
if (debug) console.log('XXX: serviceData:', serviceData); if (debug) console.log('XXX: serviceData:', serviceData);
var profile = {}; var profile = {};
@ -38,101 +37,88 @@ OAuth.registerService('oidc', 2, null, function(query) {
return { return {
serviceData: serviceData, serviceData: serviceData,
options: { profile: profile }, options: { profile: profile }
}; };
}); });
var userAgent = 'Meteor'; var userAgent = "Meteor";
if (Meteor.release) { if (Meteor.release) {
userAgent += '/' + Meteor.release; userAgent += "/" + Meteor.release;
} }
var getToken = function(query) { var getToken = function (query) {
var debug = process.env.DEBUG || false; var debug = process.env.DEBUG || false;
var config = getConfiguration(); var config = getConfiguration();
if (config.tokenEndpoint.includes('https://')) { if(config.tokenEndpoint.includes('https://')){
var serverTokenEndpoint = config.tokenEndpoint; var serverTokenEndpoint = config.tokenEndpoint;
} else { }else{
var serverTokenEndpoint = config.serverUrl + config.tokenEndpoint; var serverTokenEndpoint = config.serverUrl + config.tokenEndpoint;
} }
var requestPermissions = config.requestPermissions; var requestPermissions = config.requestPermissions;
var response; var response;
try { try {
response = HTTP.post(serverTokenEndpoint, { response = HTTP.post(
headers: { serverTokenEndpoint,
Accept: 'application/json', {
'User-Agent': userAgent, headers: {
}, Accept: 'application/json',
params: { "User-Agent": userAgent
code: query.code, },
client_id: config.clientId, params: {
client_secret: OAuth.openSecret(config.secret), code: query.code,
redirect_uri: OAuth._redirectUri('oidc', config), client_id: config.clientId,
grant_type: 'authorization_code', client_secret: OAuth.openSecret(config.secret),
scope: requestPermissions, redirect_uri: OAuth._redirectUri('oidc', config),
state: query.state, grant_type: 'authorization_code',
}, scope: requestPermissions,
}); state: query.state
} catch (err) { }
throw _.extend( }
new Error(
'Failed to get token from OIDC ' +
serverTokenEndpoint +
': ' +
err.message,
),
{ response: err.response },
); );
} catch (err) {
throw _.extend(new Error("Failed to get token from OIDC " + serverTokenEndpoint + ": " + err.message),
{ response: err.response });
} }
if (response.data.error) { if (response.data.error) {
// if the http response was a json object with an error attribute // if the http response was a json object with an error attribute
throw new Error( throw new Error("Failed to complete handshake with OIDC " + serverTokenEndpoint + ": " + response.data.error);
'Failed to complete handshake with OIDC ' +
serverTokenEndpoint +
': ' +
response.data.error,
);
} else { } else {
if (debug) console.log('XXX: getToken response: ', response.data); if (debug) console.log('XXX: getToken response: ', response.data);
return response.data; return response.data;
} }
}; };
var getUserInfo = function(accessToken) { var getUserInfo = function (accessToken) {
var debug = process.env.DEBUG || false; var debug = process.env.DEBUG || false;
var config = getConfiguration(); var config = getConfiguration();
// Some userinfo endpoints use a different base URL than the authorization or token endpoints. // Some userinfo endpoints use a different base URL than the authorization or token endpoints.
// This logic allows the end user to override the setting by providing the full URL to userinfo in their config. // This logic allows the end user to override the setting by providing the full URL to userinfo in their config.
if (config.userinfoEndpoint.includes('https://')) { if (config.userinfoEndpoint.includes("https://")) {
var serverUserinfoEndpoint = config.userinfoEndpoint; var serverUserinfoEndpoint = config.userinfoEndpoint;
} else { } else {
var serverUserinfoEndpoint = config.serverUrl + config.userinfoEndpoint; var serverUserinfoEndpoint = config.serverUrl + config.userinfoEndpoint;
} }
var response; var response;
try { try {
response = HTTP.get(serverUserinfoEndpoint, { response = HTTP.get(
headers: { serverUserinfoEndpoint,
'User-Agent': userAgent, {
Authorization: 'Bearer ' + accessToken, headers: {
}, "User-Agent": userAgent,
}); "Authorization": "Bearer " + accessToken
} catch (err) { }
throw _.extend( }
new Error(
'Failed to fetch userinfo from OIDC ' +
serverUserinfoEndpoint +
': ' +
err.message,
),
{ response: err.response },
); );
} catch (err) {
throw _.extend(new Error("Failed to fetch userinfo from OIDC " + serverUserinfoEndpoint + ": " + err.message),
{response: err.response});
} }
if (debug) console.log('XXX: getUserInfo response: ', response.data); if (debug) console.log('XXX: getUserInfo response: ', response.data);
return response.data; return response.data;
}; };
var getConfiguration = function() { var getConfiguration = function () {
var config = ServiceConfiguration.configurations.findOne({ service: 'oidc' }); var config = ServiceConfiguration.configurations.findOne({ service: 'oidc' });
if (!config) { if (!config) {
throw new ServiceConfiguration.ConfigError('Service oidc not configured.'); throw new ServiceConfiguration.ConfigError('Service oidc not configured.');
@ -140,7 +126,7 @@ var getConfiguration = function() {
return config; return config;
}; };
var getTokenContent = function(token) { var getTokenContent = function (token) {
var content = null; var content = null;
if (token) { if (token) {
try { try {
@ -151,13 +137,13 @@ var getTokenContent = function(token) {
var signed = parts[0] + '.' + parts[1]; var signed = parts[0] + '.' + parts[1];
} catch (err) { } catch (err) {
this.content = { this.content = {
exp: 0, exp: 0
}; };
} }
} }
return content; return content;
}; }
Oidc.retrieveCredential = function(credentialToken, credentialSecret) { Oidc.retrieveCredential = function (credentialToken, credentialSecret) {
return OAuth.retrieveCredential(credentialToken, credentialSecret); return OAuth.retrieveCredential(credentialToken, credentialSecret);
}; };

View file

@ -451,10 +451,10 @@ FS.HTTP.Handlers.Get = function (ref) {
if(userAgent.indexOf('msie') >= 0 || userAgent.indexOf('trident') >= 0 || userAgent.indexOf('chrome') >= 0) { if(userAgent.indexOf('msie') >= 0 || userAgent.indexOf('trident') >= 0 || userAgent.indexOf('chrome') >= 0) {
ref.filename = encodeURIComponent(ref.filename); ref.filename = encodeURIComponent(ref.filename);
} else if(userAgent.indexOf('firefox') >= 0) { } else if(userAgent.indexOf('firefox') >= 0) {
ref.filename = new Buffer.alloc(ref.filename).toString('binary'); ref.filename = Buffer.from(ref.filename).toString('binary');
} else { } else {
/* safari*/ /* safari*/
ref.filename = new Buffer.alloc(ref.filename).toString('binary'); ref.filename = Buffer.from(ref.filename).toString('binary');
} }
} catch (ex){ } catch (ex){
ref.filename = 'tempfix'; ref.filename = 'tempfix';

View file

@ -138,7 +138,7 @@ export class Exporter {
// [Old] for attachments we only export IDs and absolute url to original doc // [Old] for attachments we only export IDs and absolute url to original doc
// [New] Encode attachment to base64 // [New] Encode attachment to base64
const getBase64Data = function(doc, callback) { const getBase64Data = function(doc, callback) {
let buffer = new Buffer.alloc(0); let buffer = Buffer.from(0);
// callback has the form function (err, res) {} // callback has the form function (err, res) {}
const tmpFile = path.join( const tmpFile = path.join(
os.tmpdir(), os.tmpdir(),

View file

@ -441,7 +441,7 @@ export class WekanCreator {
}); });
} else if (att.file) { } else if (att.file) {
file.attachData( file.attachData(
new Buffer.alloc(att.file, 'base64'), Buffer.from(att.file, 'base64'),
{ {
type: att.type, type: att.type,
}, },

View file

@ -286,14 +286,14 @@ export default class LDAP {
if (attribute) { if (attribute) {
filter = new this.ldapjs.filters.EqualityFilter({ filter = new this.ldapjs.filters.EqualityFilter({
attribute, attribute,
value: new Buffer.alloc(id, 'hex'), value: Buffer.from(id, 'hex'),
}); });
} else { } else {
const filters = []; const filters = [];
Unique_Identifier_Field.forEach((item) => { Unique_Identifier_Field.forEach((item) => {
filters.push(new this.ldapjs.filters.EqualityFilter({ filters.push(new this.ldapjs.filters.EqualityFilter({
attribute: item, attribute: item,
value : new Buffer.alloc(id, 'hex'), value : Buffer.from(id, 'hex'),
})); }));
}); });

View file

@ -131,9 +131,9 @@ var getTokenContent = function (token) {
if (token) { if (token) {
try { try {
var parts = token.split('.'); var parts = token.split('.');
var header = JSON.parse(new Buffer.alloc(parts[0], 'base64').toString()); var header = JSON.parse(Buffer.from(parts[0], 'base64').toString());
content = JSON.parse(new Buffer.alloc(parts[1], 'base64').toString()); content = JSON.parse(Buffer.from(parts[1], 'base64').toString());
var signature = new Buffer.alloc(parts[2], 'base64'); var signature = Buffer.from(parts[2], 'base64');
var signed = parts[0] + '.' + parts[1]; var signed = parts[0] + '.' + parts[1];
} catch (err) { } catch (err) {
this.content = { this.content = {

View file

@ -55,7 +55,7 @@ if (isSandstorm && Meteor.isServer) {
const parsedDescriptor = Capnp.parse( const parsedDescriptor = Capnp.parse(
Powerbox.PowerboxDescriptor, Powerbox.PowerboxDescriptor,
new Buffer.alloc(descriptor, 'base64'), Buffer.from(descriptor, 'base64'),
{ packed: true }, { packed: true },
); );