This repository has been archived by the owner on Sep 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
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
17 changed files
with
273 additions
and
154 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 |
---|---|---|
@@ -1,13 +1,15 @@ | ||
![GitHub](https://img.shields.io/github/license/Teifun2/nextcloud-cookbook-flutter) ![GitHub release (latest by date)](https://img.shields.io/github/v/release/Teifun2/nextcloud-cookbook-flutter) ![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/Teifun2/nextcloud-cookbook-flutter/Build/master) | ||
|
||
[<img src="assets/IzzyOnDroid.png" alt="IzyyDroid" height="80px" />](https://apt.izzysoft.de/fdroid/index/apk/com.nextcloud_cookbook_flutter) | ||
# Nextcloud Cookbook Mobile Client written in Flutter | ||
|
||
This project aims to provide a mobile client for both Android and IOs for the nextcloud plugin cookbook (https://github.com/nextcloud/cookbook) | ||
This project aims to provide a mobile client for both Android and IOs for the nextcloud app cookbook (https://github.com/nextcloud/cookbook) | ||
|
||
It works best with an Nextcloud installation >= 17 | ||
|
||
## Screenshots | ||
|
||
![Screenshot_categories](https://user-images.githubusercontent.com/7461832/91664922-899d6400-eaf2-11ea-8120-3222bd5b5363.png) | ||
![Screenshot_category_list](https://user-images.githubusercontent.com/7461832/91664920-8904cd80-eaf2-11ea-9bb3-62e0b41f85c0.png) | ||
![Screenshot_recipe_1](https://user-images.githubusercontent.com/7461832/91664918-873b0a00-eaf2-11ea-86a6-e30fde4c98a9.png) | ||
![Screenshot_recipe_2](https://user-images.githubusercontent.com/7461832/91664923-8a35fa80-eaf2-11ea-9bfe-6ed8edc41b49.png) | ||
<img src="https://user-images.githubusercontent.com/7461832/91664922-899d6400-eaf2-11ea-8120-3222bd5b5363.png" alt="Screenshot_categories" width="300px" /> <img src="https://user-images.githubusercontent.com/7461832/91664920-8904cd80-eaf2-11ea-9bb3-62e0b41f85c0.png" alt="Screenshot_category_list" width="300px" /> | ||
|
||
<img src="https://user-images.githubusercontent.com/7461832/91664923-8a35fa80-eaf2-11ea-9bfe-6ed8edc41b49.png" alt="Screenshot_recipe_2" width="300px" /> <img src="https://user-images.githubusercontent.com/7461832/91664918-873b0a00-eaf2-11ea-86a6-e30fde4c98a9.png" alt="Screenshot_recipe_1" width="300px" /> | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,124 @@ | ||
import 'dart:async'; | ||
import 'dart:convert'; | ||
|
||
import 'package:dio/dio.dart' as dio; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_secure_storage/flutter_secure_storage.dart'; | ||
import 'package:http/http.dart' as http; | ||
import 'package:nextcloud_cookbook_flutter/src/models/app_authentication.dart'; | ||
import 'package:nextcloud_cookbook_flutter/src/models/intial_login.dart'; | ||
import 'package:url_launcher/url_launcher.dart'; | ||
|
||
class AuthenticationProvider { | ||
final FlutterSecureStorage _secureStorage = new FlutterSecureStorage(); | ||
final String _appAuthenticationKey = 'appAuthentication'; | ||
AppAuthentication currentAppAuthentication; | ||
bool resumeAuthenticate = true; | ||
|
||
Future<AppAuthentication> authenticate({ | ||
@required String serverUrl, | ||
}) async { | ||
resumeAuthenticate = true; | ||
if (serverUrl.substring(0, 4) != 'http') { | ||
serverUrl = 'https://' + serverUrl; | ||
} | ||
String urlInitialCall = serverUrl + '/index.php/login/v2'; | ||
var response; | ||
try { | ||
response = await http.post(urlInitialCall, | ||
headers: {"User-Agent": "Cookbook App", "Accept-Language": "en-US"}); | ||
} catch (e) { | ||
throw ('Cannot reach: $serverUrl'); | ||
} | ||
|
||
if (response.statusCode == 200) { | ||
final initialLogin = InitialLogin.fromJson(json.decode(response.body)); | ||
|
||
if (await canLaunch(initialLogin.login)) { | ||
_launchURL(initialLogin.login); | ||
|
||
String urlLoginSuccess = | ||
initialLogin.poll.endpoint + "?token=" + initialLogin.poll.token; | ||
|
||
var responseLog = await http.post(urlLoginSuccess); | ||
while (responseLog.statusCode != 200 && resumeAuthenticate) { | ||
await Future.delayed(Duration(milliseconds: 100)); | ||
responseLog = await http.post(urlLoginSuccess); | ||
} | ||
|
||
await closeWebView(); | ||
|
||
if (responseLog.statusCode != 200) { | ||
throw "Login Process was interrupted!"; | ||
} else { | ||
return AppAuthentication.fromJson(responseLog.body); | ||
} | ||
} else { | ||
throw 'Could not launch the authentication window.'; | ||
} | ||
} else { | ||
throw Exception('Your server Name is not correct'); | ||
} | ||
} | ||
|
||
void stopAuthenticate() { | ||
resumeAuthenticate = false; | ||
} | ||
|
||
Future<bool> hasAppAuthentication() async { | ||
if (currentAppAuthentication != null) { | ||
return true; | ||
} else { | ||
String appAuthentication = | ||
await _secureStorage.read(key: _appAuthenticationKey); | ||
return appAuthentication != null; | ||
} | ||
} | ||
|
||
Future<void> loadAppAuthentication() async { | ||
String appAuthenticationString = | ||
await _secureStorage.read(key: _appAuthenticationKey); | ||
if (appAuthenticationString == null) { | ||
throw ("No authentication found in Storage"); | ||
} else { | ||
currentAppAuthentication = | ||
AppAuthentication.fromJson(appAuthenticationString); | ||
} | ||
} | ||
|
||
Future<void> persistAppAuthentication( | ||
AppAuthentication appAuthentication) async { | ||
currentAppAuthentication = appAuthentication; | ||
await _secureStorage.write( | ||
key: _appAuthenticationKey, value: appAuthentication.toJson()); | ||
} | ||
|
||
Future<void> deleteAppAuthentication() async { | ||
var response = await dio.Dio().delete( | ||
"${currentAppAuthentication.server}/ocs/v2.php/core/apppassword", | ||
options: new dio.Options( | ||
headers: { | ||
"OCS-APIREQUEST": "true", | ||
"authorization": currentAppAuthentication.basicAuth | ||
}, | ||
), | ||
); | ||
|
||
if (response.statusCode != 200) { | ||
debugPrint("Failed to remove remote apppassword!"); | ||
} | ||
|
||
//TODO Delete Appkey Serverside | ||
currentAppAuthentication = null; | ||
await _secureStorage.delete(key: _appAuthenticationKey); | ||
} | ||
|
||
Future<void> _launchURL(String url) async { | ||
await launch( | ||
url, | ||
forceSafariVC: true, | ||
forceWebView: true, | ||
enableJavaScript: true, | ||
); | ||
} | ||
} |
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
Oops, something went wrong.