Skip to content

Creating and Logging In as a New User

Open Library normally authenticates through Internet Archive accounts, which isn't available on localhost. To reproduce bugs requiring authentication, you can create users directly through Infogami using the Python shell in your web container.

Step 1: Initialize Infogami

Access the Python REPL within the web container:

bash
docker compose exec web python

Load the Infogami configuration and initialize:

python
import web
import infogami
from openlibrary.config import load_config
load_config('conf/openlibrary.yml') # for local dev
# load_config('/olsystem/etc/openlibrary.yml') # for prod
infogami._setup()
from infogami import config
from infogami.infobase import server

# Verify setup - should return a Site object:
web.ctx.site
# Output: <infogami.infobase.client.Site object at 0x7506c00c84d0>

Step 2: Create and Activate the Account

Register a new user through the Infogami site connection, then activate it. Note the email address—you'll use it to log in:

python
# Set your username (modify this as needed):
username = 'test_username'

# Register the user:
web.ctx.site.register(username, 'test_displayname', 'test@example.com', 'test_password')
# Output:
# 0.0 (5): SELECT * FROM store WHERE key='account/test_username'
# 0.03 (2): 200 POST /openlibrary.org/account/register {'username': 'test_username', 'displayname': 'test_displayname', 'email': 'test@example.com', 'password': 'test_password'}
# <Storage {'activation_code': None, 'email': 'test@example.com'}>

# Activate the account on the server:
site = server.get_site('openlibrary.org')
site.account_manager.activate(username)

Step 3: Add Users to User Groups (Optional)

Depending on the behavior you are testing locally, you may need to assign users to specific user groups. For example, to test the merge request process with a librarian account, you must add your test user to the librarians user group.

By default, new users created through this process have basic permissions only and cannot access librarian tools.

View Available User Groups

With your local development instance running, navigate to http://localhost:8080/usergroup to see all available user groups.

Screenshot of the open library usergroup page

Add a User to a User Group

  1. Open the user group page (e.g., http://localhost:8080/usergroup/librarians)
  2. Click edit to access the edit form
  3. In the members section, enter /people/ followed by the username (e.g., /people/test_username)
  4. Save your changes

Screenshot of the edit page for the librarians usergroup page

Verify Membership

Log in as the user to confirm that the appropriate user group pages and tools are now accessible. You can also verify membership by checking the user group page to see if the user appears in the member list.

Screenshot of the librarians usergroup page with the newly added test user in the list of members

Step 4: Log In as the User

If logged in as an admin, you can log in as the new user without modifying code:

  1. Navigate to the admin page: http://localhost:8080/admin/people/test_username (replace test_username if needed)
  2. Click "Login as this user"

This automatically logs you in as that user.

Step 5 (Optional): Configure Authentication

If you can't use the admin login method, modify the code directly.

In openlibrary/plugins/upstream/account.py, locate the xauth class and find the result dictionary. Set result['itemname'] to your username:

python
result = {
    "success": True,
    "values": {
        "locked": False,
        "email": "openlibrary@example.org",
        "itemname": "@openlibrary",  # Change to your username (e.g., "test_username")
        "screenname": "openlibrary",
        "verified": True,
    },
}

After making this change, you can log in using the email address you provided during registration. To restore admin access, change result['itemname'] back to @openlibrary.