Skip to content

Commit 4562e72

Browse files
committed
Update documentation
1 parent 43ae377 commit 4562e72

File tree

1 file changed

+97
-24
lines changed

1 file changed

+97
-24
lines changed

README.md

Lines changed: 97 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,30 +51,33 @@ Include the following dependencies
5151
<artifactId>oauth2-server-token-store-inmemory</artifactId>
5252
<version>${myndocs.oauth.version}</version>
5353
</dependency>
54-
<dependency>
55-
<groupId>com.google.code.gson</groupId>
56-
<artifactId>gson</artifactId>
57-
<version>2.8.5</version>
58-
</dependency>
5954
```
6055

6156
In memory example for Ktor:
6257
```kotlin
6358
embeddedServer(Netty, 8080) {
6459
install(Oauth2ServerFeature) {
65-
identityService = InMemoryIdentity()
66-
.identity {
67-
username = "foo"
68-
password = "bar"
69-
}
70-
clientService = InMemoryClient()
71-
.client {
72-
clientId = "testapp"
73-
clientSecret = "testpass"
74-
scopes = setOf("trusted")
75-
redirectUris = setOf("https://localhost:8080/callback")
76-
}
77-
tokenStore = InMemoryTokenStore()
60+
tokenService = Oauth2TokenServiceBuilder.build {
61+
identityService = InMemoryIdentity()
62+
.identity {
63+
username = "foo"
64+
password = "bar"
65+
}
66+
clientService = InMemoryClient()
67+
.client {
68+
clientId = "testapp"
69+
clientSecret = "testpass"
70+
scopes = setOf("trusted")
71+
redirectUris = setOf("https://localhost:8080/callback")
72+
authorizedGrantTypes = setOf(
73+
AuthorizedGrantType.AUTHORIZATION_CODE,
74+
AuthorizedGrantType.PASSWORD,
75+
AuthorizedGrantType.IMPLICIT,
76+
AuthorizedGrantType.REFRESH_TOKEN
77+
)
78+
}
79+
tokenStore = InMemoryTokenStore()
80+
}
7881
}
7982
}.start(wait = true)
8083
```
@@ -113,24 +116,89 @@ In memory example for Javalin:
113116
```kotlin
114117
Javalin.create().apply {
115118
enableOauthServer {
119+
tokenService = Oauth2TokenServiceBuilder.build {
120+
identityService = InMemoryIdentity()
121+
.identity {
122+
username = "foo"
123+
password = "bar"
124+
}
125+
clientService = InMemoryClient()
126+
.client {
127+
clientId = "testapp"
128+
clientSecret = "testpass"
129+
scopes = setOf("trusted")
130+
redirectUris = setOf("https://localhost:7000/callback")
131+
authorizedGrantTypes = setOf(
132+
AuthorizedGrantType.AUTHORIZATION_CODE,
133+
AuthorizedGrantType.PASSWORD,
134+
AuthorizedGrantType.IMPLICIT,
135+
AuthorizedGrantType.REFRESH_TOKEN
136+
)
137+
}
138+
tokenStore = InMemoryTokenStore()
139+
}
140+
141+
}
142+
}.start(7000)
143+
```
144+
145+
## Spark java
146+
Include the following dependencies
147+
```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>
158+
<dependency>
159+
<groupId>nl.myndocs</groupId>
160+
<artifactId>oauth2-server-sparkjava</artifactId>
161+
<version>${myndocs.oauth.version}</version>
162+
</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>
173+
```
174+
175+
In memory example for Spark java:
176+
```kotlin
177+
Oauth2Server.configureOauth2Server {
178+
tokenService = Oauth2TokenServiceBuilder.build {
116179
identityService = InMemoryIdentity()
117180
.identity {
118181
username = "foo"
119182
password = "bar"
120183
}
121-
122184
clientService = InMemoryClient()
123185
.client {
124186
clientId = "testapp"
125187
clientSecret = "testpass"
126-
scopes = setOf("ROLE_CLIENT")
127-
redirectUris = setOf("https://localhost:7000/callback")
188+
scopes = setOf("trusted")
189+
redirectUris = setOf("https://localhost:4567/callback")
190+
authorizedGrantTypes = setOf(
191+
AuthorizedGrantType.AUTHORIZATION_CODE,
192+
AuthorizedGrantType.PASSWORD,
193+
AuthorizedGrantType.IMPLICIT,
194+
AuthorizedGrantType.REFRESH_TOKEN
195+
)
128196
}
129-
130197
tokenStore = InMemoryTokenStore()
131198
}
132-
}.start(7000)
199+
}
133200
```
201+
134202
# Custom implementation
135203
## Identity service
136204
Users can be authenticate through the identity service. In OAuth2 terms this would be the resource owner.
@@ -140,7 +208,7 @@ fun identityOf(forClient: Client, username: String): Identity?
140208

141209
fun validCredentials(forClient: Client, identity: Identity, password: String): Boolean
142210

143-
fun validScopes(forClient: Client, identity: Identity, scopes: Set<String>): Boolean
211+
fun allowedScopes(forClient: Client, identity: Identity, scopes: Set<String>): Set<String>
144212
```
145213

146214
Each of the methods that needs to be implemented contains `Client`. This could give you extra flexibility.
@@ -163,6 +231,8 @@ fun storeAccessToken(accessToken: AccessToken)
163231

164232
fun accessToken(token: String): AccessToken?
165233

234+
fun revokeAccessToken(token: String)
235+
166236
fun storeCodeToken(codeToken: CodeToken)
167237

168238
fun codeToken(token: String): CodeToken?
@@ -172,6 +242,9 @@ fun consumeCodeToken(token: String): CodeToken?
172242
fun storeRefreshToken(refreshToken: RefreshToken)
173243

174244
fun refreshToken(token: String): RefreshToken?
245+
246+
fun revokeRefreshToken(token: String)
247+
175248
```
176249

177250
When `AccessToken` is passed to `storeAccessToken` and it contains a `RefreshToken`, then `storeAccessToken` is also responsible for saving the refresh token.

0 commit comments

Comments
 (0)