Add check for available oauth request token

This commit is contained in:
Vitaliy 2021-02-03 11:52:51 +02:00
parent 6dcde54ace
commit 95cc20b022
2 changed files with 10 additions and 14 deletions

View file

@ -94,6 +94,10 @@ public class OsmOAuthAuthorizationClient {
return accessToken; return accessToken;
} }
public OAuth1RequestToken getRequestToken() {
return requestToken;
}
public Response performRequestWithoutAuth(String url, String requestMethod, String requestBody) public Response performRequestWithoutAuth(String url, String requestMethod, String requestBody)
throws InterruptedException, ExecutionException, IOException { throws InterruptedException, ExecutionException, IOException {
Verb verb = parseRequestMethod(requestMethod); Verb verb = parseRequestMethod(requestMethod);

View file

@ -1,19 +1,10 @@
package net.osmand.plus.osmedit.oauth; package net.osmand.plus.osmedit.oauth;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.net.TrafficStats; import android.net.TrafficStats;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build;
import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import androidx.annotation.NonNull;
import androidx.browser.customtabs.CustomTabsIntent;
import androidx.core.content.ContextCompat;
import com.github.scribejava.core.builder.api.DefaultApi10a; import com.github.scribejava.core.builder.api.DefaultApi10a;
import com.github.scribejava.core.model.OAuth1AccessToken; import com.github.scribejava.core.model.OAuth1AccessToken;
@ -24,7 +15,6 @@ import com.github.scribejava.core.model.Verb;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.osm.oauth.OsmOAuthAuthorizationClient; import net.osmand.osm.oauth.OsmOAuthAuthorizationClient;
import net.osmand.plus.OsmAndConstants;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.wikipedia.WikipediaDialogFragment; import net.osmand.plus.wikipedia.WikipediaDialogFragment;
@ -137,7 +127,7 @@ public class OsmOAuthAuthorizationAdapter {
} }
@Override @Override
protected void onPostExecute(@NonNull OAuth1RequestToken requestToken) { protected void onPostExecute(OAuth1RequestToken requestToken) {
if (requestToken != null) { if (requestToken != null) {
loadWebView(rootLayout, nightMode, client.getService().getAuthorizationUrl(requestToken)); loadWebView(rootLayout, nightMode, client.getService().getAuthorizationUrl(requestToken));
} else { } else {
@ -156,9 +146,11 @@ public class OsmOAuthAuthorizationAdapter {
@Override @Override
protected Void doInBackground(String... oauthVerifier) { protected Void doInBackground(String... oauthVerifier) {
if (client.getRequestToken() != null) {
client.authorize(oauthVerifier[0]); client.authorize(oauthVerifier[0]);
saveToken(); saveToken();
updateUserName(); updateUserName();
}
return null; return null;
} }