{"id":20774153,"url":"https://github.com/pchmn/rxsocialauth","last_synced_at":"2025-04-30T15:17:52.494Z","repository":{"id":117650893,"uuid":"80568725","full_name":"pchmn/RxSocialAuth","owner":"pchmn","description":"Android RxJava library for Social auth (Google, Facebook) and Smart Lock For Passwords","archived":false,"fork":false,"pushed_at":"2018-04-28T15:25:34.000Z","size":184,"stargazers_count":52,"open_issues_count":2,"forks_count":8,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-30T15:17:45.726Z","etag":null,"topics":["android-rxjava-library","facebook-login","google-sign","oauth","rxjava","smart-lock"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pchmn.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-01-31T22:26:05.000Z","updated_at":"2024-01-19T02:56:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"426d69c4-2ddd-48a0-94d1-5516e97e6dfb","html_url":"https://github.com/pchmn/RxSocialAuth","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pchmn%2FRxSocialAuth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pchmn%2FRxSocialAuth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pchmn%2FRxSocialAuth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pchmn%2FRxSocialAuth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pchmn","download_url":"https://codeload.github.com/pchmn/RxSocialAuth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251729735,"owners_count":21634281,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android-rxjava-library","facebook-login","google-sign","oauth","rxjava","smart-lock"],"created_at":"2024-11-17T12:28:33.174Z","updated_at":"2025-04-30T15:17:52.487Z","avatar_url":"https://github.com/pchmn.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RxSocialAuth\nAndroid RxJava library for Social auth (Google, Facebook) and Smart Lock For Passwords\n\n[![Release](https://jitpack.io/v/pchmn/RxSocialAuth.svg)](https://jitpack.io/#pchmn/RxSocialAuth)\n\n## Setup\nTo use this library your `minSdkVersion` must be \u003e= 15.\n\nIn your project level build.gradle :\n\n```java\nallprojects {\n    repositories {\n        ...\n        maven { url \"https://jitpack.io\" }\n    }\n}\n```\n\nIn your app level build.gradle :\n\n```java\ndependencies {\n    compile 'com.github.pchmn:RxSocialAuth:2.0.1-beta'\n}\n```\n\n## Usage\n\n### Getting started\n\nIn order to use this library with Google Sign-In and Facebook Login, you need to prepare your project.\n\n#### Google Sign-In\nFollow the official guide : https://developers.google.com/identity/sign-in/android/start-integrating\n\nIn short : \n* Put your `google-services.json` into the `/app` directory of your project\n* Add the dependency `classpath 'com.google.gms:google-services:3.0.0'`  to your project-level `build.gradle`\n* Add the plugin `apply plugin: 'com.google.gms.google-services'` at the end of your app-level `build.gradle`\n* Add the dependency `compile 'com.google.android.gms:play-services-auth:10.0.1'`  to your app-level `build.gradle`\n\n#### Facebook Login\n* Create an app ID on the facebook developer website : https://developers.facebook.com/ and activate Facebook Login on the console administration.\n* Add your facebook app ID in the strings.xml (or keys.xml) of your project like this : \n```java\n\u003cstring name=\"facebook_app_id\"\u003eyou_app_id\u003c/string\u003e\n```\n* Modify your Manifest.xml like this : \n```java\n\u003capplication android:label=\"@string/app_name\" ...\u003e\n    ...\n    \u003cmeta-data\n            android:name=\"com.facebook.sdk.ApplicationId\"\n            android:value=\"@string/facebook_app_id\" /\u003e\n    ...\n\u003c/application\u003e\n```\n* You don't have to add the facebook SDK in your project, it is already included in this library\n\nIf you have trouble when trying to authenticate users, maybe you have to add the users you're trying to authenticate in your test users. See http://stackoverflow.com/questions/41861564/server-error-code-1675030-message-error-performing-query\n\n\n### Shared classes\n\n#### RxAccount\nThis class represents a social account and has these methods :\n* `String getProvider()`\n* `String getId()`\n* `String getAccessToken()`\n* `String getEmail()`\n* `String getFirstname()`\n* `String getLastname()`\n* `String getDisplayName()`\n* `Uri getPhotoUri()`\n\nThese methods can return a null object according to the permissions you asked or didn't ask when you signed in the user.\n\n#### RxStatus\nThis class represents the status of a request and has these methods : \n* `int getStatusCode()`\n* `String getMessage()`\n* `boolean isSuccess()`\n* `boolean isCanceled()`\n\n\n### Google Sign-In\nCreate a `RxGoogleAuth` object using the `RxGoogleAuth.Builder` builder.\n```java\n// build RxGoogleAuth object\n// 'this' represents a FragmentActivity\nRxGoogleAuth rxGoogleAuth = new RxGoogleAuth.Builder(this)\n        .requestIdToken(getString(R.string.oauth_google_key))\n        .requestEmail()\n        .requestProfile()\n        .disableAutoSignIn()\n        .enableSmartLock(true)\n        .build();\n```\nYou can configure the builder with these methods : \n* `requestEmail()` : Request the email \n* `requestProfile()` : Request the profile (mandatory to get the profile picture) \n* `requestIdToken(String clientId)` : Request an id token for authenticated users (mandatory to get the profile picture) \n* `disableAutoSignIn()` : Clear the account previously selected by the user, so the user will have to pick an account\n* `enableSmartLock(boolean enable)` : Enable or disable Smart Lock For Passwords. If enabled, it will save automatically the credential in Smart Lock For Passwords\n\n\n#### Sign in and silent sign in\n`signIn()` and `silentSignIn(Credential credential)` methods return an `Observable\u003cRxAccount\u003e`.\n\nI think I found a bug in the Google Sign-In API with the [`silentSignIn()`](https://developers.google.com/android/reference/com/google/android/gms/auth/api/signin/GoogleSignInApi.html#silentSignIn(com.google.android.gms.common.api.GoogleApiClient)) method. If the user you try to silent sign in doesn't have a Google+ account, no matter if you set the [`requestProfile()`](https://developers.google.com/android/reference/com/google/android/gms/auth/api/signin/GoogleSignInOptions.Builder.html#requestProfile()) options, you won't have his profile.\n```java\n// sign in\nrxGoogleAuth.signIn()\n        .subscribe(rxAccount -\u003e {\n            // user is signed in\n            // use the rxAccount object as you want\n            Log.d(TAG, \"name: \" + rxAccount.getDisplayName());\n            Log.d(TAG, \"email: \" + rxAccount.getEmail());\n            \n        }, throwable -\u003e {\n            Log.e(TAG, throwable.getMessage());\n        });\n\n\n// silent sign in\n// you have to pass a credential object in order to silent sign in\n// if it fails the credential will be deleted from smart lock for passwords\nrxGoogleAuth.silentSignIn(Credential credential)\n        .subscribe(rxAccount -\u003e {\n            // user is signed in\n            // use the rxAccount object as you want\n            Log.d(TAG, \"name: \" + rxAccount.getDisplayName());\n            Log.d(TAG, \"email: \" + rxAccount.getEmail());\n            \n        }, throwable -\u003e {\n            Log.e(TAG, throwable.getMessage());\n        });\n```\n\n#### Sign out and revoke access\n`signOut()` and `revokeAccess()` methods return an `Observable\u003cRxStatus\u003e`.\n```java\n// sign out\nrxGoogleAuth.signOut()\n        .subscribe(rxStatus -\u003e {\n            if(rxStatus.isSuccess()) {\n                // user is signed out\n            }\n            \n        }, throwable -\u003e {\n            Log.e(TAG, throwable.getMessage());\n        });\n       \n       \n// revoke access\nrxGoogleAuth.revokeAccess()\n        .subscribe(rxStatus -\u003e {\n            if(rxStatus.isSuccess()) {\n                // access is revoked\n            }\n            \n        }, throwable -\u003e {\n            Log.e(TAG, throwable.getMessage());\n        }); \n```\n\n\n### Facebook Login\nCreate a `RxFacebookAuth` object using the `RxFacebookAuth.Builder` builder.\n```java\n// build RxFacebookAuth object\n// 'this' represents a FragmentActivity\nRxFacebookAuth rxFacebookAuth = new RxFacebookAuth.Builder(this)\n        .enableSmartLock(true)\n        .requestEmail()\n        .requestProfile()\n        .requestPhotoSize(200, 200)\n        .build();\n```\nYou can configure the builder with these methods : \n* `requestEmail()` : Request the email \n* `requestProfile()` : Request the profile (mandatory to get the profile picture) \n* `requestPhotoSize(int width, int height)` : Request a specific photo size, cause request profile\n* `enableSmartLock(boolean enable)` : Enable or disable Smart Lock For Passwords. If enabled, it will save automatically the credential in Smart Lock For Passwords\n\n#### Sign in \nLike with Google Sign-In, the `signIn()` method will return an `Observable\u003cRxAccount\u003e`.\n```java\n// sign in\nrxFacebookAuth.signIn()\n        .subscribe(rxAccount -\u003e {\n            // user is signed in\n            // use the rxAccount object as you want\n            Log.d(TAG, \"name: \" + rxAccount.getDisplayName());\n            Log.d(TAG, \"email: \" + rxAccount.getEmail());\n            \n        }, throwable -\u003e {\n            Log.e(TAG, throwable.getMessage());\n        });\n```\n\n#### Sign out \n`signOut()` method returns an `Observable\u003cRxStatus\u003e`.\n```java\n// sign out\nrxFacebookAuth.signOut()\n        .subscribe(rxStatus -\u003e {\n            if(rxStatus.isSuccess()) {\n                // user is signed out\n            }\n            \n        }, throwable -\u003e {\n            Log.e(TAG, throwable.getMessage());\n        });\n```\n\n### RxAuthSocial\nThis class permits to access and sign out the current account without knowing if it is a Google account or a Facebook account. For example it is useful when you want to sign out the current user but you don't know if he/she is connected with a Google or a Facebook account.\n\nThis class uses the singleton pattern.\n\n#### Sign out\nThis method will signed out the current user from the app, and from the current provider. It will also disable auto sign in for Smart Lock for Passwords and for the current provider. So the user will be able to pick an other account when using the authentication method again.\n\n```java\n// sign out\n// 'this' represents a FragmentActivity\nRxSocialAuth.getInstance().signOut(this)\n        .subscribe(rxStatus -\u003e {\n            if(rxStatus.isSuccess()) {\n                // user is signed out\n            }\n            \n            }, throwable -\u003e {\n                    Log.e(TAG, throwable.getMessage());\n            });\n```\n\n#### Get current user\nThis method return a `RxAccount` object representing the current user in the app. If the user is signed out, the `RxAccount` object will be null.\n\n```java\n// current user\nRxAccount currentUser = RxSocialAuth.getInstance().getCurrentUser();\n```\n\n\n### Smart Lock For Passwords\nCreate a `RxSmartLockPasswords` object using the `RxSmartLockPasswords.Builder` builder.\n```java\n// build RxSmartLockPassword object\n// 'this' represents a FragmentActivity\nRxSmartLockPasswords rxSmartLockPasswords = new RxSmartLockPasswords.Builder(this)\n        .disableAutoSignIn()\n        .setAccountTypes(IdentityProviders.GOOGLE, IdentityProviders.FACEBOOK)\n        .build()\n```\nYou can configure the builder with these methods : \n* `setAccountTypes(String... accountTypes)` : Set the account types (identity providers)\n* `setPasswordLoginSupported(boolean supported)` : Enable returning credentials with a password, that is verified by the application\n* `disableAutoSignIn()` : Disable auto sign \n\n#### Retrieve a user's stored credentials\nAutomatically sign users into your app by using the Credentials API to request and retrieve stored credentials for your users.\n\nIf you want to retrieve a Facebook account credential, for example, you have to call `.setAccountTypes(IdentityProviders.FACEBOOK)` on the builder of your `RxSmartLockPassword` object before.\n\n##### Request credential\nTo retrieve user's stored credentials, use the `requestCredential()` method on a `RxSmartLockPassword` object. This method returns an `Observable\u003cCredentialRequestResult\u003e`.\n\n```java\n// request credential\nrxSmartLockPassword.requestCredential()\n        .subscribe(credentialRequestResult -\u003e {\n            if (credentialRequestResult.getStatus().isSuccess()) {\n                onCredentialRetrieved(credentialRequestResult.getCredential());\n            } \n            else {\n                resolveResult(credentialRequestResult.getStatus());\n            }\n            \n        }, throwable -\u003e {\n            Log.e(TAG, throwable.getMessage());\n        });\n```\n\n##### Request credential and auto sign in\nTo retrieve user's stored credentials and automatically sign in the user with found credentials, use the `requestCredentialAndAutoSignIn()` method. It will return an `Observable\u003cObject\u003e`.\n\nWith this method you don't have to handle different cases. No matter if there is no stored credential, if there is only one stored credential, or if there are multiple stored credentials, the `requestCredentialAndAutoSignIn()` method will do all the work.\n\n* If there is only one stored credential, or if the user picks one of the multiple stored credentials, this method will catch it :\n    * If the account type is `Google` or `Facebook`, the user will be automatically sign in according to the provider, and the observer will receive a `RxAccount` object in case of success. If it fails a `Throwable` will be emitted.\n    * If the account type is different from `Google` or `Facebook` the observer will receive a `Credential` object :\n        * If the account type is null, this is a `LoginPassword` credential. In this case the `Credential` object will contain the id and the password, and you'll have to authenticate the user manually with the credential.\n        * If the account type is not null, it means that there is a provider, but different from `Google` or `Facebook`, like `Twitter` for example\n\n* If the user cancels or if there is no stored credential, a `Throwable` will be emitted.\n\n```java\n// request credential and auto sign in\nrxSmartLockPasswords.requestCredentialAndAutoSignIn()\n        .subscribe(o -\u003e {\n            if(o instanceof RxAccount) {\n                // user is signed in using google or facebook\n                RxAccount rxAccount = (RxAccount) o;\n                Log.d(TAG, \"provider: \" + rxAccount.getProvider());\n                Log.d(TAG, \"email: \" + rxAccount.getEmail());\n             }\n\n             else if(o instanceof Credential) {\n                Credential credential = (Credential) o;\n                if(credential.getAccountType() == null) {\n                    // credential contains login and password\n                    signInWithLoginPassword(credential.getId(), credential.getPassword());\n                }\n                else {\n                    // credential from other provider than Google or Facebook\n                    handleCredential(credential);\n                }\n             }\n\n        }, throwable -\u003e {\n            Log.e(TAG, throwable.getMessage());\n        });\n        \n        \nprivate void signInWithLoginPassword(String login, String password) {\n    // authenticate the user like you want\n}\n\nprivate void handleCredential(Credential credential) {\n   // do your logic here\n}\n```\n\n#### Store a user's credentials\nAfter users successfully sign in, create accounts, or change passwords, allow them to store their credentials to automate future authentication in your app.\n\nTo store a user's credentials, use the `saveCredential(Credential credential)` method on a `RxSmartLockPassword` object. It returns an `Observable\u003cRxStatus\u003e`.\n\nIf you used `RxGoogleAuth` or `RxFacebookAuth` with the `enableSmartLock(true)` option, the credential is stored automatically, and you don't have to use this method.\n\n```java\n// save credential\nrxSmartLockPassword.saveCredential(Credential credential)\n        .subscribe(rxStatus -\u003e {\n            if(rxStatus.isSuccess()) {\n                // credential saved\n            }\n            \n        }, throwable -\u003e {\n            Log.e(TAG, throwable.getMessage());\n        });\n```\n\n#### Delete stored credentials\n\nTo delete a stored credential, use the `deleteCredential(Credential credential)` method on a `RxSmartLockPassword` object. It returns an `Observable\u003cRxStatus\u003e`.\n\n```java\n// delete credential\nrxSmartLockPassword.deleteCredential(Credential credential)\n        .subscribe(rxStatus -\u003e {\n            if(rxStatus.isSuccess()) {\n                // credential deleted\n            }\n            \n        }, throwable -\u003e {\n            Log.e(TAG, throwable.getMessage());\n        });\n```\n## Sample\nA sample app with some use cases of the library is available on this [link](https://github.com/pchmn/RxSocialAuth/tree/master/sample)\n\n## Status\nThis library is currently in beta\n\n## Credits\nThis library was greatly inspired by [SocialLoginManager](https://github.com/jaychang0917/SocialLoginManager)\n\n## License\n```\nCopyright 2017 pchmn\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n   http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpchmn%2Frxsocialauth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpchmn%2Frxsocialauth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpchmn%2Frxsocialauth/lists"}