Skip to content

Commit

Permalink
🐛 Fixed tv refresh tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
LNA-DEV committed Nov 2, 2024
1 parent d8c1154 commit 1427f92
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
8 changes: 7 additions & 1 deletion lib/auth/device_code.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:open_media_server_app/helpers/preferences.dart';
import 'package:open_media_server_app/models/auth/auth_info.dart';
import 'package:qr_flutter/qr_flutter.dart';

Expand Down Expand Up @@ -78,6 +79,7 @@ class DeviceCode {
interval,
authInfo.clientId,
authInfo.tokenUrl,
scope,
);

return token;
Expand All @@ -89,7 +91,7 @@ class DeviceCode {
}

Future<String?> pollForToken(
String deviceCode, int interval, String clientId, String tokenUrl) async {
String deviceCode, int interval, String clientId, String tokenUrl, String scope) async {
while (true) {
await Future.delayed(Duration(seconds: interval));

Expand All @@ -102,13 +104,17 @@ class DeviceCode {
'client_id': clientId,
'grant_type': 'urn:ietf:params:oauth:grant-type:device_code',
'device_code': deviceCode,
'scope': scope
},
);

if (response.statusCode == 200) {
final tokenResponse = json.decode(response.body);
print('Access token: ${tokenResponse['access_token']}');

Preferences.prefs?.setString("RefreshToken", tokenResponse['refresh_token']);
print('Refresh token: ${tokenResponse['refresh_token']}');

return tokenResponse['access_token'];
} else {
final errorResponse = json.decode(response.body);
Expand Down
7 changes: 6 additions & 1 deletion lib/auth/login_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ class LoginManager {

LoginManager(AuthInfo authInfo) {
if (PlatformGlobals.isTv) {
// Do nothing
client = OAuth2Client(
authorizeUrl: authInfo.authorizeUrl,
tokenUrl: authInfo.tokenUrl,
redirectUri: "my.test.app:/oauth2redirect", // TODO
customUriScheme: "my.test.app",
);
} else if (!PlatformGlobals.isWeb) {
client = OAuth2Client(
authorizeUrl: authInfo.authorizeUrl,
Expand Down
17 changes: 9 additions & 8 deletions lib/views/detail_views/show_detail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ class ShowDetailView extends StatelessWidget {
List<Widget> seasons = [];

for (var element in items) {
String imageUrl = Globals.PictureNotFoundUrl;

if (element.posterUrl != null) {
imageUrl = "${element.posterUrl!}?height=300";
}

seasons.add(
Padding(
padding: const EdgeInsets.all(8.0),
Expand All @@ -54,7 +60,7 @@ class ShowDetailView extends StatelessWidget {
width: 300 * (9 / 14),
fit: BoxFit.cover,
image: CachedNetworkImageProvider(
element.posterUrl ?? Globals.PictureNotFoundUrl,
imageUrl,
headers: BaseApi.getHeaders(),
),
),
Expand Down Expand Up @@ -85,12 +91,6 @@ class ShowDetailView extends StatelessWidget {
);
}

String imageUrl = Globals.PictureNotFoundUrl;

if (itemModel.backdropUrl != null) {
imageUrl = "${itemModel.backdropUrl!}?height=300";
}

return SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
Expand All @@ -109,7 +109,8 @@ class ShowDetailView extends StatelessWidget {
},
blendMode: BlendMode.dstIn,
child: CustomImage(
imageUrl: imageUrl,
imageUrl:
itemModel.backdropUrl ?? Globals.PictureNotFoundUrl,
height: 300,
width: double.infinity,
fit: BoxFit.cover,
Expand Down
4 changes: 3 additions & 1 deletion lib/widgets/custom_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ class CustomImage extends StatelessWidget {
required this.imageUrl,
this.fit,
this.width,
this.height,
this.height,
this.disableAdaptiveImage = false,
});

final String imageUrl;
final BoxFit? fit;
final double? width;
final double? height;
final bool disableAdaptiveImage;

@override
Widget build(BuildContext context) {
Expand Down

0 comments on commit 1427f92

Please sign in to comment.