Skip to content

Commit 6eb770e

Browse files
committed
Add basic documentation
1 parent 07227f5 commit 6eb770e

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

README.md

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Kotlin OAuth2 server
22
## Goal
3-
The goal of this project is to provide an OAuth2 library which can be implemented in multiple frameworks
3+
The goal of this project is to provide a simple OAuth2 library which can be implemented in any framework
44

55
Configuring the oauth2 server for any framework should be simple and understandable.
6+
It encourages to adapt to existing implementations instead the other way around.
67
## Frameworks
78
### Ktor
89
Basic setup for Ktor:
@@ -13,16 +14,60 @@ embeddedServer(Netty, 8080) {
1314
.identity {
1415
username = "foo"
1516
password = "bar"
16-
scopes = setOf("trusted")
1717
}
1818
clientService = InMemoryClient()
1919
.client {
2020
clientId = "testapp"
2121
clientSecret = "testpass"
2222
scopes = setOf("trusted")
23-
redirectUris = setOf("https://app.localhost/callback")
23+
redirectUris = setOf("https://localhost:8080/callback")
2424
}
2525
tokenStore = InMemoryTokenStore()
2626
}
2727
}.start(wait = true)
28-
```
28+
```
29+
30+
## Custom implementation
31+
### Identity service
32+
Users can be authenticate through the identity service. In OAuth2 terms this would be the resource owner.
33+
34+
```kotlin
35+
fun identityOf(forClient: Client, username: String): Identity?
36+
37+
fun validCredentials(forClient: Client, identity: Identity, password: String): Boolean
38+
39+
fun validScopes(forClient: Client, identity: Identity, scopes: Set<String>): Boolean
40+
```
41+
42+
Each of the methods that needs to be implemented contains `Client`. This could give you extra flexibility.
43+
For example you could have user base per client, instead of have users over all clients.
44+
45+
### Client service
46+
Client service is similar to the identity service.
47+
48+
```kotlin
49+
fun clientOf(clientId: String): Client?
50+
51+
fun validClient(client: Client, clientSecret: String): Boolean
52+
```
53+
54+
### Token store
55+
The following methods have to be implemented for a token store.
56+
57+
```kotlin
58+
fun storeAccessToken(accessToken: AccessToken)
59+
60+
fun accessToken(token: String): AccessToken?
61+
62+
fun storeCodeToken(codeToken: CodeToken)
63+
64+
fun codeToken(token: String): CodeToken?
65+
66+
fun consumeCodeToken(token: String): CodeToken?
67+
68+
fun storeRefreshToken(refreshToken: RefreshToken)
69+
70+
fun refreshToken(token: String): RefreshToken?
71+
```
72+
73+
When `AccessToken` is passed to `storeAccessToken` and it contains a `RefreshToken`, then `storeAccessToken` is also responsible for saving the refresh token.

kotlin-oauth2-server-core/src/main/java/nl/myndocs/oauth2/identity/IdentityService.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ package nl.myndocs.oauth2.identity
33
import nl.myndocs.oauth2.client.Client
44

55
interface IdentityService {
6+
/**
7+
* Find identity within a client and username
8+
* If not found return null
9+
*/
610
fun identityOf(forClient: Client, username: String): Identity?
711

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

0 commit comments

Comments
 (0)