basic oauth finally but also more dependencies
This commit is contained in:
parent
4baacc751d
commit
f6ea45d0e2
5 changed files with 21 additions and 10 deletions
|
@ -30,10 +30,13 @@ class App {
|
|||
}
|
||||
}
|
||||
|
||||
Future<http.Response> askKnownServerForAppRegistration() async {
|
||||
Future<http.Response> doOauthFlow() async {
|
||||
String url = await settings.loadInstanceUrl();
|
||||
try {
|
||||
return await registerApp(url);
|
||||
http.Response response = await registerApp(url);
|
||||
print(response.body);
|
||||
openBrowserForAuthCode(url, App.fromJson(jsonDecode(response.body)));
|
||||
return response;
|
||||
} catch (e) {
|
||||
return http.Response(jsonEncode({}), 404);
|
||||
}
|
||||
|
@ -46,7 +49,7 @@ Future<http.Response> registerApp(String baseurl) async {
|
|||
headers: global.defaultHeaders,
|
||||
body: jsonEncode({
|
||||
'client_name': global.name,
|
||||
'redirect_uris': "urn:ietf:wg:oauth:2.0:oob",
|
||||
'redirect_uris': "http://localhost:4040",
|
||||
'scopes': "read write",
|
||||
'website': global.website
|
||||
}));
|
||||
|
@ -54,14 +57,14 @@ Future<http.Response> registerApp(String baseurl) async {
|
|||
}
|
||||
|
||||
void openBrowserForAuthCode(String baseurl, App app) {
|
||||
Uri url = Uri.https(
|
||||
baseurl,
|
||||
Uri url = Uri(
|
||||
scheme: "https",
|
||||
path: "$baseurl/oauth/authorize",
|
||||
// ignore: prefer_interpolation_to_compose_strings
|
||||
"/oauth/authorize"
|
||||
"?client_id=" +
|
||||
query: "client_id=" +
|
||||
app.clientId +
|
||||
"&scope=read+write" +
|
||||
"&redirect_uri=urn:ietf:wg:oauth:2.0:oob" +
|
||||
"&redirect_uri=http://localhost:4040" +
|
||||
"&response_type=code");
|
||||
launchUrl(url);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:slothmu/business_logic/auth/oauth.dart';
|
||||
|
||||
enum Settings {
|
||||
instanceUrl,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue