import java.io.IOException;
import org.average.whereami.ClientCredentials;
+import org.average.whereami.CredentialStore;
import android.app.Activity;
import android.os.Bundle;
ClientCredentials.CLIENT_SECRET,
code,
ClientCredentials.REDIRECT_URI).execute();
- storeTokens(accessTokenResponse);
+ CredentialStore credentialStore =
+ new CredentialStore(prefs);
+ credentialStore.write(accessTokenResponse);
finish();
//view.setVisibility(View.INVISIBLE);
//startActivity(new Intent(Authorize.this,
// WhereAmI.class));
} else if (url.indexOf("error=")!=-1) {
- clearTokens();
+ new CredentialStore(prefs).clear();
finish();
//view.setVisibility(View.INVISIBLE);
//startActivity(new Intent(Authorize.this,
ClientCredentials.REDIRECT_URI.length()+7,
url.length());
}
-
- private void storeTokens(AccessTokenResponse accessTokenResponse) {
- Log.w(TAG, "Storing tokens: " + accessTokenResponse);
- Editor editor = prefs.edit();
- editor.putString(ACCESS_TOKEN,
- accessTokenResponse.accessToken);
- editor.putLong( EXPIRES_IN,
- accessTokenResponse.expiresIn);
- editor.putString(REFRESH_TOKEN,
- accessTokenResponse.refreshToken);
- editor.putString(SCOPE,
- accessTokenResponse.scope);
- editor.commit();
- }
-
- private void clearTokens() {
- Log.w(TAG, "Clear tokens");
- Editor editor = prefs.edit();
- editor.remove(ACCESS_TOKEN);
- editor.remove(EXPIRES_IN);
- editor.remove(REFRESH_TOKEN);
- editor.remove(SCOPE);
- editor.commit();
- }
});
webview.loadUrl(authorizationUrl);