Git Product home page Git Product logo

githubloginsdk's Introduction

Github Login SDK for Android (LightWeight)

Motivation BTS: :octocat:

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)

Installation

Project Root Level Gradle (Below 7.0)

allprojects {
	repositories {
		maven { url 'https://jitpack.io' }
	}
}

OR

settings.gradle Level Gradle (Below 7.0)

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven { url "https://jitpack.io" }
    }
}

App Level Gradle

dependencies {
	 implementation 'com.github.debojyoti452:GithubLoginSDK:${version}'
}

AuthResult Model

  • 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

Integrations

  • 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 Available (Constants)

       - Scopes.PUBLIC_REPO
       - Scopes.USER_EMAIL
       - Scopes.REPO
       - Scopes.GIST
  • Response Listener

      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()
       }
  • Setting Scopes - [Accepts Arrays of Strings]

-- Kotlin Code

       setScopes(listOf(Scopes.PUBLIC_REPO, Scopes.USER_EMAIL)) 

-- JAVA Code

       setScopes(Arrays.asList(Scopes.PUBLIC_REPO, Scopes.USER_EMAIL))
  • Setting Custom Redirect URL (Optional Builder Method)

       setRedirectUrl("WILL ACCEPT ONLY THE URL USED IN YOUR GITHUB OAUTH APP CREATION")
  • Authorization Call (Mandatory)

    It will open the external browser for github oauth authorization.
       override fun onClick(id: Int?) {
           githubAuth.auth()
       }
  • Deep Link Observer (Mandatory)

    It will check when we will return the ==Auth Code== after ==Github Web OAuth== Successfully done.
       override fun onResume() {
           super.onResume()
           githubAuth.onDeepLinkInitializer()
       }
  • Deep Link Manifest (Mandatory)

   <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>

Demo Links

IMPORTANT NOTES

==(Feel free to raise a PR)==

Open Source Plugins used

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]

githubloginsdk's People

Contributors

debojyoti452 avatar

Stargazers

 avatar Roman avatar hexpee avatar Abubakar Abdusalam Olajide avatar Mahoro Pierratono Costa avatar David Okonji 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.