當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。