Skip to content

Commit 51327f5

Browse files
authored
Release/0.2.0 (#19)
* Fix state not being included * Custom authentication, with basic authentication as default * Split up IdentityService into re-usable parts Redirects authentication can be intercepted based on there context * Open up BasicAuthorizer implementations * Remove context from authorizer methods Bind Authorizer to requests * Abstract layer around requests to make future changes easier (#11) * Abstract layer around requests to make future changes easier * Remove generic from CallContext * Configuration (#12) * Align configuration over modules Make TokenService configurable * Configuration should not be aware of which TokenService is being implemented * Sparkjava implementation (#13) * Scope handling (#14) * Improve validating scopes * Strip kotlin name of modules (#15) * Strip kotlin name of modules * json module (#16) * Authorized grant types (#17) * Update documentation * Revokable tokens (#18) * Release 0.2.0
1 parent 2269148 commit 51327f5

File tree

89 files changed

+1212
-826
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+1212
-826
lines changed

README.md

Lines changed: 108 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Include the following repository in order to download the artifacts
1818
Setting the version in properties
1919
```xml
2020
<properties>
21-
<myndocs.oauth.version>0.1.1</myndocs.oauth.version>
21+
<myndocs.oauth.version>0.2.0</myndocs.oauth.version>
2222
</properties>
2323
```
2424
# Frameworks
@@ -28,53 +28,56 @@ Include the following dependencies
2828
```xml
2929
<dependency>
3030
<groupId>nl.myndocs</groupId>
31-
<artifactId>kotlin-oauth2-server-core</artifactId>
31+
<artifactId>oauth2-server-core</artifactId>
3232
<version>${myndocs.oauth.version}</version>
3333
</dependency>
3434
<dependency>
3535
<groupId>nl.myndocs</groupId>
36-
<artifactId>kotlin-oauth2-server-ktor</artifactId>
36+
<artifactId>oauth2-server-ktor</artifactId>
3737
<version>${myndocs.oauth.version}</version>
3838
</dependency>
3939
<dependency>
4040
<groupId>nl.myndocs</groupId>
41-
<artifactId>kotlin-oauth2-server-client-inmemory</artifactId>
41+
<artifactId>oauth2-server-client-inmemory</artifactId>
4242
<version>${myndocs.oauth.version}</version>
4343
</dependency>
4444
<dependency>
4545
<groupId>nl.myndocs</groupId>
46-
<artifactId>kotlin-oauth2-server-identity-inmemory</artifactId>
46+
<artifactId>oauth2-server-identity-inmemory</artifactId>
4747
<version>${myndocs.oauth.version}</version>
4848
</dependency>
4949
<dependency>
5050
<groupId>nl.myndocs</groupId>
51-
<artifactId>kotlin-oauth2-server-token-store-inmemory</artifactId>
51+
<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
```
@@ -84,27 +87,27 @@ Include the following dependencies
8487
```xml
8588
<dependency>
8689
<groupId>nl.myndocs</groupId>
87-
<artifactId>kotlin-oauth2-server-core</artifactId>
90+
<artifactId>oauth2-server-core</artifactId>
8891
<version>${myndocs.oauth.version}</version>
8992
</dependency>
9093
<dependency>
9194
<groupId>nl.myndocs</groupId>
92-
<artifactId>kotlin-oauth2-server-client-inmemory</artifactId>
95+
<artifactId>oauth2-server-client-inmemory</artifactId>
9396
<version>${myndocs.oauth.version}</version>
9497
</dependency>
9598
<dependency>
9699
<groupId>nl.myndocs</groupId>
97-
<artifactId>kotlin-oauth2-server-javalin</artifactId>
100+
<artifactId>oauth2-server-javalin</artifactId>
98101
<version>${myndocs.oauth.version}</version>
99102
</dependency>
100103
<dependency>
101104
<groupId>nl.myndocs</groupId>
102-
<artifactId>kotlin-oauth2-server-identity-inmemory</artifactId>
105+
<artifactId>oauth2-server-identity-inmemory</artifactId>
103106
<version>${myndocs.oauth.version}</version>
104107
</dependency>
105108
<dependency>
106109
<groupId>nl.myndocs</groupId>
107-
<artifactId>kotlin-oauth2-server-token-store-inmemory</artifactId>
110+
<artifactId>oauth2-server-token-store-inmemory</artifactId>
108111
<version>${myndocs.oauth.version}</version>
109112
</dependency>
110113
```
@@ -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.

kotlin-oauth2-server-javalin/src/main/java/nl/myndocs/oauth2/javalin/Oauth2Server.kt

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

0 commit comments

Comments
 (0)