Skip to content

Commit 717ef51

Browse files
committed
Contributing: clarify and simplify test credential instructions
1 parent 3d7a326 commit 717ef51

3 files changed

Lines changed: 40 additions & 55 deletions

File tree

CONTRIBUTING.md

Lines changed: 25 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -23,61 +23,43 @@ sure to read and agree with the license.
2323

2424
## Setting up Test Credentials
2525

26-
The tests require two credentials to run:
26+
The tests require at least two credentials to run:
2727

28-
- `TEST_CLIENT_ID`: Your Trakt API client ID
29-
- `TEST_ACCESS_TOKEN`: Your Trakt API access token
28+
- `TEST_CLIENT_ID`: A Trakt API client ID
29+
- `TEST_ACCESS_TOKEN`: A Trakt API access token
3030

31-
### Option 1: Environment Variables (Recommended for CI/CD)
31+
They can be set either
3232

33-
Set environment variables in your shell:
33+
- in a `secrets.properties` file (a template is available in [secrets.properties.template](secrets.properties.template))
34+
- or as environment variables.
3435

35-
**Windows (PowerShell):**
36-
37-
```powershell
38-
$env:TEST_CLIENT_ID="your_client_id_here"
39-
$env:TEST_ACCESS_TOKEN="your_access_token_here"
40-
```
41-
42-
**Linux/Mac:**
43-
44-
```bash
45-
export TEST_CLIENT_ID="your_client_id_here"
46-
export TEST_ACCESS_TOKEN="your_access_token_here"
47-
```
48-
49-
### Option 2: secrets.properties File (Recommended for Local Development)
50-
51-
1. Copy the sample file:
52-
53-
```
54-
cp secrets.properties.sample secrets.properties
55-
```
56-
57-
2. Edit `secrets.properties` and add your credentials:
36+
If both are set, environment variables take precedence over the properties file.
5837

59-
```properties
60-
TEST_CLIENT_ID=your_client_id_here
61-
TEST_ACCESS_TOKEN=your_access_token_here
62-
```
38+
### Getting Credentials
6339

64-
3. The `secrets.properties` file is automatically ignored by git and will not be committed.
40+
To obtain Trakt API credentials:
6541

66-
### Priority
42+
1. Create a Trakt account at https://trakt.tv (⚠️ Tests do modify data of the Trakt account, don't use your personal account!)
43+
2. Register an application at https://trakt.tv/oauth/applications
44+
3. Copy the Client ID and set it as `TEST_CLIENT_ID`
45+
4. Copy the Client Secret and set it as `TEST_CLIENT_SECRET`
46+
5. Add `http://localhost` to the Redirect URIs
47+
6. Click the "Authorize" button next to the localhost redirect URI and authorize access (alternatively, run `test_getAuthorizationRequest()` in [AuthTest][] and visit the URL it prints)
48+
7. Extract the value of `code` from the redirect URI and set it as `TEST_AUTH_CODE`
49+
8. Run `test_getAccessToken()` in [AuthTest][]
50+
9. Copy the printed access and refresh token and set them as `TEST_ACCESS_TOKEN` and `TEST_REFRESH_TOKEN`
6751

68-
If both are set, environment variables take precedence over the properties file.
52+
### Refreshing the Access Token
6953

70-
### Getting Credentials
54+
If `TEST_ACCESS_TOKEN` is expired, but `TEST_REFRESH_TOKEN` isn't:
7155

72-
To obtain your Trakt API credentials:
56+
1. Run `test_refreshAccessToken()` in [AuthTest][]
57+
2. Copy the printed access and refresh token and set them as `TEST_ACCESS_TOKEN` and `TEST_REFRESH_TOKEN`
7358

74-
1. Create a Trakt account at https://trakt.tv
75-
2. Register your application at https://trakt.tv/oauth/applications
76-
3. Use the provided Client ID and generate an access token.
77-
For example, add the `http://localhost` URI and use the "Authorize" button on the Trakt API apps website.
78-
Then use the `code` in the redirect URL to obtain an access token using `AuthTest.test_getAccessToken` (set client
79-
secret and code first).
59+
Otherwise, repeat steps 6 and following from above.
8060

8161
## No code!
8262

8363
You can [discuss or submit bug reports](https://github.com/UweTrottmann/trakt-java/issues)!
64+
65+
[AuthTest]: src/test/java/com/uwetrottmann/trakt5/AuthTest.java

secrets.properties.sample

Lines changed: 0 additions & 12 deletions
This file was deleted.

secrets.properties.template

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Test credentials for trakt-java
2+
# See CONTRIBUTING.md on how to set up.
3+
# Environment variables of the same name take precedence over this file.
4+
5+
TEST_CLIENT_ID=your_client_id_here
6+
7+
# To obtain an access token using AuthTest
8+
TEST_CLIENT_SECRET=your_client_secret_here
9+
TEST_AUTH_CODE=your_auth_code_here
10+
11+
TEST_ACCESS_TOKEN=your_access_token_here
12+
TEST_REFRESH_TOKEN=your_refresh_token_here
13+
14+
# Optional: To obtain an access token using DeviceAuthTest
15+
# TEST_DEVICE_CODE=your_device_code_here

0 commit comments

Comments
 (0)