Code Monkey home page Code Monkey logo

github-oauth's Introduction

github-oauth

Simple library to integrate Github authentication to android app using OAuth.

Installation

compile 'com.github.geniushkg:oauthLibGithub:1.0.2'

Add to manifest

<uses-permission android:name="android.permission.INTERNET"/>

and activity declaration:

<activity android:name="com.hardikgoswami.oauthLibGithub.OauthActivity"/>

Github Auth Flow

Initialise new Auth instance with credentials

  1. Client id : you get it from your github profile by creating new app.
    Follow this tutorial
  2. Client Secret : same as above.
  3. NextActivity : Thats your activity you want launch after user gets authenticated.
  4. Context : you can use context variable from place where initiate the process that is getActivity() from fragment or getapplicationcontext() from activity.

Sample initialization :

    // Github ID and secret are generated in github.com profile
	// package name is your packagename
	// next activity is your activity with full name including package 
	// you can use debug(true) for logcat , use TAG = "github-oauth"
	
	// scope can also be defined (optional)

	loginButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
             GithubOauth
                    .Builder()
                    .withClientId(GITHUB_ID)
                    .withClientSecret(GITHUB_SECRET)
                    .withContext(context)
                    .packageName("com.hardikgoswami.github_oauth_lib")
                    .nextActivity("com.hardikgoswami.github_oauth_lib.UserActivity")
                    .debug(true)
                     .execute();
        }
    });

Note : Callback url can be as per your requirement or make it http://localhost while registering new Oauth application.

Note 2: Available scopes are presented on the table below

Scope Description
repo:status Access commit status
repo_deployment Access deployment status
public_repo Access public repositories
admin:org Full control of orgs and teams
write:org Read and write org and team membership
read:org Read org and team membership
admin:public_key Full control of user public keys
write:public_key Write user public keys
read:public_key Read user public keys
admin:repo_hook Full control of repository hooks
write:repo_hook Write repository hooks
read:repo_hook Read repository hooks
admin:org_hook Full control of organization hooks
gist Create gists
notifications Access notifications
user Update all user data
read:user Read all user profile data
user:email Access user email addresses (read-only)
user:follow Follow and unfollow users
delete_repo Delete repositories
admin:gpg_key Full control of user gpg keys (Developer Preview)
write:gpg_key Write user gpg keys
read:gpg_key Read user gpg keys

Execute will launch a new activity with webview and user token will be stored in shared preference

shared preference name : github_prefs

String in preference : oauth_token

	// Sample to read logged in user oauth token
    public static final String PREFERENCE = "github_prefs";
	sharedPreferences = getSharedPreferences(PREFERENCE, 0);
    String oauthToken = sharedPreferences.getString("oauth_token", null);
    Log.d(TAG, "oauth token for github loged in user is :" + oauthToken);

if you found any bug you can create issue or want to contribute feel free to PR.

Contributor's


darvid7 jdamacena

For new programmer's -> do not hesitate, please send PR we both will learn something new. :)

twitter - linkedIn - blog

github-oauth's People

Contributors

darvid7 avatar gammmaf avatar geniushkg avatar jdamacena avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

github-oauth's Issues

Doesn't work if client has got two-factor authentication

Hey,
I'm having an issue with two-factor authorization,

Here is stacktrace:

FATAL EXCEPTION: main
Process: fogelao.com.github.gitauthtest, PID: 14878
java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
at com.hardikgoswami.oauthLibGithub.OauthActivity$1.shouldOverrideUrlLoading(OauthActivity.java:87)
at com.android.webview.chromium.WebViewContentsClientAdapter.shouldOverrideUrlLoading(WebViewContentsClientAdapter.java:356)
at org.chromium.android_webview.AwContentsClient.shouldIgnoreNavigation(AwContentsClient.java:168)
at org.chromium.android_webview.AwContentsClientBridge.shouldOverrideUrlLoading(AwContentsClientBridge.java:269)
at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:41)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5527)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)

Hope you will fix it, Thanks!

Scope list could be an enum

Hello, would be great if the available scopes came in the form of an enum, and also, if they were listed on the README file (I'll make a pull request with it soon).

Disabled authorize button on Android.

Hey,
I'm having an issue with authorization, I've checked my client_id and client_secret and am sure they are correct in my app.

In android (simulator and on my device) when I try to authenticate the authorize button is disabled.
18765257_758923900934955_1860996768_o

Works ok when I copy and paste the logged out link (below) into a web browser.
https://github.com/login/oauth/authorize?client_id=MY_CLIENT_ID&scope=user%2Cpublic_repo

screen shot 2017-05-28 at 5 49 12 pm

Im getting this as my response: {"error":"bad_verification_code","error_description":"The code passed is incorrect or expired.","error_uri":"https://developer.github.com/v3/oauth/#bad-verification-code"}.

Any ideas would be great,
Thanks!

Bad verification code?

I cannot authorize users through the web flow because the API returns this json:

response is:{"error":"bad_verification_code","error_description":"The code passed is incorrect or expired.","error_uri":"https://developer.github.com/v3/oauth/#bad-verification-code"}

I called the library like this (in Kotlin):

val githubOauth: GithubOauth = GithubOauth.Builder()
githubOauth.scopeList = arrayListOf("repo", "gist", "user")
githubOauth
.withClientId("...")
.withClientSecret("...")
.withContext(this)
.packageName("giuliolodi.gitnav")
.nextActivity("giuliolodi.gitnav.EventActivity")
.debug(true)
.execute()

The intent to OauthActivity seems correct, but after logging through the webview, the bottom Authorize User button isn't clickable and the spinner is spinning indefinitely.

Is it parsing the URL incorrectly?

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.