fix authentication by not authenticating

This commit is contained in:
Sammy 2023-06-03 22:06:23 +02:00
parent f91157467d
commit 4917fe11da

View File

@ -25,20 +25,22 @@ export class JellyfinHandler {
} }
constructor(_config: Config, _userApi?: UserApi, _systemApi?: SystemApi) { constructor(_config: Config, _userApi?: UserApi, _systemApi?: SystemApi) {
this.config = _config this.config = _config
const userApiConfigurationParams: ConfigurationParameters = {
basePath: this.config.bot.jellyfin_url
}
const systemApiConfigurationParams: ConfigurationParameters = {
basePath: this.config.bot.jellyfin_url
}
this.userApi = _userApi ?? new UserApi(new Configuration(userApiConfigurationParams))
this.systemApi = _systemApi ?? new SystemApi(new Configuration(systemApiConfigurationParams))
this.token = this.config.bot.jellfin_token this.token = this.config.bot.jellfin_token
this.authHeader = { this.authHeader = {
headers: { headers: {
"X-MediaBrowser-Token": this.token "X-MediaBrowser-Token": this.token
} }
} }
const userApiConfigurationParams: ConfigurationParameters = {
basePath: this.config.bot.jellyfin_url,
headers: this.authHeader.headers
}
const systemApiConfigurationParams: ConfigurationParameters = {
basePath: this.config.bot.jellyfin_url,
headers: this.authHeader.headers
}
this.userApi = _userApi ?? new UserApi(new Configuration(userApiConfigurationParams))
this.systemApi = _systemApi ?? new SystemApi(new Configuration(systemApiConfigurationParams))
logger.info(`Initialized Jellyfin handler`, { requestId: 'Init' }) logger.info(`Initialized Jellyfin handler`, { requestId: 'Init' })
} }
@ -51,7 +53,7 @@ export class JellyfinHandler {
} }
private generatePasswordForUser(user: GuildMember): string { private generatePasswordForUser(user: GuildMember): string {
return user.nickname + user.user.discriminator return user.displayName + user.user.discriminator
} }
public async createUserAccountForDiscordUser(discordUser: GuildMember, guildId?: string, requestId?: string): Promise<UserDto> { public async createUserAccountForDiscordUser(discordUser: GuildMember, guildId?: string, requestId?: string): Promise<UserDto> {
@ -64,7 +66,7 @@ export class JellyfinHandler {
} }
} }
logger.debug(JSON.stringify(req)) logger.debug(JSON.stringify(req))
const createResult = await this.userApi.createUserByName(req, this.authHeader) const createResult = await this.userApi.createUserByName(req)
if (createResult) if (createResult)
return createResult return createResult
else throw new Error('Could not create User in Jellyfin') else throw new Error('Could not create User in Jellyfin')
@ -79,7 +81,7 @@ export class JellyfinHandler {
isDisabled: true isDisabled: true
}, },
} }
await this.userApi.updateUserPolicy(r, this.authHeader) await this.userApi.updateUserPolicy(r)
logger.info(`Succeeded with disabling user: ${user.name}`) logger.info(`Succeeded with disabling user: ${user.name}`)
} }
else { else {
@ -127,7 +129,7 @@ export class JellyfinHandler {
updateUserPolicyRequest: { updateUserPolicyRequest: {
} }
} }
await this.userApi.updateUserPolicy(r, this.authHeader) await this.userApi.updateUserPolicy(r)
logger.info(`Succeeded with enabling user: ${user.name}`) logger.info(`Succeeded with enabling user: ${user.name}`)
} }
else { else {