diff --git a/.htaccess b/.htaccess
index b91932b..80f08ce 100644
--- a/.htaccess
+++ b/.htaccess
@@ -2,4 +2,5 @@
RewriteEngine on
RewriteRule index.php/apps/notes/api/v0.2 lib/nextcloudnotes.php [PT]
+ RewriteRule index.php/login/flow lib/nextcloudlogin.php [PT]
\ No newline at end of file
diff --git a/lib/nextcloudlogin.php b/lib/nextcloudlogin.php
new file mode 100644
index 0000000..40e5894
--- /dev/null
+++ b/lib/nextcloudlogin.php
@@ -0,0 +1,142 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
get($title); ?>
+
+
+
+
+
+
+
+ $_SESSION["login_code"]]);
+
+ if ($uidinfo["status"] == "ERROR") {
+ throw new Exception();
+ }
+ if (is_numeric($uidinfo['uid'])) {
+ $user = new User($uidinfo['uid'] * 1);
+ foreach ($SETTINGS['permissions'] as $perm) {
+ if (!$user->hasPermission($perm)) {
+ showHTML("no access permission", "", "");
+ die();
+ }
+ }
+
+ $addpassresp = AccountHubApi::get(
+ "addapppassword",
+ [
+ "desc" => $SETTINGS["site_title"] . " - Nextcloud Notes API",
+ "username" => $user->getUsername()
+ ],
+ true
+ );
+
+ $_SESSION["login_code"] = null;
+
+ $redirecturl = "nc://login/server:" . htmlentities($appurl) . "&user:" . htmlentities($user->getUsername()) . "&password:" . htmlentities($addpassresp["pass"]);
+
+ header("Location: $redirecturl");
+ die("Click here");
+ } else {
+ throw new Exception();
+ }
+ } catch (Exception $ex) {
+ $redirecttologin = true;
+ }
+}
+
+if ($redirecttologin) {
+ try {
+ $codedata = AccountHubApi::get("getloginkey", ["appname" => $SETTINGS["site_title"], "appicon" => $iconurl]);
+
+ if ($codedata['status'] != "OK") {
+ throw new Exception($Strings->get("login server unavailable", false));
+ }
+
+ $_SESSION["login_code"] = $codedata["code"];
+
+ $locationurl = $codedata["loginurl"] . "?code=" . htmlentities($codedata["code"]) . "&redirect=" . htmlentities($thisurl);
+
+ header("Location: $locationurl");
+ showHTML("Continue", "Continue", $locationurl);
+ die();
+ } catch (Exception $ex) {
+ sendError($ex->getMessage());
+ }
+}
\ No newline at end of file