Comment 9 for bug 387297

Revision history for this message
Leonard Richardson (leonardr) wrote : Re: manage-credentials should not ask for Launchpad password directly

OK, as a non UI expert here is my proposed design for the console version of the trusted client. I would like to get Martin and Matthew's comments on this before I go too far into the implementation.

Usage:
    console-client [application name] [hostname] [oauth_token] [allow_permission, ...]

Examples:
    console-client "my application" edge.launchpad.net fJdXbM2tqrtbX3pHGxSM WRITE_PUBLIC WRITE_PRIVATE
    console-client "my application" staging.launchpad.net SMfJdXbM2tqrtbX3pHGx

Flow of execution:

Before console-client is run
============================

The client that invokes console-client must first obtain an OAuth
request token by POSTing to +request-token. launchpadlib will do this
automatically. This is not part of console-client because 1) we want the
code to be as small as possible, and 2) after console-client exits, the
calling code will need to look up the access token based on the request
token.

launchpadlib's credential-fetching methods will take an argument saying which
client should be run. The default is "browser", which will give the
current launchpadlib behavior. This document describes the "console"
behavior. "gtk" and "qt" behavior should be similar to "console", but
in a GUI window.

When console-client is run
==========================

0. Sanity check. Hostname must be .launchpad.net. Or maybe just stick
.launchpad.net onto [hostname].

1. Print intro.

   Launchpad credential client (console)
   -------------------------------------

   The application identified as "my application" wants to access
   Launchpad on your behalf. I'm the Launchpad credential client and
   I'm here to ask for your Launchpad username and password.

   I'll use your Launchpad password to give the application "my
   application" limited access to your Launchpad account. I will not
   show your password to the "my application" application itself.

   If you don't trust this client with your Launchpad password, use your web
   browser to visit this URL:
    https://[hostname]/+authorize-token?oauth_token=%(token)&allow_permission=%(allow_permission)

   Once you've authorized the application manually, hit Ctrl-C in this window to
   return to the application "my application".

2. Your Launchpad username: [input]

3. Your Launchpad password: [input, no echo]

4. GET /+authorize-token?oauth_token=%(token)&allow_permission=%(allow_permission) HTTP/1.1
   Host: %(hostname)
   Authorization=Basic %(username):%(password)
   Accept: application/json

5a. If denied access, print an error message and goto 2. Save the
    username as a default so user doesn't have to enter it again.

   Example:

   It looks like that username and password aren't valid on Launchpad.

5b. Parse the JSON result and extract the list of access levels. This
    list is automatically reconciled against any restrictions given in
    allow_permission.

7. Present the list of access levels to the end-user. Number them starting
   from 1. UNAUTHORIZED should always be displayed last and should be
   'numbered' Q.

   Example:

   How much access do you want to give "my application"?

   1: Change Non-Private Data
   2. Change Anything
   Q. No Access

8. POST /+authorize-token
   Authorization=Basic %(username):%(password)
   Content-Type: application/x-www-form-urlencoded

   oauth_token=%(token)&field.actions.%(access_level.name)=%(access_level.title)

   Do this even if the user chose Q--that way the token will be deactivated.

9a. If there was an error because the token is no longer valid, exit.
 If there was any other error, go to 7 and let the user try again.

9b. Exit.

    Example:

    Okay, we're done. You should now be able to use the application
    "my application" with Launchpad.

After console-client is run
===========================

The client application can now look up the access token using the
request token ID as a key. launchpadlib will do this automatically.