Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed bug where logout operation crashed when user is already logged in #38

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 21
buildToolsVersion "21.1.1"

defaultConfig {
minSdkVersion 11
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
java.srcDirs = ['socialauth-android/src']
res.srcDirs = ['socialauth-android/res']
manifest.srcFile 'socialauth-android/AndroidManifest.xml'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.2'
compile files('socialauth-android/libs/socialauth-4.4.jar')
}
91 changes: 91 additions & 0 deletions socialauth-android.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
<option name="GRADLE_PROJECT_PATH" value=":socialauth-android" />
</configuration>
</facet>
<facet type="android" name="Android">
<configuration>
<option name="SELECTED_BUILD_VARIANT" value="debug" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
<option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
<option name="TEST_SOURCE_GEN_TASK_NAME" value="generateDebugTestSources" />
<option name="ALLOW_USER_CONFIGURATION" value="false" />
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/res" />
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
<option name="LIBRARY_PROJECT" value="true" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/test/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/test/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="support-annotations-21.0.2" level="project" />
<orderEntry type="library" exported="" name="support-v4-21.0.2" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-21.0.2" level="project" />
<orderEntry type="library" exported="" name="socialauth-4.4" level="project" />
</component>
</module>

Binary file removed socialauth-android/libs/socialauth-4.4.jar
Binary file not shown.
Binary file added socialauth-android/libs/socialauth-4.7.jar
Binary file not shown.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.brickred.socialauth.android;

interface iOnProviderRestoreListener{
public void onConnected();
public void onError(SocialAuthError e);
public void onNotAvailable();
}

public abstract class OnProviderConnectedListener implements iOnProviderRestoreListener{

public abstract void onConnected();

public abstract void onError(SocialAuthError e);

public abstract void onNotAvailable();
}
Empty file.
Empty file.
134 changes: 133 additions & 1 deletion socialauth-android/src/org/brickred/socialauth/android/SocialAuthAdapter.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,130 @@ public void run() {

new Thread(runnable).start();
}

public void connect(final Context ctx, final Provider provider, final OnProviderConnectedListener restoreListener ){

currentProvider = provider;
Log.d("SocialAuthAdapter", "Selected provider is " + currentProvider);

// Initialize socialauth manager if not already done
if (socialAuthManager != null) {
// If SocialAuthManager is not null and contains Provider Id, send
// response to listener
if (socialAuthManager.getConnectedProvidersIds().contains(currentProvider.toString())) {
Log.d("SocialAuthAdapter", "Provider already connected");
Bundle bundle = new Bundle();
bundle.putString(SocialAuthAdapter.PROVIDER, currentProvider.toString());
restoreListener.onConnected();
}
// If SocialAuthManager is not null and not contains Provider ID connect provider
else {
Log.e("no","not yet implemented");
connectProvider(ctx, provider,restoreListener);
}

}
// If SocialAuthManager is null, create new SocialAuthManager , load configuration and connect provider
else {
Log.d("SocialAuthAdapter", "Loading keys and secrets from configuration");

socialAuthManager = new SocialAuthManager();
try {
loadConfig(ctx);

} catch (Exception e) {
Log.d("SocialAuthAdapter", "Could not load configuration");
}
connectProvider(ctx, provider,restoreListener);
}

// If network not available show message
if (!Util.isNetworkAvailable(ctx)) {
restoreListener.onError(new SocialAuthError("Please check your Internet connection", new Exception("")));
return;
}
}

private void connectProvider(final Context ctx, final Provider provider, final OnProviderConnectedListener restoreListener ){
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(ctx);

if (pref.contains(provider.toString() + " key")) {
tokenMap = new HashMap<String, Object>();

for (Map.Entry entry : pref.getAll().entrySet())
tokenMap.put(entry.getKey().toString(), entry.getValue());

// If Access Token is available , connect using Access Token
try {
HashMap<String, Object> attrMap = null;
attrMap = new HashMap<String, Object>();

String key = (String) tokenMap.get(provider.toString() + " key");
String secret = (String) tokenMap.get(provider.toString() + " secret");
String providerid = (String) tokenMap.get(provider.toString() + " providerid");

String temp = provider.toString() + "attribute";
for (String attr : tokenMap.keySet()) {
System.out.println("Attr " + attr);

if (attr.startsWith(temp)) {
int startLocation = attr.indexOf(temp) + temp.length() + 1;
attrMap.put(attr.substring(startLocation), tokenMap.get(attr));
}

}

for (Map.Entry entry : attrMap.entrySet()) {
System.out.println(entry.getKey() + ", " + entry.getValue());
}

// create new AccessGrant Object
final AccessGrant accessGrant = new AccessGrant(key, secret);
accessGrant.setProviderId(providerid);
accessGrant.setAttributes(attrMap);

Log.d("SocialAuthAdapter", "Loading from AccessToken "+providerid+"--"+attrMap+"---"+key+"---"+secret);

AsyncTask<Void, Void, Exception> task = new AsyncTask<Void, Void, Exception>()
{
@Override
protected Exception doInBackground(Void... params) {
try {
// connect manager with accessGrant
socialAuthManager.connect(accessGrant);

// To check validity of Access Token
getCurrentProvider().getUserProfile().getValidatedId();
return null;
} catch (Exception e) {
return e;
}
}

@Override
protected void onPostExecute(Exception result) {
super.onPostExecute(result);

if (result instanceof Exception){
restoreListener.onError(new SocialAuthError("Token Error", result));
return;
}
restoreListener.onConnected();
}

};

task.execute();

} catch (Exception e) {
restoreListener.onError(new SocialAuthError("Restore Provider Error", e));
}
}
else {
restoreListener.onNotAvailable();
}
}

/**
* Internal method to connect provider. The method check for access token If
* available it connects manager with AccessGrant else create new manager
Expand All @@ -670,7 +793,7 @@ public void run() {
*/

private void connectProvider(final Context ctx, final Provider provider) {

SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(ctx);

if (pref.contains(provider.toString() + " key")) {
Expand Down Expand Up @@ -794,6 +917,15 @@ public boolean signOut(Context ctx, String providerName) {

if (providerName != null) {

if (socialAuthManager == null) {
socialAuthManager = new SocialAuthManager();
try {
loadConfig(ctx);
} catch (Exception e) {
Log.d("SocialAuthAdapter", "Could not load configuration");
}
}

if (socialAuthManager.getConnectedProvidersIds().contains(providerName))
socialAuthManager.disconnectProvider(providerName);

Expand Down
Empty file.
Empty file.
Empty file.
Empty file.