Reason Behind Building SDK :- As all we know that Github SDK is already available in Firebase Auth SDK but it has limitation like using custom redirect url can't be used or setting scopes is hard. Firebase Auth comes with a lot of extras like analytics, etc.. So I need a solution which simply just do the auth and return me token. So as usual was looking for an efficient SDK that can help me with this simple Auth, but TBH not a single solution I able to find, all were complex and head scratching. Finally I created my own and made it open source.
- 🔥 Light Weight SDK (No Extra Libs used)
- 😎 Works with Firebase Authentication Redirect Url also. (No Extra Firebase SDK Required)
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url "https://jitpack.io" }
}
}
dependencies {
implementation 'com.github.debojyoti452:GithubLoginSDK:${version}'
}
- Response will return this Params as ==AuthResult== model
val scope: String? = null,
val accessToken: String? = null,
val tokenType: String? = null,
val errorDescription: String? = null,
val error: String? = null
- Initiate Github Auth SDK in Kotlin
private val githubAuth: GithubAuth by lazy {
GithubAuth.Builder(GIT_CLIENT_ID, GIT_CLIENT_SECRET)
.setActivity(this)
.setOnSuccess {
// Success Response Fetched.
Toast.makeText(this, it.toString(), Toast.LENGTH_SHORT).show()
}
.setOnFailed {
// Exceptions Catched.
Toast.makeText(this, it.message, Toast.LENGTH_SHORT).show()
}
.setScopes(listOf(Scopes.PUBLIC_REPO, Scopes.USER_EMAIL))
.build()
}
- Initiate Github Auth SDK in JAVA
private GithubAuth githubAuth = new GithubAuth.Builder(GIT_CLIENT_ID, GIT_CLIENT_SECRET)
.setActivity(this)
.setOnSuccess(response -> {
Toast.makeText(JavaActivity.this, "Success", Toast.LENGTH_SHORT).show();
return null;
})
.setOnFailed(error -> {
Toast.makeText(JavaActivity.this, "Failed", Toast.LENGTH_SHORT).show();
return null;
})
.setScopes(Arrays.asList(Scopes.PUBLIC_REPO, Scopes.USER_EMAIL))
.build();
- Scopes.PUBLIC_REPO
- Scopes.USER_EMAIL
- Scopes.REPO
- Scopes.GIST
setOnSuccess {
// Success Response Fetched.
Toast.makeText(this, it.toString(), Toast.LENGTH_SHORT).show()
}
setOnFailed {
// Exceptions Catched.
Toast.makeText(this, it.message, Toast.LENGTH_SHORT).show()
}
-- Kotlin Code
setScopes(listOf(Scopes.PUBLIC_REPO, Scopes.USER_EMAIL))
-- JAVA Code
setScopes(Arrays.asList(Scopes.PUBLIC_REPO, Scopes.USER_EMAIL))
setRedirectUrl("WILL ACCEPT ONLY THE URL USED IN YOUR GITHUB OAUTH APP CREATION")
- It will open the external browser for github oauth authorization.
override fun onClick(id: Int?) {
githubAuth.auth()
}
- It will check when we will return the ==Auth Code== after ==Github Web OAuth== Successfully done.
override fun onResume() {
super.onResume()
githubAuth.onDeepLinkInitializer()
}
<activity
android:name="Activity Name"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
// example: <data android:host="***.firebaseapp.com" />
<data android:host="Redirect URL" />
</intent-filter>
</activity>
- Success -> https://youtu.be/sYPK4LWFHio
- Failed -> https://youtu.be/2_73Z_LEW14
Library | README |
---|---|
HttpUrlConnection | [https://developer.android.com/reference/java/net/HttpURLConnection] |
GSON Serializer | [https://github.com/google/gson] |
Android STD Libs | [https://developer.android.com/kotlin/first] |