Social Login

Additional

Language
Kotlin
Version
1.3.0 (Jun 2, 2017)
Created
Jul 18, 2016
Updated
Jun 1, 2017 (Retired)
Owner
Roga Labs (RogaLabs)
Contributors
Felipe Oliveira (oliveiradev)
Cleylson Freire (cleylsonsouza)
2
Activity
Badge
Generate
Download
Source code

Social Login

Very simple implementaion for social login on android

Install

In build.gradle root level add that:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        ...
        classpath 'com.google.gms:google-services:3.0.0'
        ...
    }
}


allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

In build.gradle app level add that:

apply plugin: 'com.google.gms.google-services'
...

dependencies {
    ...
    compile 'com.github.RogaLabs:social-login:[latest-version]'
    ...
}

Usage

Is required

In Google login

Register an app on Google Developers console after that, you should ensure which the file google-services.json is inside app module

In Facebook login

Create an app on Facebook Developers

after

add in your string.xml:

<string name="facebook_app_id">1320760547953881</string>

and

<application android:label="@string/app_name" ...>
    ...
    <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
    ...
</application>

Init the Social Login on your application:

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        LoginApplication.startSocialLogin(this);
    }
}

In your Login Activity you should extends one specific class:

public class YourLoginActivity extends LoginView 

Login with google:

loginWithGoogle(new Callback() {
                    @Override
                    public void onSuccess(SocialUser socialUser) {
                        buildProfileDialog(socialUser);
                    }

                    @Override
                    public void onError(Throwable throwable) {
                        throwable.printStackTrace();
                    }
                });

Login with Facebook:

loginWithFacebook(new Callback() {
                    @Override
                    public void onSuccess(SocialUser socialUser) {
                        buildProfileDialog(socialUser);
                    }

                    @Override
                    public void onError(Throwable throwable) {
                        throwable.printStackTrace();
                    }
                });

// or setting your desired permissions...
String[] permissions = {"public_profile", "email"};
loginWithFacebook(new Callback() {
                    @Override
                    public void onSuccess(SocialUser socialUser) {
                        buildProfileDialog(socialUser);
                    }

                    @Override
                    public void onError(Throwable throwable) {
                        throwable.printStackTrace();
                    }
                }, Arrays.asList(permissions));

Also, you can make a request with your own endpoint and params:

loginWithCommonCredentials(yourEndpoint, jsonParams, new CommonCallback() {
                @Override
                public void onSuccess(@NotNull JSONObject success) {
                    Log.i(TAG, "onSuccess: " + success);
                }

                @Override
                public void onError(@NotNull ResponseHandler.ErrorHandler error) {
                    Log.e(TAG, "onError: " + error.getCode() + " - " + error.getMessage());
                }
            });

Sample

Sample

License

License