O'Reilly logo

Twisted Network Programming Essentials by Abe Fettig

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 6. Authentication

A requirement in almost any server application is a system for managing authentication . You need to be able to verify the identity of every user who attempts to access your server, based on their password or some other credentials. Once you allow a user to log in, you need to manage his permissions, controlling what he can and cannot do. The twisted.cred package is designed to facilitate these kinds of tasks.

Many parts of Twisted rely on twisted.cred, including the POP3, IMAP, SSH, and FTP servers. You can also use twisted.cred to add authentication to a web application, an SMTP server, a Perspective Broker server, or your own custom protocol. This chapter explains how twisted.cred works, and how to use it in your applications.

Using Authentication in a Twisted Server

There are quite a few different classes and interfaces used in twisted.cred. These classes and interfaces work together to form a flexible authentication system. This lab introduces the individual pieces of twisted.cred and shows how to tie them together to add authentication to a server.

How Do I Do That?

Set up a portal.Portal object that takes the username and password provided by a user, verifies her identity, and returns an object representing the actions and data available to that user. To do this you'll need to implement a few different twisted.cred interfaces. Example 6-1 demonstrates how to do this, adding authentication to a simple line-based server protocol.

Example 6-1. simplecred.py ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required