Skip to content

Commit a09db20

Browse files
Merge branch 'release/0.8.0'
2 parents 5478bd1 + d221365 commit a09db20

File tree

13 files changed

+481
-241
lines changed

13 files changed

+481
-241
lines changed

.github/dependabot.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "maven"
4+
directory: "/"
5+
schedule:
6+
interval: "monthly"
7+
day: "monday"
8+
time: "06:00"
9+
timezone: "UTC"
10+
groups:
11+
maven-dependencies:
12+
patterns:
13+
- "*"
14+
15+
- package-ecosystem: "github-actions"
16+
directory: "/" # even for `.github/workflows`
17+
schedule:
18+
interval: "monthly"
19+
groups:
20+
github-actions:
21+
patterns:
22+
- "*"

.github/release.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# .github/release.yml
2+
# see https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes#configuring-automatically-generated-release-notes
3+
4+
changelog:
5+
exclude:
6+
authors:
7+
- cryptobot
8+
- dependabot
9+
- github-actions
10+
categories:
11+
- title: What's New 🎉
12+
labels:
13+
- enhancement
14+
- title: Bugfixes 🐛
15+
labels:
16+
- bug
17+
- title: Other Changes 📎
18+
labels:
19+
- "*"
20+
exclude:
21+
labels:
22+
- bug
23+
- enhancement

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ jobs:
77
runs-on: ubuntu-latest
88
if: "!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]')"
99
steps:
10-
- uses: actions/checkout@v3
10+
- uses: actions/checkout@v4
1111
with:
1212
fetch-depth: 0
1313
- uses: actions/setup-java@v3
1414
with:
15-
java-version: 11
15+
java-version: 21
1616
distribution: temurin
1717
cache: 'maven'
1818
gpg-private-key: ${{ secrets.RELEASES_GPG_PRIVATE_KEY }}
@@ -44,7 +44,7 @@ jobs:
4444
- uses: actions/setup-java@v3
4545
if: startsWith(github.ref, 'refs/tags/')
4646
with:
47-
java-version: 11
47+
java-version: 21
4848
distribution: temurin
4949
cache: 'maven'
5050
server-id: ossrh

README.md

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,60 @@ support for [PKCE](https://datatracker.ietf.org/doc/html/rfc8252#section-8.1) an
1717

1818
## Usage
1919

20-
Configure your authorization server to allow `http://127.0.0.1/*` as a redirect target and look up these configuration values:
20+
This library requires an instance of [`java.net.http.HttpClient`](https://docs.oracle.com/en/java/javase/21/docs/api/java.net.http/java/net/http/HttpClient.html).
2121

22-
* client identifier
23-
* token endpoint
24-
* authorization endpoint
22+
```java
23+
// usually the default is sufficent:
24+
var httpClient = HttpClient.newHttpClient();
25+
26+
// but feel free to adjust it to your needs, e.g. by applying custom proxy settings:
27+
var httpClient = HttpClient.newBuilder()
28+
.proxy(ProxySelector.of(InetSocketAddress.createUnresolved("https:\\example.com",1337)))
29+
.build();
30+
```
31+
32+
Now to begin, start building an OAuth 2.0 Client via the fluent API:
2533

2634
```java
27-
// this library will just perform the Authorization Flow:
28-
var httpResponse = TinyOAuth2.client("oauth-client-id")
29-
.withTokenEndpoint(URI.create("https://login.example.com/oauth2/token"))
30-
.withRequestTimeout(Duration.ofSeconds(10)) // optional
31-
.authFlow(URI.create("https://login.example.com/oauth2/authorize"))
32-
.authorize(uri -> System.out.println("Please login on " + uri));
35+
var oauthClient = TinyOAuth2.client("oauth-client-id") // The client identifier
36+
.withTokenEndpoint(URI.create("https://login.example.com/oauth2/token")) // The token endpoint
37+
.withRequestTimeout(Duration.ofSeconds(10)) // optional
38+
// ...
39+
```
3340

34-
// from this point onwards, please proceed with the JSON/JWT parser of your choice:
35-
if (httpResponse.statusCode() == 200) {
36-
var jsonString = httpResponse.body()
37-
var bearerToken = parseJson(jsonString).get("access_token");
38-
// ...
39-
}
41+
Next, continue with a specific grant type by invoking `.authorizationCodeGrant(...)` or `.clientCredentialsGrant(...)` (more may be added eventually).
42+
43+
### Authorization Code Grant
44+
Usually, you would want to use the [Authorization Code Grant](https://datatracker.ietf.org/doc/html/rfc6749#section-4.1) type to obtain access tokens.
45+
Configure your Authorization Server to allow `http://127.0.0.1/*` as a redirect target and look up the authorization endpoint:
46+
47+
```java
48+
// this library will just perform the Authorization Flow:
49+
var httpResponse = oauthClient.authorizationCodeGrant(URI.create("https://login.example.com/oauth2/authorize"))
50+
.authorize(httpClient, uri -> System.out.println("Please login on " + uri), "openid", "profile"); // optionally add scopes here);
4051
```
4152

42-
If you wish to use a proxy or your own set of root certificates, provide your own JDK [http client](https://docs.oracle.com/en/java/javase/11/docs/api/java.net.http/java/net/http/HttpClient.html):
53+
If your authorization server doesn't allow wildcards, you can also configure a fixed path (and even port) via e.g. `setRedirectPath("/callback")` and `setRedirectPorts(8080)` before calling `authorize(...)`.
54+
55+
### Client Credentials Grant
56+
Alternatively, if your client shall act on behalf of a service account, use the [Client Credentials Grant](https://datatracker.ietf.org/doc/html/rfc6749#section-4.4) type,
57+
which allows the client to authenticate directly without further user interaction:
58+
4359
```java
44-
var httpClient = HttpClient.newBuilder()
45-
.proxy(ProxySelector.of(InetSocketAddress.createUnresolved("https:\\example.com",1337)))
46-
.build();
47-
var httpResponse = TinyOAuth2.client("oauth-client-id")
48-
.withTokenEndpoint(URI.create("https://login.example.com/oauth2/token"))
49-
.authFlow(URI.create("https://login.example.com/oauth2/authorize"))
50-
.authorize(httpClient, uri -> System.out.println("Please login on " + uri));
60+
var httpResponse = oauthClient.clientCredentialsGrant(UTF_8, "client secret")
61+
.authorize(httpClient, "openid", "profile"); // optionally add scopes here
5162
```
5263

53-
If your authorization server doesn't allow wildcards, you can also configure a fixed path (and even port) via e.g. `setRedirectPath("/callback")` and `setRedirectPorts(8080)`.
64+
### Parsing the Response
65+
For maximum flexibility and minimal attack surface, this library does not include or depend on a specific parser. Instead, use a JSON or JWT parser of your choice to parse the Authorization Server's response:
66+
67+
```java
68+
if (httpResponse.statusCode() == 200) {
69+
var jsonString = httpResponse.body()
70+
var bearerToken = parseJson(jsonString).get("access_token");
71+
// ...
72+
}
73+
```
5474

5575
## Why this library?
5676

pom.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>io.github.coffeelibs</groupId>
77
<artifactId>tiny-oauth2-client</artifactId>
8-
<version>0.7.0</version>
8+
<version>0.8.0</version>
99
<name>Tiny OAuth2 Client</name>
1010
<description>Zero Dependency RFC 8252 Authorization Flow</description>
1111
<inceptionYear>2022</inceptionYear>
@@ -41,7 +41,7 @@
4141
<dependency>
4242
<groupId>org.jetbrains</groupId>
4343
<artifactId>annotations</artifactId>
44-
<version>23.0.0</version>
44+
<version>24.0.1</version>
4545
<scope>provided</scope>
4646
</dependency>
4747

@@ -54,7 +54,7 @@
5454
<dependency>
5555
<groupId>org.mockito</groupId>
5656
<artifactId>mockito-core</artifactId>
57-
<version>5.5.0</version>
57+
<version>5.6.0</version>
5858
<scope>test</scope>
5959
</dependency>
6060
</dependencies>
@@ -72,7 +72,7 @@
7272
<plugin>
7373
<groupId>org.apache.maven.plugins</groupId>
7474
<artifactId>maven-surefire-plugin</artifactId>
75-
<version>3.1.2</version>
75+
<version>3.2.1</version>
7676
</plugin>
7777
<plugin>
7878
<groupId>org.apache.maven.plugins</groupId>
@@ -111,7 +111,7 @@
111111
<plugin>
112112
<groupId>org.jacoco</groupId>
113113
<artifactId>jacoco-maven-plugin</artifactId>
114-
<version>0.8.8</version>
114+
<version>0.8.11</version>
115115
<executions>
116116
<execution>
117117
<id>prepare-agent</id>
@@ -137,7 +137,7 @@
137137
<plugins>
138138
<plugin>
139139
<artifactId>maven-gpg-plugin</artifactId>
140-
<version>3.0.1</version>
140+
<version>3.1.0</version>
141141
<executions>
142142
<execution>
143143
<id>sign-artifacts</id>
@@ -172,7 +172,7 @@
172172
<plugin>
173173
<groupId>org.sonatype.plugins</groupId>
174174
<artifactId>nexus-staging-maven-plugin</artifactId>
175-
<version>1.6.8</version>
175+
<version>1.6.13</version>
176176
<extensions>true</extensions>
177177
<configuration>
178178
<serverId>ossrh</serverId>

0 commit comments

Comments
 (0)