本文整理汇总了TypeScript中ldapjs.createClient函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createClient函数的具体用法?TypeScript createClient怎么用?TypeScript createClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了createClient函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: authenticateLdap
static async authenticateLdap(
username: string,
password: string,
): Promise<User> {
const client = ldap.createClient({ url: 'ldaps://ldap.uchicago.edu/' });
await new Promise((resolve, reject) => {
client.bind(
`uid=${username},ou=people,dc=uchicago,dc=edu`,
password,
err => {
if (err) {
client.destroy();
reject(new Error('Either your username or password is incorrect.'));
}
resolve();
},
);
});
return new Promise<User>((resolve, reject) => {
client.search(
'dc=uchicago,dc=edu',
{
filter: `uid=${username}`,
scope: 'sub',
attributes: ['chicagoID', 'ucCurriculum', 'displayName'],
},
(err, res) => {
if (err) {
client.destroy();
reject(err);
}
let resolved = false;
res.on('searchEntry', entry => {
resolved = true;
const uid = entry.object['chicagoID'];
const displayName = entry.object['displayName'];
resolve({
uid,
displayName,
email: `${username}@uchicago.edu`,
});
});
res.on('error', error => {
client.destroy();
reject(error);
});
res.on('end', result => {
client.destroy();
if (!resolved) {
reject(new Error('LDAP record not found.'));
}
});
},
);
});
}
示例2: auth
async auth (login, password) {
const user = await this.get(login)
if (!user) return null
const client = ldap.createClient({
url: this.url,
tlsOptions: this.options.tlsOptions
})
await new Promise(((resolve, reject) => {
client.bind(user.dn, password, function (err) {
if (err) return reject(err)
resolve()
})
}))
return user
}
示例3: constructor
constructor (private url, private options: IOptions) {
this.client = ldap.createClient({
url,
tlsOptions: options.tlsOptions
})
this.options.attributes = this.options.attributes || {email: 'mail'}
if (options.filter) {
this.filter = options.filter.replace('{{user}}', `${options.loginField}={{user}}`)
} else {
this.filter = `${options.loginField}={{user}}`
}
if (options.dn) {
this.client.bind(options.dn, options.password, function (err) {
if (err) throw err
})
}
}
示例4: login
protected login(request: Request, response: Response) {
const credential = request.body;
if (!credential.username || !credential.password) {
response.status(401).json(false);
return;
}
// check LDAP
const ldap = LdapClient.createClient({ url: LDAP.uri });
ldap.bind(credential.username + LDAP.principalSuffix, credential.password, err => {
if (err) {
response.status(401).json(false);
} else {
// login success
let opts = {
filter: '(&(sAMAccountName=' + credential.username + ')(objectcategory=person))',
scope: 'sub'
};
ldap.search(LDAP.base, opts, function(err, result) {
var isInAdminGroup = false;
result.on('searchEntry', function (entry) {
if (entry.object && !err) {
let groups = entry.object["memberOf"];
for (var group of groups) {
const groupName = group.split(",", 1)[0].split("=")[1];
if (groupName == LDAP.adminGroup) {
isInAdminGroup = true;
break;
}
}
}
request.session.username = credential.username;
request.session.isAdmin = isInAdminGroup;
response.json(isInAdminGroup);
});
});
}
});
}
示例5: function
export var login = function(uid,password,successCallback,errorCallback) {
var client = ldap.createClient({
url: options.login.ldap.server
});
var userField = options.login.ldap.userField;
var userDN = options.login.ldap.userDN;
client.bind(userField+'='+uid+','+userDN, password, function(err) {
if (err) {
log.error({error:err});
errorCallback(err.message);
}
client.unbind(function(err2) {
if (err) {
// Already reported this error.
} else if (err2) {
log.error({error:err2});
errorCallback(err2.message);
} else {
successCallback();
}
});
});
};