Fladder/lib/models/credentials_model.dart
PartyDonut f7ceb6c3a7
fix: Updated auth header (#62)
## Pull Request Description

Use updated auth header for jellyfin authentication

## Issue Being Fixed

Using deprecated auth headers

Resolves #61 

## Checklist

- [x] If a new package was added, did you ensure it works for all
supported platforms? Is the package also well maintained?
- [x] Did you add localization for any text? If yes, did you sort the
.arb file using ```arb_utils sort <INPUT_FILE>```?
- [x] Check that any changes are related to the issue at hand.

Co-authored-by: PartyDonut <PartyDonut@users.noreply.github.com>
2024-10-22 16:29:38 +02:00

80 lines
2.1 KiB
Dart

import 'dart:convert';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:xid/xid.dart';
import 'package:fladder/util/application_info.dart';
class CredentialsModel {
final String token;
final String server;
final String serverName;
final String serverId;
final String deviceId;
CredentialsModel({
this.token = "",
this.server = "",
this.serverName = "",
this.serverId = "",
required this.deviceId,
});
factory CredentialsModel.createNewCredentials() {
return CredentialsModel(deviceId: Xid().toString());
}
Map<String, String> header(Ref ref) {
final application = ref.read(applicationInfoProvider);
final headers = {
'content-type': 'application/json',
'authorization':
'MediaBrowser Token="$token", Client="${application.name}", Device="${application.os}", DeviceId="$deviceId", Version="${application.version}"'
};
return headers;
}
CredentialsModel copyWith({
String? token,
String? server,
String? serverName,
String? serverId,
String? deviceId,
}) {
return CredentialsModel(
token: token ?? this.token,
server: server ?? this.server,
serverName: serverName ?? this.serverName,
serverId: serverId ?? this.serverId,
deviceId: deviceId ?? this.deviceId,
);
}
Map<String, dynamic> toMap() {
return {
'token': token,
'server': server,
'serverName': serverName,
'serverId': serverId,
'deviceId': deviceId,
};
}
factory CredentialsModel.fromMap(Map<String, dynamic> map) {
return CredentialsModel(
token: map['token'] ?? '',
server: map['server'] ?? '',
serverName: map['serverName'] ?? '',
serverId: map['serverId'] ?? '',
deviceId: map['deviceId'] ?? '',
);
}
String toJson() => json.encode(toMap());
factory CredentialsModel.fromJson(String source) => CredentialsModel.fromMap(json.decode(source));
@override
String toString() {
return 'CredentialsModel(token: $token, server: $server, serverName: $serverName, serverId: $serverId, header: $header)';
}
}