1 个稳定版本
| 1.0.0 | 2022年2月8日 |
|---|
340 在 电子邮件
16KB
374 代码行
MFAuth
多因素认证CLI
简单的CLI工具,用于请求和管理OAuth2令牌。可用于与mbsync和msmtp一起使用,接收和发送需要OAuth2认证的提供者的邮件。
安装
- 安装Rust,可以使用您的包管理器或使用rustup
- 克隆此仓库并进入
git@github.com:rien/mfauth.git
cd mfauth
- 构建并安装程序
cargo install --path .
- 通过运行
mfauth help来测试它是否工作
如果您看到command not found错误,您可以在您的$HOME/.cargo/bin中尝试添加。
用法
- 运行
mfauth init在$HOME/.config/mfauth/config.toml中创建示例配置文件 - 编辑配置文件(
$EDITOR $HOME/.config/mfauth/config.toml) - 运行
mfauth authorize <账户>以获取有效会话(访问令牌和刷新令牌),这将在此会话中保存到$HOME/.cache/mfauth/cache.toml - 运行
mfauth access <账户>以获取有效的访问令牌,如果需要,将自动刷新令牌 - 配置您的邮件客户端使用
XOAUTH2身份验证,并使用mfauth获取访问令牌
有时如果会话过期,这可能会停止工作。如果发生这种情况,您只需再次运行mfauth authorize <账户>即可。
使用msmtp(发送)的示例
在msmtp配置中使用mfauth的工作账户条目
account microsoft
auth xoauth2
from username@outlook.com
host outlook.office365.com
passwordeval /home/user/.cargo/bin/mfauth access microsoft
port 587
tls on
tls_starttls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
user username@outlook.com
使用mbsync(接收)的示例
重要:isync需要安装cyrus-sasl-xoauth2扩展以支持XOAUTH2身份验证协议。
这是使用mfauth的IMAPAccount块的示例。
IMAPAccount microsoft
AuthMechs XOAUTH2
CertificateFile /etc/ssl/certs/ca-certificates.crt
Host outlook.office365.com
PassCmd "/home/user/.cargo/bin/mfauth access microsoft"
Port 993
SSLType IMAPS
User username@outlook.com
依赖关系
~10-25MB
~345K SLoC