~ubuntuone-pqm-team/canonical-identity-provider/trunk

« back to all changes in this revision

Viewing changes to identityprovider/webservice/interfaces.py

  • Committer: Danny Tamez
  • Date: 2010-04-21 15:29:24 UTC
  • Revision ID: danny.tamez@canonical.com-20100421152924-lq1m92tstk2iz75a
Canonical SSO Provider (Open Source) - Initial Commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2010 Canonical Ltd.  This software is licensed under the
 
2
# GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
from lazr.restful.frameworks.django import IDjangoLocation
 
5
from lazr.restful.declarations import (export_as_webservice_entry,
 
6
    collection_default_content, exported, export_write_operation,
 
7
    export_as_webservice_collection, operation_parameters,
 
8
    export_read_operation)
 
9
from zope.schema import Text, TextLine, List
 
10
 
 
11
 
 
12
__all__ = [
 
13
    'IAccount',
 
14
    'ICaptcha',
 
15
    'IAccountSet',
 
16
    'ICaptchaSet',
 
17
    'IRegistrationSet',
 
18
    'IValidationSet',
 
19
    'IAuthenticationSet'
 
20
]
 
21
 
 
22
 
 
23
class IAccount(IDjangoLocation):
 
24
    export_as_webservice_entry()
 
25
    id = exported(Text(title=u"Account ID"))
 
26
    preferred_email = exported(Text(title=u"Primary email address"))
 
27
    verified_emails = exported(List(title=u"List of verified emails",
 
28
                      value_type=Text()))
 
29
    unverified_emails = exported(List(value_type=Text(),
 
30
                        title=u"List of unverified emails"))
 
31
 
 
32
 
 
33
class IRegistration(IAccount):
 
34
    export_as_webservice_entry()
 
35
 
 
36
 
 
37
class IValidation(IAccount):
 
38
    export_as_webservice_entry()
 
39
 
 
40
 
 
41
class IAuthentication(IAccount):
 
42
    export_as_webservice_entry()
 
43
 
 
44
 
 
45
class ICaptcha(IDjangoLocation):
 
46
    export_as_webservice_entry()
 
47
    id = exported(Text(title=u"Captcha ID"))
 
48
    content = exported(Text(title=u"Captcha content"))
 
49
 
 
50
 
 
51
class IAccountSet(IDjangoLocation):
 
52
    export_as_webservice_collection(IAccount)
 
53
 
 
54
    @collection_default_content()
 
55
    def getAll():
 
56
        """Fail, as no default content should be provided."""
 
57
 
 
58
    def get(request, unique_id):
 
59
        """Retrieve a account by its ID."""
 
60
 
 
61
    @export_read_operation()
 
62
    def me():
 
63
        """ Get details for the currently authenticated user. """
 
64
 
 
65
    @operation_parameters(
 
66
        team_names=List(title=u"List of team names to check",
 
67
                        value_type=Text())
 
68
        )
 
69
    @export_read_operation()
 
70
    def team_memberships(team_names):
 
71
        """Query account for team memberships"""
 
72
 
 
73
    @operation_parameters(
 
74
        email_token=TextLine(title=u"Email validation token."))
 
75
    @export_read_operation()
 
76
    def validate_email(email_token):
 
77
        """Validate email by sending token user received in email"""
 
78
 
 
79
 
 
80
class IAuthenticationSet(IAccountSet):
 
81
    export_as_webservice_collection(IAuthentication)
 
82
 
 
83
    @collection_default_content()
 
84
    def getAll():
 
85
        """Fail, as no default content should be provided."""
 
86
 
 
87
    @operation_parameters(
 
88
        token_name=TextLine(title=u"Token name."))
 
89
    @export_read_operation()
 
90
    def authenticate(token_name):
 
91
        """Obtain OAuth token for logged in user"""
 
92
 
 
93
    @operation_parameters(
 
94
        consumer_key=TextLine(title=u"User's OpenID identifier"))
 
95
    @export_read_operation()
 
96
    def list_tokens(consumer_key):
 
97
        """ Get the currently valid tokens for a given user """
 
98
 
 
99
    @operation_parameters(
 
100
        token=TextLine(title=u"The token you want to validate"),
 
101
        consumer_key=TextLine(title=u"The consumer key (openid identifier)")
 
102
        )
 
103
    @export_read_operation()
 
104
    def validate_token(token, consumer_key):
 
105
        """Check that a token is valid.
 
106
 
 
107
        If valid, this method return the token and consumer secrets
 
108
        """
 
109
 
 
110
    @operation_parameters(
 
111
        token=TextLine(title=u"The token you want to invalidate"),
 
112
        consumer_key=TextLine(title=u"The consumer key (openid identifier)")
 
113
        )
 
114
    @export_write_operation()
 
115
    def invalidate_token(token, consumer_key):
 
116
        """ Make the given token invalid """
 
117
 
 
118
    @operation_parameters(
 
119
        team_names=List(title=u"List of team names to check",
 
120
                        value_type=Text()),
 
121
        openid_identifier=Text(title=u"OpenID Identifier used for asking for"
 
122
                               u"team memberships on behalf of other user.")
 
123
        )
 
124
    @export_read_operation()
 
125
    def team_memberships(team_names, openid_identifier):
 
126
        """Query user for team memberships"""
 
127
 
 
128
 
 
129
class IValidationSet(IAccountSet):
 
130
    pass
 
131
 
 
132
 
 
133
class IRegistrationSet(IAccountSet):
 
134
    export_as_webservice_collection(IRegistration)
 
135
 
 
136
    @collection_default_content()
 
137
    def getAll():
 
138
        """Fail, as no default content should be provided."""
 
139
 
 
140
    @operation_parameters(
 
141
        email=TextLine(title=u"Email address."),
 
142
        password=TextLine(title=u"Password should be at least 8 "
 
143
            "characters long and contain at least one uppercase letter "
 
144
            "and a number."),
 
145
        captcha_id=TextLine(title=u"ID for the generated captcha"),
 
146
        captcha_solution=TextLine(title=u"Solution for the generated "
 
147
            "captcha."))
 
148
    @export_write_operation()
 
149
    def register(email, password, captcha_id, captcha_solution):
 
150
        """ Generate a new captcha """
 
151
 
 
152
 
 
153
class ICaptchaSet(IDjangoLocation):
 
154
    export_as_webservice_collection(ICaptcha)
 
155
 
 
156
    @collection_default_content()
 
157
    def getAll():
 
158
        """Fail, as no default content should be provided."""
 
159
 
 
160
    def get(request, unique_id):
 
161
        """Retrieve a captcha by its ID."""
 
162
 
 
163
    @export_write_operation()
 
164
    def new():
 
165
        """ Generate a new captcha """