mirror of
https://github.com/nix-community/home-manager.git
synced 2025-12-10 11:01:07 +01:00
aerc-accounts: improve logic for parsing XOAUTH2 URL params (#6530)
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.
This commit is contained in:
parent
74f0a8546e
commit
18e74c2e02
4 changed files with 52 additions and 2 deletions
|
|
@ -134,8 +134,9 @@ in {
|
||||||
|
|
||||||
oauthParams = { auth, params }:
|
oauthParams = { auth, params }:
|
||||||
if useOauth auth && params != null && params != { } then
|
if useOauth auth && params != null && params != { } then
|
||||||
"?" + builtins.concatStringsSep "&" lib.attrsets.mapAttrsToList
|
"?" + builtins.concatStringsSep "&"
|
||||||
(k: v: k + "=" + lib.strings.escapeURL v) params
|
(lib.attrsets.mapAttrsToList (k: v: k + "=" + lib.strings.escapeURL v)
|
||||||
|
(lib.attrsets.filterAttrs (k: v: v != null) params))
|
||||||
else
|
else
|
||||||
"";
|
"";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,4 +2,5 @@
|
||||||
aerc-noSettings = ./noSettings.nix;
|
aerc-noSettings = ./noSettings.nix;
|
||||||
aerc-settings = ./settings.nix;
|
aerc-settings = ./settings.nix;
|
||||||
aerc-assertion = ./assertion.nix;
|
aerc-assertion = ./assertion.nix;
|
||||||
|
aerc-oauth = ./oauth.nix;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
9
tests/modules/programs/aerc/oauth.expected
Normal file
9
tests/modules/programs/aerc/oauth.expected
Normal file
|
|
@ -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
tests/modules/programs/aerc/oauth.nix
Normal file
39
tests/modules/programs/aerc/oauth.nix
Normal file
|
|
@ -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;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue