61
63
salgado_with_full_permissions = KnownTokens('salgado-change-anything', 'test')
62
64
salgado_read_nonprivate = KnownTokens('salgado-read-nonprivate', 'secret')
63
65
nopriv_read_nonprivate = KnownTokens('nopriv-read-nonprivate', 'mystery')
68
class ScriptableRequestTokenAuthorization(AuthorizeRequestTokenProcess):
69
"""A request token process that doesn't need any user input.
71
The AuthorizeRequestTokenProcess is supposed to be hooked up to a
72
user interface, but that makes it difficult to test. This subclass
73
is designed to be easy to test.
76
def __init__(self, consumer_name, username, password, choose_access_level,
77
allow_access_levels=[], max_failed_attempts=2,
78
web_root="http://launchpad.dev:8085/"):
80
# Get a request token.
81
self.credentials = Credentials(consumer_name)
82
self.credentials.get_request_token(web_root=web_root)
84
# Initialize the superclass with the new request token.
85
super(ScriptableRequestTokenAuthorization, self).__init__(
86
web_root, consumer_name, self.credentials._request_token.key,
87
allow_access_levels, max_failed_attempts)
89
self.username = username
90
self.password = password
91
self.choose_access_level = choose_access_level
94
super(ScriptableRequestTokenAuthorization, self).__call__()
96
# Now verify that it worked by exchanging the authorized
97
# request token for an access token.
98
if self.choose_access_level != self.UNAUTHORIZED_ACCESS_LEVEL:
99
self.credentials.exchange_request_token_for_access_token(
100
web_root=self.web_root)
101
return self.credentials.access_token
104
def open_login_page_in_user_browser(self, url):
105
"""Print a status message."""
106
print ("[If this were a real application, the end-user's web "
107
"browser would be opened to %s]" % url)
109
def setup(self, suggested_message):
110
print suggested_message
112
def input_username(self, cached_username, suggested_message):
113
"""Collect the Launchpad username from the end-user."""
114
print suggested_message
115
if cached_username is not None:
116
print "Cached username: " + cached_username
119
def input_password(self, suggested_message):
120
"""Collect the Launchpad password from the end-user."""
121
print suggested_message
124
def input_access_level(self, available_levels, suggested_message):
125
"""Collect the desired level of access from the end-user."""
126
print suggested_message
127
print [level['value'] for level in available_levels]
128
return self.choose_access_level
130
def authentication_failure(self, suggested_message):
131
"""The user entered invalid credentials."""
132
print suggested_message
134
def user_refused_to_authorize(self, suggested_message):
135
"""The user refused to authorize a request token."""
136
print suggested_message
138
def user_authorized(self, access_level, suggested_message):
139
"""The user authorized a request token with some access level."""
140
print suggested_message
142
def server_consumer_differs_from_client_consumer(
143
self, client_name, real_name, suggested_message):
144
"""The client seems to be lying or mistaken about its name."""
145
print suggested_message
147
def success(self, suggested_message):
148
"""The token was successfully authorized."""
149
print suggested_message