register app in ui
This commit is contained in:
parent
bc8d31ccbc
commit
4baacc751d
3 changed files with 101 additions and 10 deletions
|
@ -1,6 +1,9 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import '../../global.dart' as global;
|
||||
import '../../business_logic/settings.dart' as settings;
|
||||
|
||||
class App {
|
||||
late String clientSecret;
|
||||
|
@ -27,15 +30,26 @@ class App {
|
|||
}
|
||||
}
|
||||
|
||||
Future<http.Response> askKnownServerForAppRegistration() async {
|
||||
String url = await settings.loadInstanceUrl();
|
||||
try {
|
||||
return await registerApp(url);
|
||||
} catch (e) {
|
||||
return http.Response(jsonEncode({}), 404);
|
||||
}
|
||||
}
|
||||
|
||||
Future<http.Response> registerApp(String baseurl) async {
|
||||
//String url = baseurl Uri."api/v1/apps";
|
||||
Uri url = Uri.https(baseurl, "/api/v1/apps");
|
||||
var response = await http.post(url, headers: global.defaultHeaders, body: {
|
||||
'client_name': global.name,
|
||||
'redirect_uris': "ietf:wg:oauth:2.0:oob",
|
||||
'scopes': "read write",
|
||||
'website': global.website
|
||||
});
|
||||
final response = await http.post(url,
|
||||
headers: global.defaultHeaders,
|
||||
body: jsonEncode({
|
||||
'client_name': global.name,
|
||||
'redirect_uris': "urn:ietf:wg:oauth:2.0:oob",
|
||||
'scopes': "read write",
|
||||
'website': global.website
|
||||
}));
|
||||
return response;
|
||||
}
|
||||
|
||||
|
|
30
lib/business_logic/settings.dart
Normal file
30
lib/business_logic/settings.dart
Normal file
|
@ -0,0 +1,30 @@
|
|||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
enum Settings {
|
||||
instanceUrl,
|
||||
username,
|
||||
}
|
||||
|
||||
void saveSetting(Settings setting, dynamic value) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
}
|
||||
|
||||
Future<bool> saveInstanceUrl(String url) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
return prefs.setString("instance-url", url);
|
||||
}
|
||||
|
||||
Future<String> loadInstanceUrl() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
String? possibleReturn = prefs.getString("instance-url");
|
||||
if (possibleReturn == null) {
|
||||
return "example.com";
|
||||
} else {
|
||||
return possibleReturn;
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> saveUsername(String username) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
return prefs.setString("username", username);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue