async authenticate()

in resources/oidc-provider/account/cognito_auth/index.js [22:53]


  async authenticate(email, password) {
    Log.debug(`cognitoaccount: authenticate from oidc/account/cognito just got invoked! and I have ${this.clientId} and ${this.userPoolId} `)
    return Promise.resolve()
      .then(() => new Promise((resolve, reject) => {
        // Try to log in as administrator using parameters passed from user.
        sharedConfig.cognitoIdentityServiceProvider.adminInitiateAuth({
          AuthFlow: 'ADMIN_NO_SRP_AUTH',
          ClientId: this.clientId,
          UserPoolId: this.userPoolId,
          AuthParameters: {
            USERNAME: email,
            PASSWORD: password
          }
        }, (error, data) => {
          if (error) {
            reject(error)
            return
          }
          Log.debug('cognitoaccount: Auth successful',data)
          resolve(data)
        })
      }))
      .then(data => {
        // Decode Cognito's id token and get user's sub.
        const idToken = jwt.decode(data.AuthenticationResult.IdToken)
        Log.debug('cognitoaccount: decoding JWT successful', idToken)
        return {
          sub: idToken.email,
          raw: data
        }
      })
  }