Skip to content
This repository has been archived by the owner on Jun 12, 2018. It is now read-only.

Commit

Permalink
Cut-down copy of go.apps.http_api app in go.apps.http_api_nostream.
Browse files Browse the repository at this point in the history
  • Loading branch information
jerith committed Dec 5, 2013
1 parent 0f9c247 commit 5bb2b65
Show file tree
Hide file tree
Showing 11 changed files with 1,242 additions and 0 deletions.
Empty file.
42 changes: 42 additions & 0 deletions go/apps/http_api_nostream/auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from zope.interface import implements

from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.web import resource
from twisted.cred import portal, checkers, credentials, error


class ConversationRealm(object):
implements(portal.IRealm)

def __init__(self, resource):
self.resource = resource

def requestAvatar(self, user, mind, *interfaces):
if resource.IResource in interfaces:
return (resource.IResource, self.resource, lambda: None)
raise NotImplementedError()


class ConversationAccessChecker(object):
implements(checkers.ICredentialsChecker)
credentialInterfaces = (credentials.IUsernamePassword,)

def __init__(self, vumi_api, conversation_key):
self.vumi_api = vumi_api
self.conversation_key = conversation_key

@inlineCallbacks
def requestAvatarId(self, credentials):
username = credentials.username
token = credentials.password
user_exists = yield self.vumi_api.user_exists(username)
if user_exists:
user_api = self.vumi_api.get_user_api(username)
conversation = yield user_api.get_wrapped_conversation(
self.conversation_key)
if conversation is not None:
tokens = conversation.config.get('http_api_nostream', {}).get(
'api_tokens', [])
if token in tokens:
returnValue(username)
raise error.UnauthorizedLogin()
5 changes: 5 additions & 0 deletions go/apps/http_api_nostream/definition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from go.vumitools.conversation.definition import ConversationDefinitionBase


class ConversationDefinition(ConversationDefinitionBase):
conversation_type = u'http_api_nostream'
Loading

0 comments on commit 5bb2b65

Please sign in to comment.