Android OAuth2 library, Simple O Auth is a simple android Library used to Sign in Google, Facebook. A library designed to use Oauth 2.0 easily.
Need some career advice or prepping for an Android developer interview? Hit me up on Topmate.io, and let's chat!
Simple OAuth Login! Super simple, super easy to use!
About this Library
Link: https://github.com/rohjk/SimpleOAuth
Min SDK: 16 (Android 4.1 Jelly Bean)
Owner: Roh JeongKeun (https://github.com/rohjk)
Language: Java
Quick Setup
1. Include Android OAuth2 Simple library
Using Gradle
Step 1. Add the JitPack repository to your build file.
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.rohjk:SimpleOAuth:1.2'
}
2. Usage
- In AndroidManifest.xml :
Nothing
- In Activity :
a. Set IDP Provider
set Google OAuth 2.0 ‘Web Client ID’, Facebook ‘App ID’
SimpleSession.setAuthProvider(IdpType.GOOGLE,"<OAuth 2.0 Web Client ID>");
SimpleSession.setAuthProvider(IdpType.FACEBOOK,"<App ID>");
b. Override onActivityResult
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
SimpleSession.onActivityResult(requestCode,resultCode,data);
}
C. Call Login API
IdpType idpType; // IdpType.GOOGLE or IdpType.FACEBOOK
SimpleSession.login(this, idpType, new SimpleAuthResultCallback<Void>() {
@Override
public void onResult(SimpleAuthResult<Void> result) {
if(result.isSuccess()){
//Success to Login!
}else{
//Fail to Login!
int errorCode = result.getErrorCode();
String errorMessage = result.getErrorMessaage();
}
}
});
D. Done! Super Simple
3. Others
A. Get Sign in Status
SimpleSession.isSignedIn(<Activity>);
B. Get Signed IDP Type
SimpleSession.getCurrentIdpType();
C. Get Access Token
SimpleSession.getAccessToken();
D. Get Email
SimpleSession.getEmail();
E. Logout
SimpleSession.logout();
3. dependencies
play-services-auth:16.0.1 , facebook-android-sdk:4.+
To know how to set up a Google Sign in Android Example using Firebase Auth, Click here to know more!
2 comments