'Try to authenticate using TOTP.'

def authenticate(self, request, auth_payload):

    response_data = {}
    user_info = plugins.TOTPUserInfo.create(auth_payload, METHOD_NAME)
    auth_passcode = auth_payload.get('user').get('passcode')
    credentials = self.credential_api.list_credentials_for_user(user_info.user_id, type='totp')
    valid_passcode = False
    for credential in credentials:
        try:
            generated_passcode = _generate_totp_passcode(credential['blob'])
            if (auth_passcode == generated_passcode):
                valid_passcode = True
                break
        except (ValueError, KeyError):
            LOG.debug('No    TOTP    match;    credential    id:    %s,    user_id:    %s', credential['id'], user_info.user_id)
        except TypeError:
            LOG.debug('Base32    decode    failed    for    TOTP    credential    %s', credential['id'])
    if (not valid_passcode):
        msg = _('Invalid    username    or    TOTP    passcode')
        raise exception.Unauthorized(msg)
    response_data['user_id'] = user_info.user_id
    return base.AuthHandlerResponse(status=True, response_body=None, response_data=response_data)
