async findAccount()

in resources/oidc-provider/account/cognito_auth/index.js [55:90]


  async findAccount(ctx, id) {
    Log.debug(`cognitoaccount: about to find user ${id} in cognito in userpool ${this.userPoolId}`, ctx)
    return Promise.resolve()
      .then(() => new Promise((resolve, reject) => {
        sharedConfig.cognitoIdentityServiceProvider.listUsers({
          UserPoolId: this.userPoolId,
          Filter: `email = "${id}"`,
          Limit: 1
        }, (error, results) => {
          Log.debug('cognitoaccount: cognito listusers response', error, results)
          if (error || results.Users.length === 0) {
            reject((error) || new Error())
            return
          }
          resolve(results.Users[0])
        })
      }))
      .then(data => {
        Log.debug('cognitoaccount: cognito claims: received', data)
        // Return the value of Cognito's UserAttributes as claims.

        const claims = async (use, scope, claims, rejected) => {
          Log.debug(`cognitoaccount: claims was called with use: ${use}, scope: ${scope}, claims: ${claims}, rejected: ${rejected}, data: ${data}`)
          const clms = data.Attributes.reduce((acc, current) => {
            acc[current.Name] = current.Value
            return acc
          }, {})
          clms.tenantid=this.tenant_id
          Log.debug('cognitoaccount: claims will return!', clms)
          return clms

        }
        
        return new CognitoAccount(id, claims, this.userPoolId, this.clientId, this.tenant_id)
      })
  }