mirror of
https://github.com/jellyfin/jellyfin.org.git
synced 2026-09-03 04:30:04 +03:00
WIP authentication page
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
---
|
||||
title: Authentication
|
||||
sidebar_position: 3
|
||||
---
|
||||
|
||||
# Authentication
|
||||
|
||||
## Password login
|
||||
|
||||
The password login is the easiest method to implement. Use the authenticateUserByName method in the userApi with a username and password combination to get an access token. The server responds with an HTTP 401 status code when the credentials are invalid, otherwise it contains the authentication result with user information.
|
||||
|
||||
import Tabs from '@theme/Tabs';
|
||||
import TabItem from '@theme/TabItem';
|
||||
import CodeBlock from '@theme/CodeBlock';
|
||||
import AuthByNameSnippetTs from '!!raw-loader!./snippet/auth-byname.ts';
|
||||
import AuthByNameSnippetKt from '!!raw-loader!./snippet/auth-byname.kt';
|
||||
|
||||
<Tabs defaultValue='ts' groupId='dev-sdk-language'>
|
||||
<TabItem value='ts' label='TypeScript'>
|
||||
<CodeBlock language='typescript'>{AuthByNameSnippetTs}</CodeBlock>
|
||||
</TabItem>
|
||||
<TabItem value='kt' label='Kotlin'>
|
||||
<CodeBlock language='kt'>{AuthByNameSnippetKt}</CodeBlock>
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
@@ -0,0 +1,21 @@
|
||||
val api = jellyfin.createApi(/* .. */)
|
||||
|
||||
try {
|
||||
// highlight-start
|
||||
val authenticationResult by api.userApi.authenticateUserByName(
|
||||
username = "demo",
|
||||
password = "",
|
||||
)
|
||||
// highlight-end
|
||||
|
||||
// Use access token in api instance
|
||||
api.accessToken = authenticationResult.accessToken
|
||||
|
||||
// Print session information
|
||||
println(authenticationResult.sessionInfo)
|
||||
} catch (err: InvalidStatusException) {
|
||||
if (err.status == 401) {
|
||||
// Username or password is incorrect
|
||||
println("Invalid user")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
const api = new Jellyfin(/* .. */);
|
||||
|
||||
try {
|
||||
// highlight-start
|
||||
const authenticationResult = await api.authenticateUserByName('demo', '');
|
||||
// highlight-end
|
||||
|
||||
// Log session information
|
||||
console.log(authenticationResult.data.sessionInfo);
|
||||
} catch (err) {
|
||||
// TODO: Check how to catch 401 with TS SDK
|
||||
if (err.status == 401) {
|
||||
// Username or password is incorrect
|
||||
console.log('Invalid user');
|
||||
}
|
||||
}
|
||||
@@ -101,6 +101,9 @@ const config: Config = {
|
||||
</a>
|
||||
<br/>
|
||||
Site content is licensed <a href='http://creativecommons.org/licenses/by-nd/4.0/'>CC-BY-ND-4.0</a>`
|
||||
},
|
||||
prism: {
|
||||
additionalLanguages: ['kotlin', 'typescript', 'python']
|
||||
}
|
||||
},
|
||||
plugins: [
|
||||
|
||||
Generated
+37
@@ -26,6 +26,7 @@
|
||||
"clsx": "2.1.0",
|
||||
"docusaurus-plugin-sass": "0.2.5",
|
||||
"file-loader": "6.2.0",
|
||||
"raw-loader": "4.0.2",
|
||||
"react": "18.2.0",
|
||||
"react-dom": "18.2.0",
|
||||
"sass": "1.71.0",
|
||||
@@ -14893,6 +14894,42 @@
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/raw-loader": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/raw-loader/-/raw-loader-4.0.2.tgz",
|
||||
"integrity": "sha512-ZnScIV3ag9A4wPX/ZayxL/jZH+euYb6FcUinPcgiQW0+UBtEv0O6Q3lGd3cqJ+GHH+rksEv3Pj99oxJ3u3VIKA==",
|
||||
"dependencies": {
|
||||
"loader-utils": "^2.0.0",
|
||||
"schema-utils": "^3.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 10.13.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/webpack"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"webpack": "^4.0.0 || ^5.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/raw-loader/node_modules/schema-utils": {
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-3.1.1.tgz",
|
||||
"integrity": "sha512-Y5PQxS4ITlC+EahLuXaY86TXfR7Dc5lw294alXOq86JAHCihAIZfqv8nNCWvaEJvaC51uN9hbLGeV0cFBdH+Fw==",
|
||||
"dependencies": {
|
||||
"@types/json-schema": "^7.0.8",
|
||||
"ajv": "^6.12.5",
|
||||
"ajv-keywords": "^3.5.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 10.13.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/webpack"
|
||||
}
|
||||
},
|
||||
"node_modules/rc": {
|
||||
"version": "1.2.8",
|
||||
"resolved": "https://registry.npmjs.org/rc/-/rc-1.2.8.tgz",
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
"react-dom": "18.2.0",
|
||||
"sass": "1.71.0",
|
||||
"swiper": "11.0.6",
|
||||
"raw-loader": "4.0.2",
|
||||
"url-loader": "4.1.1"
|
||||
},
|
||||
"browserslist": {
|
||||
|
||||
Reference in New Issue
Block a user