Skip to content

Commit

Permalink
Clean up and remove oauth1 and signpost references
Browse files Browse the repository at this point in the history
  • Loading branch information
mendhak committed Nov 2, 2023
1 parent 13dacfc commit e35f64e
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 120 deletions.
15 changes: 0 additions & 15 deletions assets/text/opensource.md
Original file line number Diff line number Diff line change
Expand Up @@ -793,21 +793,6 @@ limitations under the License.
[2]: http://www.gnu.org/licenses/lgpl-2.1.html


## [mttkay/signpost](https://github.com/mttkay/signpost)


Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

## [eltos/SimpleDialogFragments](https://github.com/eltos/SimpleDialogFragments)

Apache License
Expand Down
8 changes: 0 additions & 8 deletions gpslogger/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,6 @@ dependencies {
//OKHTTP client
implementation 'com.squareup.okhttp3:okhttp:3.10.0'

//OKHTTP interceptor, works with oauth signpost
implementation 'se.akerfeldt:okhttp-signpost:1.1.0'

//OAuth signing
implementation('oauth.signpost:signpost-core:1.2.1.1'){
exclude module: 'commons-codec'
}

//Dropbox API 3
implementation 'com.dropbox.core:dropbox-core-sdk:5.1.1'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -942,33 +942,6 @@ public void setOSMAuthState(String auth_state_json_serialized){
prefs.edit().putString(PreferenceNames.OPENSTREETMAP_AUTH_STATE, auth_state_json_serialized).apply();
}

/**
* Sets OpenStreetMap OAuth secret for auto send
*/
public void setOSMAccessTokenSecret(String secret) {
prefs.edit().putString(PreferenceNames.OPENSTREETMAP_ACCESS_TOKEN_SECRET, secret).apply();
}

/**
* Gets access token secret for OpenStreetMap auto send
*/
public String getOSMAccessTokenSecret() {
return prefs.getString(PreferenceNames.OPENSTREETMAP_ACCESS_TOKEN_SECRET, "");
}

/**
* Sets request token for OpenStreetMap auto send
*/
public void setOSMRequestToken(String token) {
prefs.edit().putString(PreferenceNames.OPENSTREETMAP_REQUEST_TOKEN, token).apply();
}

/**
* Sets request token secret for OpenStreetMap auto send
*/
public void setOSMRequestTokenSecret(String secret) {
prefs.edit().putString(PreferenceNames.OPENSTREETMAP_REQUEST_TOKEN_SECRET, secret).apply();
}

/**
* Description of uploaded trace on OpenStreetMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import javax.net.ssl.X509TrustManager;

import de.greenrobot.event.EventBus;
import oauth.signpost.OAuthConsumer;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
Expand All @@ -59,17 +58,15 @@ public class OSMJob extends Job {

private final AtomicBoolean taskDone = new AtomicBoolean(false);
private String openStreetMapAccessToken;
//OAuthConsumer consumer;
String gpsTraceUrl;
File chosenFile;
String description;
String tags;
String visibility;

protected OSMJob(OAuthConsumer consumer, String gpsTraceUrl, File chosenFile, String description, String tags, String visibility) {
protected OSMJob(String gpsTraceUrl, File chosenFile, String description, String tags, String visibility) {
super(new Params(1).requireNetwork().persist().addTags(getJobTag(chosenFile)));

// this.consumer = consumer;
this.gpsTraceUrl = gpsTraceUrl;
this.chosenFile = chosenFile;
this.description = description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,8 @@
import net.openid.appauth.AuthorizationService;
import net.openid.appauth.AuthorizationServiceConfiguration;

import oauth.signpost.OAuthConsumer;
import oauth.signpost.OAuthProvider;

import org.json.JSONException;
import org.slf4j.Logger;
import se.akerfeldt.okhttp.signpost.OkHttpOAuthConsumer;
import se.akerfeldt.okhttp.signpost.OkHttpOAuthProvider;


import java.io.File;
import java.util.List;

Expand All @@ -53,9 +46,7 @@ public class OpenStreetMapManager extends FileSender {


private static final Logger LOG = Logs.of(OpenStreetMapManager.class);
static final String OSM_REQUESTTOKEN_URL = "https://www.openstreetmap.org/oauth2/request_token";
static final String OSM_ACCESSTOKEN_URL = "https://www.openstreetmap.org/oauth2/access_token";
static final String OSM_AUTHORIZE_URL = "https://www.openstreetmap.org/oauth2/authorize";

static final String OSM_GPSTRACE_URL = "https://www.openstreetmap.org/api/0.6/gpx/create";
private PreferenceHelper preferenceHelper;

Expand Down Expand Up @@ -89,9 +80,6 @@ public static AuthorizationServiceConfiguration getAuthorizationServiceConfigura
);
}

public static OAuthProvider getOSMAuthProvider() {
return new OkHttpOAuthProvider(OSM_REQUESTTOKEN_URL, OSM_ACCESSTOKEN_URL, OSM_AUTHORIZE_URL);
}

public static AuthState getAuthState() {
AuthState authState = new AuthState();
Expand All @@ -113,31 +101,6 @@ public boolean isOsmAuthorized() {
return getAuthState().isAuthorized();
}

public static OAuthConsumer getOSMAuthConsumer() {

OAuthConsumer consumer = null;

try {

consumer = new OkHttpOAuthConsumer("NQ4ucS4F0RpQO1byUQB5JA", Strings.GetOSM());


String osmAccessToken = PreferenceHelper.getInstance().getOSMAccessToken();
String osmAccessTokenSecret = PreferenceHelper.getInstance().getOSMAccessTokenSecret();

if (Strings.isNullOrEmpty(osmAccessToken) || Strings.isNullOrEmpty(osmAccessTokenSecret)) {
return consumer;
} else {
consumer.setTokenWithSecret(osmAccessToken, osmAccessTokenSecret);
}

} catch (Exception e) {
LOG.error("Error getting OAuth Consumer", e);
}

return consumer;
}

@Override
public void uploadFile(List<File> files) {
for (File f : files) {
Expand Down Expand Up @@ -165,7 +128,7 @@ public String getName() {
public void uploadFile(String fileName) {
File gpxFolder = new File(preferenceHelper.getGpsLoggerFolder());
final File chosenFile = new File(gpxFolder, fileName);
final OAuthConsumer consumer = getOSMAuthConsumer();

final String gpsTraceUrl = OSM_GPSTRACE_URL;


Expand All @@ -177,7 +140,7 @@ public void uploadFile(String fileName) {
jobManager.cancelJobsInBackground(new CancelResult.AsyncCancelCallback() {
@Override
public void onCancelled(CancelResult cancelResult) {
jobManager.addJobInBackground(new OSMJob( consumer, gpsTraceUrl, chosenFile, description, tags, visibility));
jobManager.addJobInBackground(new OSMJob(gpsTraceUrl, chosenFile, description, tags, visibility));
}
}, TagConstraint.ANY, OSMJob.getJobTag(chosenFile));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.util.Base64;

import androidx.activity.result.ActivityResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,6 @@
@RunWith(MockitoJUnitRunner.class)
public class OpenStreetMapManagerTest {

@Test
public void IsAvailable_WithValidValues_IsAvailable(){
PreferenceHelper pm = mock(PreferenceHelper.class);
OpenStreetMapManager osm = new OpenStreetMapManager(pm);
assertThat("Account and token indicate availability", osm.isAvailable(), is(false));

when(pm.getOSMAccessToken()).thenReturn("");
assertThat("Account and token indicate availability", osm.isAvailable(), is(false));

when(pm.getOSMAccessToken()).thenReturn("923487234");
assertThat("Account and token indicate availability", osm.isAvailable(), is(true));
}

@Test
public void IsAutosendAvailable_WhenUserChecked_IsAvailable(){
PreferenceHelper pm = mock(PreferenceHelper.class);
OpenStreetMapManager osm = new OpenStreetMapManager(pm);
when(pm.getOSMAccessToken()).thenReturn("923487234");

assertThat("Autosend available when user checked preference", osm.isAutoSendAvailable(), is(false));

when(pm.isOsmAutoSendEnabled()).thenReturn(true);
assertThat("Autosend available when user checked preference", osm.isAutoSendAvailable(), is(true));
}

@Test
public void Accept_OnlyGpxAllowed(){
PreferenceHelper pm = mock(PreferenceHelper.class);
Expand Down

0 comments on commit e35f64e

Please sign in to comment.