@@ -4,7 +4,17 @@ The goal of this project is to provide a simple OAuth2 library which can be impl
44
55Configuring the oauth2 server for any framework should be simple and understandable.
66It encourages to adapt to existing implementations instead the other way around.
7- # Maven
7+
8+ # Frameworks
9+ ## Setup
10+ ### Maven
11+ First define the version to be used and set it as a property
12+ ``` xml
13+ <properties >
14+ <myndocs .oauth.version>0.2.1</myndocs .oauth.version>
15+ </properties >
16+ ```
17+
818Include the following repository in order to download the artifacts
919``` xml
1020<repositories >
@@ -15,40 +25,39 @@ Include the following repository in order to download the artifacts
1525</repositories >
1626```
1727
18- Setting the version in properties
19- ``` xml
20- <properties >
21- <myndocs .oauth.version>0.2.0</myndocs .oauth.version>
22- </properties >
23- ```
24- # Frameworks
25- ## Ktor
26- Include the following dependencies
27-
28+ For the frameworks examples we need at least the following dependencies:
2829``` xml
2930<dependency >
3031 <groupId >nl.myndocs</groupId >
3132 <artifactId >oauth2-server-core</artifactId >
3233 <version >${myndocs.oauth.version}</version >
3334</dependency >
35+
36+ <!-- In memory dependencies -->
3437<dependency >
3538 <groupId >nl.myndocs</groupId >
36- <artifactId >oauth2-server-ktor </artifactId >
39+ <artifactId >oauth2-server-client-inmemory </artifactId >
3740 <version >${myndocs.oauth.version}</version >
3841</dependency >
3942<dependency >
4043 <groupId >nl.myndocs</groupId >
41- <artifactId >oauth2-server-client -inmemory</artifactId >
44+ <artifactId >oauth2-server-identity -inmemory</artifactId >
4245 <version >${myndocs.oauth.version}</version >
4346</dependency >
4447<dependency >
4548 <groupId >nl.myndocs</groupId >
46- <artifactId >oauth2-server-identity -inmemory</artifactId >
49+ <artifactId >oauth2-server-token-store -inmemory</artifactId >
4750 <version >${myndocs.oauth.version}</version >
4851</dependency >
52+ ```
53+
54+ ## Ktor
55+ The following dependency is required along with the dependencies described in Setup
56+
57+ ``` xml
4958<dependency >
5059 <groupId >nl.myndocs</groupId >
51- <artifactId >oauth2-server-token-store-inmemory </artifactId >
60+ <artifactId >oauth2-server-ktor </artifactId >
5261 <version >${myndocs.oauth.version}</version >
5362</dependency >
5463```
@@ -83,33 +92,13 @@ embeddedServer(Netty, 8080) {
8392```
8493
8594## Javalin
86- Include the following dependencies
95+ The following dependency is required along with the dependencies described in Setup
8796``` xml
88- <dependency >
89- <groupId >nl.myndocs</groupId >
90- <artifactId >oauth2-server-core</artifactId >
91- <version >${myndocs.oauth.version}</version >
92- </dependency >
93- <dependency >
94- <groupId >nl.myndocs</groupId >
95- <artifactId >oauth2-server-client-inmemory</artifactId >
96- <version >${myndocs.oauth.version}</version >
97- </dependency >
9897<dependency >
9998 <groupId >nl.myndocs</groupId >
10099 <artifactId >oauth2-server-javalin</artifactId >
101100 <version >${myndocs.oauth.version}</version >
102101</dependency >
103- <dependency >
104- <groupId >nl.myndocs</groupId >
105- <artifactId >oauth2-server-identity-inmemory</artifactId >
106- <version >${myndocs.oauth.version}</version >
107- </dependency >
108- <dependency >
109- <groupId >nl.myndocs</groupId >
110- <artifactId >oauth2-server-token-store-inmemory</artifactId >
111- <version >${myndocs.oauth.version}</version >
112- </dependency >
113102```
114103
115104In memory example for Javalin:
@@ -143,33 +132,13 @@ Javalin.create().apply {
143132```
144133
145134## Spark java
146- Include the following dependencies
135+ The following dependency is required along with the dependencies described in Setup
147136``` xml
148- <dependency >
149- <groupId >nl.myndocs</groupId >
150- <artifactId >oauth2-server-core</artifactId >
151- <version >${myndocs.oauth.version}</version >
152- </dependency >
153- <dependency >
154- <groupId >nl.myndocs</groupId >
155- <artifactId >oauth2-server-client-inmemory</artifactId >
156- <version >${myndocs.oauth.version}</version >
157- </dependency >
158137<dependency >
159138 <groupId >nl.myndocs</groupId >
160139 <artifactId >oauth2-server-sparkjava</artifactId >
161140 <version >${myndocs.oauth.version}</version >
162141</dependency >
163- <dependency >
164- <groupId >nl.myndocs</groupId >
165- <artifactId >oauth2-server-identity-inmemory</artifactId >
166- <version >${myndocs.oauth.version}</version >
167- </dependency >
168- <dependency >
169- <groupId >nl.myndocs</groupId >
170- <artifactId >oauth2-server-token-store-inmemory</artifactId >
171- <version >${myndocs.oauth.version}</version >
172- </dependency >
173142```
174143
175144In memory example for Spark java:
@@ -198,7 +167,48 @@ Oauth2Server.configureOauth2Server {
198167 }
199168}
200169```
170+ ## http4k
171+ The following dependency is required along with the dependencies described in Setup
172+ ``` xml
173+ <dependency >
174+ <groupId >nl.myndocs</groupId >
175+ <artifactId >oauth2-server-http4k</artifactId >
176+ <version >${myndocs.oauth.version}</version >
177+ </dependency >
178+ ```
179+
180+ In memory example for http4k:
181+ ``` kotlin
182+ val app: HttpHandler = routes(
183+ " /ping" bind GET to { _: Request -> Response (Status .OK ).body(" pong!" ) }
184+ ) `enable oauth2` {
185+ tokenService = Oauth2TokenServiceBuilder .build {
186+ identityService = InMemoryIdentity ()
187+ .identity {
188+ username = " foo"
189+ password = " bar"
190+ }
191+ clientService = InMemoryClient ()
192+ .client {
193+ clientId = " testapp"
194+ clientSecret = " testpass"
195+ scopes = setOf (" trusted" )
196+ redirectUris = setOf (" http://localhost:8080/callback" )
197+ authorizedGrantTypes = setOf (
198+ AuthorizedGrantType .AUTHORIZATION_CODE ,
199+ AuthorizedGrantType .PASSWORD ,
200+ AuthorizedGrantType .IMPLICIT ,
201+ AuthorizedGrantType .REFRESH_TOKEN
202+ )
203+ }
204+ tokenStore = InMemoryTokenStore ()
205+ }
206+ }
207+
208+ app.asServer(Jetty (9000 )).start()
209+ ```
201210
211+ ** Note:** ` /ping ` is only added for demonstration for own defined routes.
202212# Custom implementation
203213## Identity service
204214Users can be authenticate through the identity service. In OAuth2 terms this would be the resource owner.
@@ -247,4 +257,4 @@ fun revokeRefreshToken(token: String)
247257
248258```
249259
250- When ` AccessToken ` is passed to ` storeAccessToken ` and it contains a ` RefreshToken ` , then ` storeAccessToken ` is also responsible for saving the refresh token.
260+ When ` AccessToken ` is passed to ` storeAccessToken ` and it contains a ` RefreshToken ` , then ` storeAccessToken ` is also responsible for saving the refresh token.
0 commit comments