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; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue