Skip to content

Commit dea95bf

Browse files
committed
Add app authentication method and update README with OAuth setup instructions and images.
1 parent 120eafe commit dea95bf

File tree

5 files changed

+29
-16
lines changed

5 files changed

+29
-16
lines changed

README.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,26 @@ Optional environment variables:
3434

3535
### Authentication
3636

37+
You must have a developer account and app to use this tool.
38+
39+
App authentication:
40+
```bash
41+
xurl auth app --bearer-token BEARER_TOKEN
42+
```
43+
3744
OAuth 2.0 authentication:
3845
```bash
3946
xurl auth oauth2
4047
```
4148

49+
**Note:** For OAuth 2.0 authentication, you must specify the redirect URI in the [X API developer portal](https://developer.x.com/en/portal/dashboard).
50+
51+
1. Create an app at the [X API developer portal](https://developer.x.com/en/portal/dashboard).
52+
2. Go to authentication settings and set the redirect URI to `http://localhost:8080/callback`.
53+
![Setup](./assets/setup.png)
54+
![Redirect URI](./assets/callback.png)
55+
3. Set the client ID and secret in your environment variables.
56+
4257
OAuth 1.0a authentication:
4358
```bash
4459
xurl auth oauth1 --consumer-key KEY --consumer-secret SECRET --access-token TOKEN --token-secret SECRET
@@ -54,6 +69,7 @@ Clear authentication:
5469
xurl auth clear --all # Clear all tokens
5570
xurl auth clear --oauth1 # Clear OAuth 1.0a tokens
5671
xurl auth clear --oauth2-username USERNAME # Clear specific OAuth 2.0 token
72+
xurl auth clear --bearer # Clear bearer token
5773
```
5874

5975
### Making Requests
@@ -77,6 +93,7 @@ Specify authentication type:
7793
```bash
7894
xurl --auth oauth2 /2/users/me
7995
xurl --auth oauth1 /2/tweets
96+
xurl --auth app /2/users/me
8097
```
8198

8299
Use specific OAuth 2.0 account:
@@ -88,16 +105,6 @@ xurl --username johndoe /2/users/me
88105

89106
Tokens are stored securely in `~/.xurl` in your home directory.
90107

91-
## Development
92-
93-
The project uses the following structure:
94-
- `src/main.rs`: Entry point and command handling
95-
- `src/auth/`: Authentication implementation
96-
- `src/api/`: API client implementation
97-
- `src/cli/`: Command-line interface definitions
98-
- `src/config/`: Configuration management
99-
- `src/error/`: Error types and handling
100-
101108
## Testing
102109

103110
Run the test suite:
@@ -108,11 +115,5 @@ cargo test
108115
## Contributing
109116
Contributions are welcome!
110117

111-
1. Fork the repository
112-
2. Create your feature branch
113-
3. Commit your changes
114-
4. Push to the branch
115-
5. Create a new Pull Request
116-
117118
## License
118119
This project is open-sourced under the MIT License - see the LICENSE file for details.

assets/callback.png

137 KB
Loading

assets/setup.png

129 KB
Loading

src/auth/token_store.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ impl TokenStore {
163163
self.oauth1_tokens.is_some()
164164
}
165165

166+
pub fn has_bearer_token(&self) -> bool {
167+
self.bearer_token.is_some()
168+
}
169+
166170
fn save_to_file(&self) -> Result<(), TokenStoreError> {
167171
let content =
168172
serde_json::to_string(&self).map_err(|_| TokenStoreError::JSONSerializationError)?;

src/main.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ async fn main() -> Result<(), Error> {
5959
"Not configured"
6060
}
6161
);
62+
println!(
63+
"App Auth: {}",
64+
if store.has_bearer_token() {
65+
"Configured"
66+
} else {
67+
"Not configured"
68+
}
69+
);
6270
}
6371

6472
AuthCommands::Clear {

0 commit comments

Comments
 (0)