OXYGENHUB
# db00632a61d6 oxygenhub-android / app / src / main / java / io / oxygenhub / android / auth / Session.kt
1.1 KiB · last changed The hub's API and device sign-in, the token in the Keystore (refs #2) 11 days ago source blame history raw
1
package io.oxygenhub.android.auth
2
3
/** A signed-in hub: its address, the account, and the device token. */
4
data class Session(
5
    /** `https://oxygenhub.io`, no trailing slash. */
6
    val hub: String,
7
    val username: String,
8
    val token: String,
9
    /** The scopes the user allowed when approving the device. */
10
    val scopes: List<String> = emptyList(),
11
) {
12
    // The token never reaches a log through toString.
13
    override fun toString(): String = "Session(hub=$hub, username=$username, scopes=$scopes, token=<redacted>)"
14
}
15
16
/** Where the session is kept between launches. */
17
interface SessionStore {
18
    fun load(): Session?
19
    fun save(session: Session)
20
    fun clear()
21
22
    /** The hub last signed in to (or typed), so the sign-in screen offers it again. */
23
    var lastHub: String?
24
}
25
26
/** A store in memory, for tests and previews. */
27
class MemorySessionStore(private var session: Session? = null, override var lastHub: String? = null) : SessionStore {
28
    override fun load(): Session? = session
29
    override fun save(session: Session) {
30
        this.session = session
31
    }
32
33
    override fun clear() {
34
        session = null
35
    }
36
}