Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
pchmn committed Feb 2, 2017
2 parents 8c2c9be + 6c8fe21 commit d6a8811
Showing 1 changed file with 61 additions and 18 deletions.
79 changes: 61 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# RxSocialAuth
Android RxJava library for Social auth (Google, Facebook) and Smart Lock For Passwords

[![Release](https://jitpack.io/v/pchmn/RxSocialAuth.svg)](https://jitpack.io/#pchmn/RxSocialAuth/1.0.0-beta)
[![Release](https://jitpack.io/v/pchmn/RxSocialAuth.svg)](https://jitpack.io/#pchmn/RxSocialAuth)

## Setup
To use this library your `minSdkVersion` must be >= 15.
Expand All @@ -21,7 +21,7 @@ In your app level build.gradle :

```java
dependencies {
compile 'com.github.pchmn:RxSocialAuth:1.0.0-beta'
compile 'com.github.pchmn:RxSocialAuth:1.0.1-beta'
}
```

Expand Down Expand Up @@ -65,6 +65,7 @@ If you have trouble when trying to authenticate users, maybe you have to add the

#### RxAccount
This class represents a social account and has these methods :
* `String getProvider()`
* `String getId()`
* `String getAccessToken()`
* `String getEmail()`
Expand Down Expand Up @@ -103,8 +104,11 @@ You can configure the builder with these methods :
* `disableAutoSignIn()` : Clear the account previously selected by the user, so the user will have to pick an account
* `enableSmartLock(boolean enable)` : Enable or disable Smart Lock For Passwords. If enabled, it will save automatically the credential in Smart Lock For Passwords


#### Sign in and silent sign in
With `signIn()` and `silentSignIn(Credential credential)` methods, the observer receive a `RxAccount` object in case of success.
With `signIn()` and `silentSignIn(Credential credential)` methods, the observer receives a `RxAccount` object in case of success.

I 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.
```java
// sign in
rxGoogleAuth.signIn()
Expand Down Expand Up @@ -134,7 +138,7 @@ rxGoogleAuth.silentSignIn(Credential credential)
```

#### Sign out and revoke access
With `signOut()` and `revokeAccess()` methods, the observer receive a `RxStatus` object in case of success.
With `signOut()` and `revokeAccess()` methods, the observer receives a `RxStatus` object in case of success.
```java
// sign out
rxGoogleAuth.signOut()
Expand Down Expand Up @@ -180,7 +184,7 @@ You can configure the builder with these methods :
* `enableSmartLock(boolean enable)` : Enable or disable Smart Lock For Passwords. If enabled, it will save automatically the credential in Smart Lock For Passwords

#### Sign in
Like with Google Sign-In, the `signIn()` method will return an observable. And the observer will receive a `RxAccount` object in case of success.
Like with Google Sign-In, the `signIn()` method will return an `Observable<RxAccount>`. And the observer will receive a `RxAccount` object in case of success.
```java
// sign in
rxFacebookAuth.signIn()
Expand All @@ -196,7 +200,7 @@ rxFacebookAuth.signIn()
```

#### Sign out
With `signOut()` method, the observer receive a `RxStatus` object in case of success.
With `signOut()` method, the observer receives a `RxStatus` object in case of success.
```java
// sign out
rxFacebookAuth.signOut()
Expand All @@ -213,7 +217,7 @@ rxFacebookAuth.signOut()
### RxAuthSocial
This 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.

This class use the singleton pattern.
This class uses the singleton pattern.

#### Sign out
This 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.
Expand Down Expand Up @@ -253,33 +257,72 @@ RxSmartLockPassword rxSmartLockPassword = new RxSmartLockPassword.Builder(this)
.build()
```
You can configure the builder with these methods :
* `setAccountTypes(String... accountTypes)` : Sets the account types (identity providers)
* `setPasswordLoginSupported(boolean supported)` : Enables returning credentials with a password, that is verified by the application
* `setAccountTypes(String... accountTypes)` : Set the account types (identity providers)
* `setPasswordLoginSupported(boolean supported)` : Enable returning credentials with a password, that is verified by the application
* `disableAutoSignIn()` : Disable auto sign

#### Retrieve a user's stored credentials
Automatically sign users into your app by using the Credentials API to request and retrieve stored credentials for your users.

To retrieve user's stored credentials, use the `requestCredential()` method on a `RxSmartLockPassword` object. If 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.

You don't have to handle different cases. No matter if there is only one stored credential, or if there are multiple stored credentials, the `requestCredential()` method will do all the work.
If 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.

If there is only one stored credential, or if the user pick one of the multiple stored credentials, the user will be signed in according to the provider, and the observer will receive a `RxAccount` object in case of success. If the user cancel, a `Throwable` will be emitted.
##### Request credential
To retrieve user's stored credentials, use the `requestCredential()` method on a `RxSmartLockPassword` object. This method will emit a `Observable<CredentialRequestResult>`.

```java
// request credential
rxSmartLockPassword.requestCredential()
.subscribe(rxAccount -> {
// user is signed in
// use the rxAccount object as you want
Log.d(TAG, "name: " + rxAccount.getDisplayName());
Log.d(TAG, "email: " + rxAccount.getEmail());
.subscribe(credentialRequestResult -> {
if (credentialRequestResult.getStatus().isSuccess()) {
onCredentialRetrieved(credentialRequestResult.getCredential());
}
else {
resolveResult(credentialRequestResult.getStatus());
}

}, throwable -> {
Log.e(TAG, throwable.getMessage());
});
```

##### Request credential and auto sign in
To retrieve user's stored credentials and automatically sign in the user with found credentials, use the `requestCredentialAndAutoSignIn()` method. It will emit a `Observable<Object>`.

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

* If there is only one stored credential, or if the user picks one of the multiple stored credentials, this method will catch it :
* 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.
* If the account type is null, this is a `LoginPassword` credential. In this case, the observer will receive a `Credential` object, containing the id and the password, and you'll have to authenticate the user manually with the credential.

* If the user cancels or if there is no stored credential, a `Throwable` will be emitted.

```java
// request credential and auto sign in
rxSmartLockPassword.requestCredentialAndAutoSignIn()
.subscribe(o -> {
if(o instanceof RxAccount) {
// user is signed in using google or facebook
RxAccount rxAccount = (RxAccount) o;
Log.d(TAG, "provider: " + rxAccount.getProvider());
Log.d(TAG, "email: " + rxAccount.getEmail());
}
else if(o instanceof Credential) {
// credential contains login and password
Credential credential = (Credential) o;
// sign in manually
signInWithLoginPassword(credential.getId(), credential.getPassword());
}

}, throwable -> {
Log.e(TAG, throwable.getMessage());
});


private void signInWithLoginPassword(String login, String password) {
// authenticate the user like you want
}
```

#### Store a user's credentials
After users successfully sign in, create accounts, or change passwords, allow them to store their credentials to automate future authentication in your app.

Expand Down

0 comments on commit d6a8811

Please sign in to comment.