1
# Copyright 2014 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
"""API handler: `Account`."""
6
from __future__ import (
20
from maasserver.api.support import (
24
from maasserver.api.utils import get_mandatory_param
25
from piston.utils import rc
28
class AccountHandler(OperationsHandler):
29
"""Manage the current logged-in user."""
30
api_doc_section_name = "Logged-in user"
31
create = read = update = delete = None
33
@operation(idempotent=False)
34
def create_authorisation_token(self, request):
35
"""Create an authorisation OAuth token and OAuth consumer.
37
:return: a json dict with three keys: 'token_key',
38
'token_secret' and 'consumer_key' (e.g.
39
{token_key: 's65244576fgqs', token_secret: 'qsdfdhv34',
40
consumer_key: '68543fhj854fg'}).
44
profile = request.user.get_profile()
45
consumer, token = profile.create_authorisation_token()
47
'token_key': token.key, 'token_secret': token.secret,
48
'consumer_key': consumer.key,
51
@operation(idempotent=False)
52
def delete_authorisation_token(self, request):
53
"""Delete an authorisation OAuth token and the related OAuth consumer.
55
:param token_key: The key of the token to be deleted.
56
:type token_key: unicode
58
profile = request.user.get_profile()
59
token_key = get_mandatory_param(request.data, 'token_key')
60
profile.delete_authorisation_token(token_key)
64
def resource_uri(cls, *args, **kwargs):
65
return ('account_handler', [])