Skip to content

Commit

Permalink
Merge pull request #31 from canonical/u1
Browse files Browse the repository at this point in the history
docs: tutorial for logging in using Ubuntu One (CRAFT-692)
  • Loading branch information
sergiusens committed Dec 2, 2021
2 parents 157df86 + d077b15 commit cd55cc1
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions docs/tutorials.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,97 @@ Run the saved python module to login::
$ python snap_store_login.py


Login to the Snap Store using Ubuntu One
========================================

At the end of this tutorial you will have successfully written a
script that can log you into the Snap Store using Ubuntu One
(https://login.ubuntu.com) and have those credentials stored for the
combination of Dashboard endpoint (https://dashboard.snapcraft.io) and
application name (``ubuntu1-dashboard``).

Prerequisites
-------------

- Python 3.8 or 3.9
- a clean virtual environment setup
- a text editor
- a developer account on https://snapcraft.io


Setup
-----

Enable the virtual environment and then install Craft Store by running::

$ pip install craft-store click

Code
----

Write following into a a text editor and save it as ``snap_store_login_ubuntu_one.py``:

.. code-block:: python
import click
from craft_store import *
c = UbuntuOneStoreClient(
base_url="https://dashboard.snapcraft.io",
auth_url="https://login.ubuntu.com",
endpoints=endpoints.U1_SNAP_STORE,
application_name="ubuntu1-dashboard",
user_agent="test",
)
email = click.prompt("Email")
password = click.prompt("Password", hide_input=True)
try:
c.login(
permissions=[
"package_access",
"package_manage",
"package_metrics",
"package_push",
"package_register",
"package_release",
"package_update",
],
description="foo",
ttl=1800,
email=email,
password=password,
)
except errors.StoreServerError as server_error:
if "twofactor-required" in server_error.error_list:
otp = click.prompt("OTP")
c.login(
permissions=[
"package_access",
"package_manage",
"package_metrics",
"package_push",
"package_register",
"package_release",
"package_update",
],
description="foo",
ttl=1800,
email=email,
password=password,
otp=otp,
)
Run
---

Run the saved python module to login::

$ python snap_store_login_ubuntu_one.py


Get Account email and id from the Snap Store
============================================

Expand Down

0 comments on commit cd55cc1

Please sign in to comment.