logout added
This commit is contained in:
parent
689ebf5b75
commit
33f933e89d
4 changed files with 61 additions and 26 deletions
|
@ -20,7 +20,7 @@ public class OsmOAuthAuthorizationClient {
|
||||||
OAuth1RequestToken requestToken;
|
OAuth1RequestToken requestToken;
|
||||||
OAuth1AccessToken accessToken;
|
OAuth1AccessToken accessToken;
|
||||||
|
|
||||||
public OsmOAuthAuthorizationClient(String key, String secret){
|
public OsmOAuthAuthorizationClient(String key, String secret) {
|
||||||
service = new ServiceBuilder(key)
|
service = new ServiceBuilder(key)
|
||||||
.apiSecret(secret)
|
.apiSecret(secret)
|
||||||
.callback("osmand-oauth://example.com/oauth")
|
.callback("osmand-oauth://example.com/oauth")
|
||||||
|
@ -53,9 +53,13 @@ public class OsmOAuthAuthorizationClient {
|
||||||
return service;
|
return service;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAccessToken(OAuth1AccessToken accessToken) { this.accessToken = accessToken; }
|
public void setAccessToken(OAuth1AccessToken accessToken) {
|
||||||
|
this.accessToken = accessToken;
|
||||||
public OAuth1AccessToken getAccessToken() { return this.accessToken; }
|
}
|
||||||
|
|
||||||
|
public OAuth1AccessToken getAccessToken() {
|
||||||
|
return this.accessToken;
|
||||||
|
}
|
||||||
|
|
||||||
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 {
|
||||||
|
@ -88,20 +92,6 @@ public class OsmOAuthAuthorizationClient {
|
||||||
return service.execute(req);
|
return service.execute(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Verb parseRequestMethod(String method) {
|
|
||||||
Verb m = Verb.GET;
|
|
||||||
if (method.equals("POST")) {
|
|
||||||
m = Verb.POST;
|
|
||||||
}
|
|
||||||
if (method.equals("PUT")) {
|
|
||||||
m = Verb.PUT;
|
|
||||||
}
|
|
||||||
if (method.equals("DELETE")) {
|
|
||||||
m = Verb.DELETE;
|
|
||||||
}
|
|
||||||
return m;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OAuth1RequestToken startOAuth() {
|
public OAuth1RequestToken startOAuth() {
|
||||||
try {
|
try {
|
||||||
requestToken = service.getRequestToken();
|
requestToken = service.getRequestToken();
|
||||||
|
@ -131,4 +121,18 @@ public class OsmOAuthAuthorizationClient {
|
||||||
public boolean isValidToken() {
|
public boolean isValidToken() {
|
||||||
return !(accessToken == null);
|
return !(accessToken == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Verb parseRequestMethod(String method) {
|
||||||
|
Verb m = Verb.GET;
|
||||||
|
if (method.equals("POST")) {
|
||||||
|
m = Verb.POST;
|
||||||
|
}
|
||||||
|
if (method.equals("PUT")) {
|
||||||
|
m = Verb.PUT;
|
||||||
|
}
|
||||||
|
if (method.equals("DELETE")) {
|
||||||
|
m = Verb.DELETE;
|
||||||
|
}
|
||||||
|
return m;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,12 @@
|
||||||
Thx - Hardy
|
Thx - Hardy
|
||||||
|
|
||||||
-->
|
-->
|
||||||
|
<string name="osm_edit_logout_success">Logout successful</string>
|
||||||
|
<string name="clear_osm_token">Clear OpenStreetMap OAuth token</string>
|
||||||
|
<string name="test_user_request_description">Test user request</string>
|
||||||
|
<string name="test_user_request">Retrieve current user info</string>
|
||||||
|
<string name="perform_oauth_authorization">Log in via OAuth</string>
|
||||||
|
<string name="perform_oauth_authorization_description">Perform an OAuth Login to use osmedit features</string>
|
||||||
<string name="sort_name_ascending">Name: A – Z</string>
|
<string name="sort_name_ascending">Name: A – Z</string>
|
||||||
<string name="sort_name_descending">Name: Z – A</string>
|
<string name="sort_name_descending">Name: Z – A</string>
|
||||||
<string name="sort_last_modified">Last modified</string>
|
<string name="sort_last_modified">Last modified</string>
|
||||||
|
|
|
@ -81,8 +81,8 @@ public class SettingsOsmEditingActivity extends SettingsBaseActivity {
|
||||||
prefOAuth.setKey("local_openstreetmap_token");
|
prefOAuth.setKey("local_openstreetmap_token");
|
||||||
|
|
||||||
final Preference prefTestUser = new Preference(this);
|
final Preference prefTestUser = new Preference(this);
|
||||||
prefTestUser.setTitle("Test user request");
|
prefTestUser.setTitle(R.string.test_user_request);
|
||||||
prefTestUser.setSummary("Test user request");
|
prefTestUser.setSummary(R.string.test_user_request_description);
|
||||||
prefTestUser.setKey("local_openstreetmap_token");
|
prefTestUser.setKey("local_openstreetmap_token");
|
||||||
prefTestUser.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
prefTestUser.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -92,8 +92,7 @@ public class SettingsOsmEditingActivity extends SettingsBaseActivity {
|
||||||
@Override
|
@Override
|
||||||
public void onCompleted(Response response) {
|
public void onCompleted(Response response) {
|
||||||
try {
|
try {
|
||||||
Toast.makeText(SettingsOsmEditingActivity.this,
|
Toast.makeText(SettingsOsmEditingActivity.this,response.getBody(),Toast.LENGTH_SHORT).show();
|
||||||
"DATA RETRIEVED: " + response.getBody().toString(),Toast.LENGTH_SHORT).show();
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -108,11 +107,27 @@ public class SettingsOsmEditingActivity extends SettingsBaseActivity {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
grp.addPreference(prefTestUser);
|
final Preference prefClearToken = new Preference(this);
|
||||||
|
prefClearToken.setTitle(R.string.shared_string_logoff);
|
||||||
|
prefClearToken.setSummary(R.string.clear_osm_token);
|
||||||
|
prefClearToken.setKey("local_openstreetmap_token");
|
||||||
|
prefClearToken.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
|
settings.USER_ACCESS_TOKEN.set("");
|
||||||
|
settings.USER_ACCESS_TOKEN_SECRET.set("");
|
||||||
|
client.resetToken();
|
||||||
|
Toast.makeText(SettingsOsmEditingActivity.this, R.string.osm_edit_logout_success, Toast.LENGTH_SHORT).show();
|
||||||
|
finish();
|
||||||
|
startActivity(getIntent());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
grp.addPreference(prefClearToken);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
prefOAuth.setTitle(R.string.osb_author_dialog_password);
|
prefOAuth.setTitle(R.string.perform_oauth_authorization);
|
||||||
prefOAuth.setSummary(R.string.osb_author_dialog_password);
|
prefOAuth.setSummary(R.string.perform_oauth_authorization_description);
|
||||||
prefOAuth.setKey("local_openstreetmap_token");
|
prefOAuth.setKey("local_openstreetmap_token");
|
||||||
prefOAuth.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
prefOAuth.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -193,6 +208,8 @@ public class SettingsOsmEditingActivity extends SettingsBaseActivity {
|
||||||
if (uri != null && uri.toString().startsWith("osmand-oauth")) {
|
if (uri != null && uri.toString().startsWith("osmand-oauth")) {
|
||||||
String oauthVerifier = uri.getQueryParameter("oauth_verifier");
|
String oauthVerifier = uri.getQueryParameter("oauth_verifier");
|
||||||
client.authorize(oauthVerifier);
|
client.authorize(oauthVerifier);
|
||||||
|
finish();
|
||||||
|
startActivity(getIntent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -34,10 +34,18 @@ public class OsmOAuthAuthorizationAdapter {
|
||||||
return client.isValidToken();
|
return client.isValidToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void resetToken() {
|
||||||
|
client.setAccessToken(null);
|
||||||
|
}
|
||||||
|
|
||||||
public void restoreToken() {
|
public void restoreToken() {
|
||||||
String token = application.getSettings().USER_ACCESS_TOKEN.get();
|
String token = application.getSettings().USER_ACCESS_TOKEN.get();
|
||||||
String tokenSecret = application.getSettings().USER_ACCESS_TOKEN_SECRET.get();
|
String tokenSecret = application.getSettings().USER_ACCESS_TOKEN_SECRET.get();
|
||||||
client.setAccessToken(new OAuth1AccessToken(token, tokenSecret));
|
if (!(token.isEmpty() || tokenSecret.isEmpty())) {
|
||||||
|
client.setAccessToken(new OAuth1AccessToken(token, tokenSecret));
|
||||||
|
} else {
|
||||||
|
client.setAccessToken(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startOAuth(ViewGroup rootLayout) {
|
public void startOAuth(ViewGroup rootLayout) {
|
||||||
|
|
Loading…
Reference in a new issue