Skip to content

Commit

Permalink
aerc-accounts: improve logic for parsing XOAUTH2 URL params (#6530)
Browse files Browse the repository at this point in the history
This commit fixes an issue in aerc-accounts that prevents oauth2
accounts from being generated from given parameters. It also allows
users to add XOAUTH2 credentials without having to add all four of
client_id, client_secret, token_endpoint, and scope. It further adds
tests for the XOAUTH2 config generation.
  • Loading branch information
3ulalia authored Feb 26, 2025
1 parent 74f0a85 commit 18e74c2
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
5 changes: 3 additions & 2 deletions modules/programs/aerc-accounts.nix
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ in {

oauthParams = { auth, params }:
if useOauth auth && params != null && params != { } then
"?" + builtins.concatStringsSep "&" lib.attrsets.mapAttrsToList
(k: v: k + "=" + lib.strings.escapeURL v) params
"?" + builtins.concatStringsSep "&"
(lib.attrsets.mapAttrsToList (k: v: k + "=" + lib.strings.escapeURL v)
(lib.attrsets.filterAttrs (k: v: v != null) params))
else
"";

Expand Down
1 change: 1 addition & 0 deletions tests/modules/programs/aerc/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
aerc-noSettings = ./noSettings.nix;
aerc-settings = ./settings.nix;
aerc-assertion = ./assertion.nix;
aerc-oauth = ./oauth.nix;
}
9 changes: 9 additions & 0 deletions tests/modules/programs/aerc/oauth.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Generated by Home Manager.

[basic]
copy-to = Sent
default = Inbox
from = Annie X. Hacker <anniex@mail.invalid>
outgoing = smtp+xoauth2://anniex@smtp.office365.com:587?client_id=9e5f94bc-e8a4-4e73-b8be-63364c29d753&token_endpoint=https%3A%2F%2Flogin.microsoftonline.com%2Fcommon%2Foauth2%2Fv2.0%2Ftoken
postpone = Drafts
source = imaps+xoauth2://anniex@outlook.office365.com:993?client_id=9e5f94bc-e8a4-4e73-b8be-63364c29d753&token_endpoint=https%3A%2F%2Flogin.microsoftonline.com%2Fcommon%2Foauth2%2Fv2.0%2Ftoken
39 changes: 39 additions & 0 deletions tests/modules/programs/aerc/oauth.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{ config, pkgs, ... }: {
config = {
nmt.script = let
dir = if (pkgs.stdenv.isDarwin && !config.xdg.enable) then
"home-files/Library/Preferences/aerc"
else
"home-files/.config/aerc";
in ''
assertFileContent ${dir}/accounts.conf ${./oauth.expected}
'';
programs.aerc = {
enable = true;
extraConfig.general.unsafe-accounts-conf = true;
};

accounts.email.accounts = {
basic = {
realName = "Annie X. Hacker";
userName = "anniex";
address = "anniex@mail.invalid";
primary = true;
flavor = "outlook.office365.com";

aerc = rec {
enable = true;
imapAuth = "xoauth2";
smtpAuth = imapAuth;
imapOauth2Params = {
client_id = "9e5f94bc-e8a4-4e73-b8be-63364c29d753";
token_endpoint =
"https://login.microsoftonline.com/common/oauth2/v2.0/token";
};
smtpOauth2Params = imapOauth2Params;
};
};
};
};
}

0 comments on commit 18e74c2

Please sign in to comment.