-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
79 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import 'dart:convert'; | ||
import 'package:open_media_server_app/apis/base_api.dart'; | ||
import 'package:http/http.dart' as http; | ||
import 'package:open_media_server_app/globals.dart'; | ||
import 'package:open_media_server_app/models/auth/auth_info.dart'; | ||
|
||
class AuthInfoApi { | ||
Future<AuthInfo> getAuthInfo() async { | ||
String apiUrl = "${Globals.BaseUrl}/auth/info"; | ||
|
||
var headers = BaseApi.getHeaders(); | ||
|
||
var response = await http.get( | ||
Uri.parse(apiUrl), | ||
headers: headers, | ||
); | ||
|
||
if (response.statusCode == 200) { | ||
var decoded = json.decode(response.body); | ||
return AuthInfo.fromJson(decoded); | ||
} else { | ||
throw Exception('Failed to load auth info'); | ||
} | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
class AuthInfo { | ||
String authorizeUrl; | ||
String deviceCodeUrl; | ||
String tokenUrl; | ||
String clientId; | ||
|
||
AuthInfo({ | ||
required this.authorizeUrl, | ||
required this.deviceCodeUrl, | ||
required this.tokenUrl, | ||
required this.clientId, | ||
}); | ||
|
||
factory AuthInfo.fromJson(Map<String, dynamic> json) { | ||
return AuthInfo( | ||
authorizeUrl: json['authorizeUrl'] as String, | ||
deviceCodeUrl: json['deviceCodeUrl'] as String, | ||
tokenUrl: json['tokenUrl'] as String, | ||
clientId: json['clientId'] as String, | ||
); | ||
} | ||
|
||
// Method for converting an instance to JSON | ||
Map<String, dynamic> toJson() { | ||
return { | ||
'authorizeUrl': authorizeUrl, | ||
'deviceCodeUrl': deviceCodeUrl, | ||
'tokenUrl': tokenUrl, | ||
'clientId': clientId, | ||
}; | ||
} | ||
} |