当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript ldapjs.createClient函数代码示例

本文整理汇总了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.'));
           }
         });
       },
     );
   });
 }
开发者ID:kevmo314,项目名称:canigraduate.uchicago.edu,代码行数:56,代码来源:Users.ts

示例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
 }
开发者ID:bangbang93,项目名称:cnpm.org-ldap,代码行数:15,代码来源:index.ts

示例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
      })
    }
  }
开发者ID:bangbang93,项目名称:cnpm.org-ldap,代码行数:18,代码来源:index.ts

示例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);
          });
        });
      }
    });
  }
开发者ID:apache,项目名称:helix,代码行数:41,代码来源:user.ts

示例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();
      }
    });
  });
};
开发者ID:MisterTea,项目名称:TidalWave,代码行数:23,代码来源:auth-ldap.ts


注:本文中的ldapjs.createClient函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。