GithubHelp home page GithubHelp logo

bhanditz / social-login Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rogalabs/social-login

0.0 2.0 0.0 173 KB

Very simple implementaion for social login on android

License: MIT License

Kotlin 66.49% Java 33.51%

social-login's Introduction

Social Login

Very simple implementaion for social login on android

AndroidArsenal

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

social-login's People

Contributors

oliveiradev avatar cleylsonsouza avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.