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,
|
||||
|
|
|
@ -125,13 +125,12 @@ class _AuthPageState extends State<AuthPage> {
|
|||
icon: const Icon(Icons.arrow_back),
|
||||
label: Text("back-button".i18n())),
|
||||
FutureBuilder<http.Response>(
|
||||
future: oauth.askKnownServerForAppRegistration(),
|
||||
future: oauth.doOauthFlow(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasError) {
|
||||
return Text("login-failed-snackbar-text".i18n());
|
||||
} else if (snapshot.hasData) {
|
||||
if (snapshot.data?.statusCode != null) {
|
||||
print(snapshot.data?.body);
|
||||
if (snapshot.data?.statusCode != 200) {
|
||||
return Row(
|
||||
children: [
|
||||
|
|
|
@ -273,6 +273,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.1"
|
||||
shelf:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: shelf
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.3.1"
|
||||
sky_engine:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
|
|
|
@ -42,6 +42,7 @@ dependencies:
|
|||
shared_preferences: ^2.0.15
|
||||
intl: ^0.17.0
|
||||
url_launcher: ^6.1.4
|
||||
shelf: ^1.3.1
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
Loading…
Reference in a new issue