-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support username and password arguments in kotlin-cli sample (#350)
- Loading branch information
1 parent
c7100b2
commit c28f76f
Showing
5 changed files
with
53 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 4 additions & 14 deletions
18
samples/kotlin-cli/src/main/kotlin/org/jellyfin/sample/cli/command/Login.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,16 @@ | ||
package org.jellyfin.sample.cli.command | ||
|
||
import com.github.ajalt.clikt.core.CliktCommand | ||
import com.github.ajalt.clikt.parameters.options.option | ||
import com.github.ajalt.clikt.parameters.options.required | ||
import kotlinx.coroutines.runBlocking | ||
import org.jellyfin.sample.cli.serverOption | ||
import org.jellyfin.sample.cli.apiInstanceHolder | ||
import org.jellyfin.sdk.Jellyfin | ||
import org.jellyfin.sdk.api.client.extensions.authenticateUserByName | ||
import org.jellyfin.sdk.api.client.extensions.userApi | ||
|
||
class Login( | ||
private val jellyfin: Jellyfin | ||
jellyfin: Jellyfin | ||
) : CliktCommand("Login to a given server and retrieve an access token") { | ||
private val server by serverOption() | ||
private val username by option("-u", "--username", help = "Username").required() | ||
private val password by option("-p", "--password", help = "Password") | ||
private val api by apiInstanceHolder(jellyfin) | ||
|
||
override fun run() = runBlocking { | ||
val api = jellyfin.createApi(baseUrl = server) | ||
|
||
val result by api.userApi.authenticateUserByName(username, password.orEmpty()) | ||
|
||
if (result.accessToken != null) println(result.accessToken) | ||
if (api.accessToken != null) println(api.accessToken) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters