Skip to content

Commit 351e3b8

Browse files
committed
Add access token based auth method
1 parent 09b408a commit 351e3b8

File tree

3 files changed

+41
-14
lines changed

3 files changed

+41
-14
lines changed

README.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@ Search Confluence from Alfred and open results in your browser.
55
- Search Confluence from Alfred and open results in your browser
66
- Copy Confluence page URL to clipboard (⌘ + C on an Alfred result)
77
- Works on M1 and Intel Macs
8+
- Authenticate with your Confluence account via Access Token or Username/Password
9+
10+
## Usage
11+
1. Download the latest version of the workflow [here](https://github.com/jovobe/alfred-confluence-workflow/releases)
12+
2. Open the workflow in Alfred
13+
3. Adjust the environment variables accordingly
14+
4. Type `c <search term>` in Alfred to search Confluence
15+
16+
### Environment variables
17+
- `BASE_URL`: Confluence base URL without trailing slash e.g. https://confluence.example.com
18+
- `ACCESS_TOKEN`: Confluence access token
19+
- `USERNAME`: Confluence username
20+
- `PASSWORD`: Confluence password
21+
22+
### Authentication
23+
You can use either an access token or a username/password combination. You can obtain an access token by following the instructions [here](https://confluence.atlassian.com/enterprise/using-personal-access-tokens-1026032365.html). If you use an access token, you can omit the username and password. If you use a username/password combination, you can omit the access token. If you provide both, the access token will be used.
824

925
## Development
1026
The current development setup assumes that it is built on a Mac with M1.
@@ -18,10 +34,16 @@ The current development setup assumes that it is built on a Mac with M1.
1834
- [x] publish
1935
- [x] create release in github
2036
- [x] build for intel chip (universal release?)
21-
- [ ] compare to python workflow
22-
- [ ] use token based auth
37+
- [x] compare to python workflow
38+
- [x] use token based auth
2339
- [x] utf-8 chars not searchable (e.g. "führung")
24-
- [ ] add getting started section to readme
40+
- [x] add getting started section to readme
41+
42+
## Contributing
43+
Contributions are welcome! Please fork the repository and submit a pull request with your changes or open an issue with your suggestions.
44+
45+
## Credits
46+
This project is heavily inspired by [alfred-confluence](https://github.com/skleinei/alfred-confluence) which is a Python based workflow for searching Confluence. The mentioned project is not working anymore due to the removal of Python 2 support in macOS 12.3.
2547

2648
---
2749

src/main.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,29 @@ use serde_variant::to_variant_name;
66
use std::env;
77

88
fn main() -> Result<()> {
9-
let username = env::var("USERNAME").context("Confluence username not found!")?;
10-
let password = env::var("PASSWORD").context("Confluence password not found!")?;
9+
let access_token = env::var("ACCESS_TOKEN").context("Confluence access token not found!");
10+
let username = env::var("USERNAME").context("Confluence username not found!");
11+
let password = env::var("PASSWORD").context("Confluence password not found!");
1112
let base_url = env::var("BASE_URL").context("Confluence base url not found!")?;
1213

1314
let args: Vec<String> = env::args().collect();
1415
let query = &args[1].nfc().collect::<String>();
1516
let request_url = format!("{base_url}/rest/quicknav/1/search", base_url = base_url);
1617

1718
let client = Client::new();
18-
let request = client
19-
.get(request_url)
20-
.query(&[("query", query)])
21-
.basic_auth(username, Some(password));
19+
let mut request = client.get(request_url).query(&[("query", query)]);
20+
if access_token.is_ok() {
21+
request = request.bearer_auth(access_token.unwrap());
22+
} else if username.is_ok() && password.is_ok() {
23+
request = request.basic_auth(username.unwrap(), Some(password.unwrap()));
24+
} else {
25+
panic!("No authentication method found!");
26+
}
2227
let response = request.send()?;
23-
2428
let result: ApiResponse = response.json()?;
2529

2630
let result_list = AlfredResultList::from(result, &base_url);
27-
if cfg!(debug_assertions) {
28-
println!("{:#?}", result_list);
29-
}
31+
3032
let out = serde_json::to_string(&result_list).unwrap();
3133
println!("{}", out);
3234

workflow/info.plist

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ The Alfred Confluence workflow makes the Confluence search available in the Alfr
124124
</dict>
125125
<key>variables</key>
126126
<dict>
127+
<key>ACCESS_TOKEN</key>
128+
<string></string>
127129
<key>BASE_URL</key>
128130
<string>Base URL with protocol and without trailing slash. e.g. https://confluence.atlassian.com</string>
129131
<key>PASSWORD</key>
@@ -133,8 +135,9 @@ The Alfred Confluence workflow makes the Confluence search available in the Alfr
133135
</dict>
134136
<key>variablesdontexport</key>
135137
<array>
136-
<string>BASE_URL</string>
137138
<string>PASSWORD</string>
139+
<string>BASE_URL</string>
140+
<string>ACCESS_TOKEN</string>
138141
<string>USERNAME</string>
139142
</array>
140143
<key>version</key>

0 commit comments

Comments
 (0)