豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Connect now / Custom Protocol URL#720

Open
davinotdavid wants to merge 4 commits intomainfrom
connect-now-custom-protocol-url
Open

Connect now / Custom Protocol URL#720
davinotdavid wants to merge 4 commits intomainfrom
connect-now-custom-protocol-url

Conversation

@davinotdavid
Copy link
Copy Markdown
Contributor

@davinotdavid davinotdavid commented Apr 17, 2026

Description of changes

  • Updated README with the current feature flags (sneaked in some fixes around incorrect instructions for testing)
  • Added a POST desktop-connect/token endpoint that current only returns the user's access token.
  • Changed from link to button for the "Connect now" to make the request and change the window.location with the formatted custom protocol mapping in the format that was suggested by the Desktop team.

Known issues / Things to improve

  • We don't have design input yet on the fallback scenario so that's not implemented in this PR.

Related issues

Fixes #708

Comment on lines +31 to +35
const url =
'net.thunderbird://accounts/new' +
`?name=${encodeURIComponent(userDisplayName)}` +
`&email=${encodeURIComponent(primaryEmail)}` +
`&token=${encodeURIComponent(data.token)}`;
Copy link
Copy Markdown
Contributor Author

@davinotdavid davinotdavid Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the Matrix discussions, would this be ok as a starting point for URL to unblock the Desktop part of the integration development?

cc @darktrojan @freaktechnik

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd prefer something like "net.thunderbird://add-thundermail/?…" so anyone reading the URL can immediately see what's going on. Also that avoids any potential issues if we add other "accounts" actions later on (all things named "accounts" would have to be handled in the same place, which isn't necessarily bad, but might add a few more hoops to jump through).

Note that passing the access token would only give Thunderbird access for that session, and the user would be asked to sign in again next time they started Thunderbird. If it was the refresh token instead, Thunderbird could then request the access token from the server.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me! I've updated the PR with your suggested URL and passing down the refresh token instead.

Comment thread src/thunderbird_accounts/mail/views.py Outdated
Comment on lines +518 to +532
@login_required
@require_http_methods(['POST'])
def generate_desktop_connect_token(request: HttpRequest):
"""Returns the OIDC access token for the Thunderbird Desktop custom
protocol connect flow. The token is fetched on-click rather than
embedded in the page to limit its exposure in the DOM."""

access_token = request.session.get('oidc_access_token')
if not access_token:
return JsonResponse(
{'success': False, 'error': str(_('Authentication token not available. Please try logging in again.'))},
status=401,
)

return JsonResponse({'success': True, 'token': access_token})
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During today's Accounts/Mail meeting, it was suggested that the initial attempt to make the integration work was to pass in the access token as is for simplicity. In the future, we could generate a single use token of sorts encrypted using a secret that only TB Desktop and Accounts have.

I've made this as a dedicated endpoint since it leaving the access token in the window._page global wasn't a great idea.

Comment thread README.md

```shell
docker compose exec backend uv run manage.py test thunderbird_accounts.client.tests
docker compose exec accounts uv run manage.py test thunderbird_accounts.mail.tests
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed from client to mail since we don't have a module for client anymore

@davinotdavid davinotdavid requested a review from darktrojan April 17, 2026 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hide "Connect now" button through a local storage flag

2 participants