summaryrefslogtreecommitdiff
path: root/ykpsmuttauth/README.md
blob: cff546f680ffe3737f376c853d73fb77211120be (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# ykpsmuttauth

This simple program allows you to obtain an XOAUTH2 token for your YK Pao School Microsoft account. This is useful as a replacement for [`mutt_oauth2.py`](https://raw.githubusercontent.com/muttmua/mutt/master/contrib/mutt_oauth2.py).

There are two implementations. One is a rather complete Go implementation, `ykpsmuttauth`, and one is a not really complete C implementation, `ykpsmuttauth2`.

|Feature|Go|C|
|-------|--|-|
|Authorize an account for the first time|Yes|No|
|Retrieve a new access token from a refresh token|Yes|Yes|
|Print an already-valid access token|Yes|Yes|

The C implementation can read files produced by the Go implementation. It doesn't work the other way around because of some broken timezone handling.

The Go implementation has no dependencies other than the Go standard library. The C implementation depends on a POSIX standard library, and `openssl` for hashing, `libcurl` for HTTP requests, and `json-c` for JSON parsing and writing.

## Usage

For the Go implementation,
```
Usage of ./ykpsmuttauth:
  -authorize string
    	email to newly authorize
  -tokenfile string
    	(required) persistent token storage
```

For the C implementation,
```
Usage: ./ykpsmuttauth2 <tokenfile>
```

## Using with [`aerc`](https://sr.ht/~rjarry/aerc/)

First run the Go implementation with `ykpsmuttauth -tokenfile ~/.cache/aerc/token.txt -authorize s65535@ykpaoschool.cn`.

```ini
[school]
from              = Your Name <s65535@ykpaoschool.cn>
default           = INBOX
copy-to           = Sent Items
source            = imaps+xoauth2://s65535%40ykpaoschool.cn@outlook.office365.com
outgoing          = smtp+xoauth2://s65535%40ykpaoschool.cn@outlook.office365.com:587
# To use the Go implementation:
source-cred-cmd   = ykpsmuttauth -tokenfile ~/.cache/aerc/token.txt
outgoing-cred-cmd = ykpsmuttauth -tokenfile ~/.cache/aerc/token.txt
# Or to use the C implementation:
# source-cred-cmd   = ykpsmuttauth2 ~/.cache/aerc/token.txt
# outgoing-cred-cmd = ykpsmuttauth2 ~/.cache/aerc/token.txt
```