|
53 | 53 | import com.google.gson.reflect.TypeToken; |
54 | 54 | import com.nextcloud.android.common.ui.color.ColorUtil; |
55 | 55 | import com.nextcloud.android.common.ui.theme.utils.ColorRole; |
| 56 | +import com.nextcloud.android.lib.resources.users.GenerateOneTimeAppPasswordRemoteOperation; |
56 | 57 | import com.nextcloud.client.account.User; |
57 | 58 | import com.nextcloud.client.account.UserAccountManager; |
58 | 59 | import com.nextcloud.client.device.DeviceInfo; |
|
61 | 62 | import com.nextcloud.client.onboarding.FirstRunActivity; |
62 | 63 | import com.nextcloud.client.onboarding.OnboardingService; |
63 | 64 | import com.nextcloud.client.preferences.AppPreferences; |
| 65 | +import com.nextcloud.common.NextcloudClient; |
64 | 66 | import com.nextcloud.common.PlainClient; |
65 | 67 | import com.nextcloud.operations.PostMethod; |
66 | 68 | import com.nextcloud.utils.extensions.BundleExtensionsKt; |
|
137 | 139 | import androidx.lifecycle.LifecycleEventObserver; |
138 | 140 | import androidx.lifecycle.ProcessLifecycleOwner; |
139 | 141 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; |
| 142 | +import okhttp3.Credentials; |
140 | 143 | import okhttp3.FormBody; |
141 | 144 | import okhttp3.RequestBody; |
142 | 145 |
|
@@ -1594,11 +1597,43 @@ private void startQRScanner() { |
1594 | 1597 | accountManager.getAccounts().length == 1) { |
1595 | 1598 | DisplayUtils.showSnackMessage(this, R.string.no_mutliple_accounts_allowed); |
1596 | 1599 | } else { |
1597 | | - parseAndLoginFromWebView(resultData); |
| 1600 | + String onetimePrefix = getString(R.string.login_data_own_scheme) + PROTOCOL_SUFFIX + "onetime-login/"; |
| 1601 | + |
| 1602 | + if (resultData.startsWith(onetimePrefix)) { |
| 1603 | + parseAndLoginFromOneTimeCode(onetimePrefix, resultData); |
| 1604 | + } else { |
| 1605 | + parseAndLoginFromWebView(resultData); |
| 1606 | + } |
1598 | 1607 | } |
1599 | 1608 | } |
1600 | 1609 | }); |
1601 | 1610 |
|
| 1611 | + private void parseAndLoginFromOneTimeCode(String onetimePrefix, String resultData) { |
| 1612 | + LoginUrlInfo loginUrlInfo = parseLoginDataUrl(onetimePrefix, resultData); |
| 1613 | + |
| 1614 | + GenerateOneTimeAppPasswordRemoteOperation generateOneTimeAppPasswordRemoteOperation = new GenerateOneTimeAppPasswordRemoteOperation(); |
| 1615 | + |
| 1616 | + String credentials = Credentials.basic(loginUrlInfo.getLoginName(), loginUrlInfo.getAppPassword()); |
| 1617 | + NextcloudClient nextcloudClient = new NextcloudClient(Uri.parse(loginUrlInfo.getServer()), loginUrlInfo.getLoginName(), credentials, this); |
| 1618 | + |
| 1619 | + new Thread(() -> { |
| 1620 | + RemoteOperationResult<String> otpResult = nextcloudClient.execute(generateOneTimeAppPasswordRemoteOperation); |
| 1621 | + |
| 1622 | + if (otpResult.isSuccess()) { |
| 1623 | + mServerInfo.mBaseUrl = AuthenticatorUrlUtils.INSTANCE.normalizeUrlSuffix(loginUrlInfo.getServer()); |
| 1624 | + webViewUser = loginUrlInfo.getLoginName(); |
| 1625 | + webViewPassword = otpResult.getResultData(); |
| 1626 | + |
| 1627 | + runOnUiThread(this::checkOcServer); |
| 1628 | + } else { |
| 1629 | + mServerStatusIcon = R.drawable.ic_alert; |
| 1630 | + mServerStatusText = getString(R.string.qr_could_not_be_read); |
| 1631 | + |
| 1632 | + runOnUiThread(this::showServerStatus); |
| 1633 | + } |
| 1634 | + }).start(); |
| 1635 | + } |
| 1636 | + |
1602 | 1637 | @Override |
1603 | 1638 | public void onRequestPermissionsResult(int requestCode, |
1604 | 1639 | @NonNull String[] permissions, |
|
0 commit comments