EasyLogin


Source link: https://github.com/maksim88/EasyLogin

EasyLogin

Easy Login in your app with different social networks. Currently supported:

  • Facebook
  • Google Plus
  • Twitter

Global Configuration

To be able to use one of the social network connections you need to create an EasyLogin instance:

EasyLogin.initialize();
 EasyLogin easyLogin = EasyLogin.getInstance();
 

Also make sure to call through to EasyLogin in onActivityResult() of your Activity:

@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) {

super.onActivityResult(requestCode, resultCode, data);

easyLogin.onActivityResult(requestCode, resultCode, data);
 
}
 

Afterwards you can connect to the social networks one by one.

Facebook Connection

To connect to facebook you need to do the following:

  • First of all you need to init a list of permissions you want to take:
    List<String> fbScope = Arrays.asList("public_profile", "email");
     
  • Add the facebook social network:
    easyLogin.addSocialNetwork(new FacebookNetwork(this, fbScope));
     
  • Add the Facebook LoginButton and the listeners:
    facebook = (FacebookNetwork) easyLogin.getSocialNetwork(SocialNetwork.Network.FACEBOOK);
      LoginButton loginButton = (LoginButton) findViewById(R.id.facebook_login_button);
     // Call this method if you are using the LoginButton provided by facebook // It can handle its own state facebook.requestLogin(loginButton, this);
     
  • In the next step you will get an onSuccess() or onError() callback. The easiest solution is to implement the OnLoginCompleteListenerin your activity and handle all the connections there.

You also need to make sure to add the Facebook ApplicationId in your manifest:

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

If an email permission is requested, the library also does a /me request on the facebook graph api to try to fetch the email.

Note that it is still not guaranteed that you will get an email because the user might not have a valid / verified email or signed up with a telephone number. So I would advise to use the userId for figuring out the user identity.

Twitter Connection

One gotcha of using the Twitter Social connection is to create the TwitterNetwork before calling to setContentView() as Twitter would complain otherwise.

// Initialization needs to happen before setContentView() if using the LoginButton! easyLogin.addSocialNetwork(new TwitterNetwork(this, twitterKey, twitterSecret));
  setContentView(R.layout.activity_main);
  twitter = (TwitterNetwork) easyLogin.getSocialNetwork(SocialNetwork.Network.TWITTER);
 twitterButton = (TwitterLoginButton) findViewById(R.id.twitter_login_button);
 twitter.requestLogin(twitterButton, this);
 

If you also want to request an email from the Twitter use, use twitter.setAdditionalEmailRequest(true); Make sure that your app has the 'Request email addresses from users' checkbox checked in the Twitter app permission settings.

Note that it is still not guaranteed that you will get an email because the user might have signed up with a telephone number. So I would advise to use the userId for figuring out the user identity.

Google Plus Connection

easyLogin.addSocialNetwork(new GooglePlusNetwork(this));
 gPlusNetwork = (GooglePlusNetwork) easyLogin.getSocialNetwork(SocialNetwork.Network.GOOGLE_PLUS);
  gPlusButton = (SignInButton) findViewById(R.id.gplus_sign_in_button);
 gPlusButton.setOnClickListener(new View.OnClickListener() {

  @Override
  public void onClick(View v) {

if (!gPlusNetwork.isConnected()) {

 gPlusNetwork.requestLogin(MainActivity.this);

}

  
}
 
}
);
 

You can pass a reference to the SignInButton to the SocialNetwork by calling gPlusNetwork.setSignInButton(gPlusButton); . This will make sure to disable and enable the button on connection state changes. Unfortunately the state is not handled automatically inside the Button like the facebook button does.

As the state is not handled by the SignInButton you may need to call silentSignIn() in your onStart() to be logged in again. You will get a callback. For more info check the sample project. If you call silentSignIn() make sure to set a listener before.

You also need to include a valid google-services.json file in your project to be able to use G+: For more information you can consult the official docs.

Callbacks

 public class MainActivity extends AppCompatActivity implements OnLoginCompleteListener {

 [...]
 @Override  public void onLoginSuccess(SocialNetwork.Network network) {

// You can check the network by e.g.: if (network == SocialNetwork.Network.FACEBOOK)

 AccessToken token = network.getAccessToken();

Log.d("MAIN", "Login successful: " + token.getToken());
  
}

 @Override  public void onError(SocialNetwork.Network socialNetwork, String errorMessage) {

Toast.makeText(getApplicationContext(), errorMessage, Toast.LENGTH_SHORT).show();
  
}
 

Download

The library is available through jcenter().

After that you can easily include the library in your app build.gradle:

dependencies {

 implementation 'com.maksim88:EasyLogin:{
latest-version
}
'  
}

The builds are also available via jitpack.io.

License

Licensed under the MIT license. See LICENSE.

Resources

Just another Kotlin sample application.

This simple demo app supplys some examples about basic controls through smart bulb's protocols. And you can customize your own apps using following protocols.

Enjoy a calendar that looks like the Contribution View in your GitHub profile.

Interesting concept of products incrementation inspired this Design.

A Kotlin android sample with rxjava, okhttp and retrofit.

SeekbarWithIntervals is an extension of the SeekBar with labels.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes