Skip to content

Commit

Permalink
Development (#57)
Browse files Browse the repository at this point in the history
Cloud Directory API
  • Loading branch information
rotembr authored and motyd committed Dec 6, 2017
1 parent 0681f2f commit 7a1ff87
Show file tree
Hide file tree
Showing 22 changed files with 1,890 additions and 257 deletions.
183 changes: 143 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# Bluemix App ID
Android SDK for the Bluemix App ID service
# IBM Cloud App ID Android SDK

[![Bluemix powered][img-bluemix-powered]][url-bluemix]
[![Travis][img-travis-master]][url-travis-master]
[![Coveralls][img-coveralls-master]][url-coveralls-master]
[![Codacy][img-codacy]][url-codacy]
[![Coverage Status][img-coveralls-master]][url-coveralls-master]
[![Codacy Badge][img-codacy]][url-codacy]
[![Release](https://jitpack.io/v/ibm-cloud-security/appid-clientsdk-android.svg)](https://jitpack.io/#ibm-cloud-security/appid-clientsdk-android)
[![License][img-license]][url-bintray]

Expand All @@ -13,11 +12,14 @@ Android SDK for the Bluemix App ID service
[![GithubForks][img-github-forks]][url-github-forks]

## Requirements
API 25 or above, Java 8.x, Android SDK tools 25.2.5 or above, Android SDK Platform Tools 25.0.3 or above, Android Build Tools version 25.0.2
* API 25 or above
* Java 8.x
* Android SDK tools 25.2.5 or above
* Android SDK Platform Tools 25.0.3 or above
* Android Build Tools version 25.0.2

## Installing the SDK:
1. Add the JitPack repository to your build file,
Add it in your root build.gradle at the end of repositories:
1. Add the JitPack repository to the your root `build.gradle` file at the end of the repository.

```gradle
allprojects {
Expand All @@ -31,7 +33,7 @@ API 25 or above, Java 8.x, Android SDK tools 25.2.5 or above, Android SDK Platfo
2. Add the dependency for the App ID client SDK:
```gradle
dependencies {
compile 'com.github.ibm-cloud-security:appid-clientsdk-android:1.+'
compile 'com.github.ibm-cloud-security:appid-clientsdk-android:2.+'
}
```
Expand All @@ -43,9 +45,7 @@ API 25 or above, Java 8.x, Android SDK tools 25.2.5 or above, Android SDK Platfo
}
```
## Using the SDK:
### Initializing the App ID client SDK
## Initializing the App ID client SDK
Initialize the client SDK by passing the context, tenantId and region parameters to the initialize method. A common, though not mandatory, place to put the initialization code is in the onCreate method of the main activity in your Android application.
```java
Expand All @@ -54,8 +54,8 @@ AppID.getInstance().initialize(getApplicationContext(), <tenantId>, AppID.REGION
* Replace "tenantId" with the App ID service tenantId.
* Replace the AppID.REGION_UK with your App ID region (AppID.REGION_US_SOUTH, AppID.REGION_SYDNEY).

### Using Login Widget
Use LoginWidget class to start the authorization flow.
## Using the Login Widget
Use the LoginWidget class to start the authorization flow.

```java
LoginWidget loginWidget = AppID.getInstance().getLoginWidget();
Expand All @@ -78,27 +78,130 @@ loginWidget.launch(this, new AuthorizationListener() {
```
**Note**:

The Login widget default configuration use Facebook and Google as authentication options.
If you configure only one of them the login widget will NOT launch and the user will be redirect to the configured idp authentication screen.
<!--
### Login using Resource Owner Password
You can obtain access token and id token by supplying the end user's username and the end user's password.
```java
AppID.getInstance().obtainTokensWithROP(getApplicationContext(), username, password,
new TokenResponseListener() {
@Override
public void onAuthorizationFailure (AuthorizationException exception) {
//Exception occurred
}
* The default configuration use Facebook and Google as authentication options. If you configure only one of them the login widget will *not* launch and the user will be redirected to the configured identity provider authentication screen.
* When using Cloud Directory, and "Email verification" is configured to *not* allow users to sign-in without email verification, then the "onAuthorizationSuccess" of the "AuthorizationListener" will be invoked without tokens.

## Managing Cloud Directory with the Android SDK
{: #managing-android}

Make sure to set Cloud Directory identity provider to ON in AppID dashboard, when using the following APIs.

### Login using Resource Owner Password
You can obtain access token and id token by supplying the end user's username and the end user's password.
```java
AppID.getInstance().obtainTokensWithROP(getApplicationContext(), username, password,
new TokenResponseListener() {
@Override
public void onAuthorizationSuccess (AccessToken accessToken, IdentityToken identityToken) {
//User authenticated
}
});
```
-->
### Anonymous Login
public void onAuthorizationFailure (AuthorizationException exception) {
//Exception occurred
}

@Override
public void onAuthorizationSuccess (AccessToken accessToken, IdentityToken identityToken) {
//User authenticated
}
});
```
### Sign Up
Make sure to set **Allow users to sign up and reset their password** to **ON**, in the settings for Cloud Directory.
Use the LoginWidget class to start the sign up flow.

```java
LoginWidget loginWidget = AppID.getInstance().getLoginWidget();
loginWidget.launchSignUp(this, new AuthorizationListener() {
@Override
public void onAuthorizationFailure (AuthorizationException exception) {
//Exception occurred
}

@Override
public void onAuthorizationCanceled () {
//Sign up canceled by the user
}

@Override
public void onAuthorizationSuccess (AccessToken accessToken, IdentityToken identityToken) {
if (accessToken != null && identityToken != null) {
//User authenticated
} else {
//email verification is required
}

}
});
```
### Forgot Password
Make sure to set **Allow users to sign up and reset their password** and **Forgot password email** to **ON**, in the settings for Cloud Directory

Use LoginWidget class to start the forgot password flow.
```java
LoginWidget loginWidget = AppID.getInstance().getLoginWidget();
loginWidget.launchForgotPassword(this, new AuthorizationListener() {
@Override
public void onAuthorizationFailure (AuthorizationException exception) {
//Exception occurred
}

@Override
public void onAuthorizationCanceled () {
//forogt password canceled by the user
}

@Override
public void onAuthorizationSuccess (AccessToken accessToken, IdentityToken identityToken) {
//forgot password finished, in this case accessToken and identityToken will be null.

}
});
```
### Change Details
Make sure to set **Allow users to sign up and reset their password** to **ON**, in Cloud Directory settings that are in AppID dashboard. Use LoginWidget class to start the change details flow. This API can be used only when the user is logged in using Cloud Directory identity provider.

```java
LoginWidget loginWidget = AppID.getInstance().getLoginWidget();
loginWidget.launchChangeDetails(this, new AuthorizationListener() {
@Override
public void onAuthorizationFailure (AuthorizationException exception) {
//Exception occurred
}

@Override
public void onAuthorizationCanceled () {
//changed details canceled by the user
}

@Override
public void onAuthorizationSuccess (AccessToken accessToken, IdentityToken identityToken) {
//User authenticated, and fresh tokens received
}
});
```
### Change Password
Make sure to set **Allow users to sign up and reset their password** to **ON**, in the settings for Cloud Directory.

Use LoginWidget class to start the change password flow. This API can be used only when the user logged in by using Cloud Directory as their identity provider.

```java
LoginWidget loginWidget = AppID.getInstance().getLoginWidget();
loginWidget.launchChangePassword(this, new AuthorizationListener() {
@Override
public void onAuthorizationFailure (AuthorizationException exception) {
//Exception occurred
}

@Override
public void onAuthorizationCanceled () {
//change password canceled by the user
}

@Override
public void onAuthorizationSuccess (AccessToken accessToken, IdentityToken identityToken) {
//User authenticated, and fresh tokens received
}
});
```

## Anonymous Login
```java
AppID.getInstance().loginAnonymously(getApplicationContext(), new AuthorizationListener() {
@Override
Expand All @@ -118,7 +221,7 @@ AppID.getInstance().loginAnonymously(getApplicationContext(), new AuthorizationL
});
```

### User profile attributes
## User profile attributes
```java
AppID appId = AppID.getInstance();
String name = "name";
Expand Down Expand Up @@ -172,7 +275,7 @@ appId.getUserAttributeManager().deleteAttribute(name, new UserAttributeResponseL
});
```

### Invoking protected resources
## Invoking protected resources
```java
BMSClient bmsClient = BMSClient.getInstance();
bmsClient.initialize(getApplicationContext(), AppID.REGION_UK);
Expand All @@ -199,7 +302,7 @@ public void onFailure (Response response, Throwable t, JSONObject extendedInfo)
});
```

### License
## License
This package contains code licensed under the Apache License, Version 2.0 (the "License"). You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 and may also view the License in the LICENSE file within this package.

[img-bluemix-powered]: https://img.shields.io/badge/bluemix-powered-blue.svg
Expand All @@ -218,8 +321,8 @@ This package contains code licensed under the Apache License, Version 2.0 (the "
[img-travis-master]: https://travis-ci.org/ibm-cloud-security/appid-clientsdk-android.svg
[url-travis-master]: https://travis-ci.org/ibm-cloud-security/appid-clientsdk-android

[img-coveralls-master]: https://coveralls.io/repos/github/ibm-cloud-security/appid-clientsdk-android/badge.svg
[url-coveralls-master]: https://coveralls.io/github/ibm-cloud-security/appid-clientsdk-android
[img-coveralls-master]: https://coveralls.io/repos/github/ibm-cloud-security/appid-clientsdk-android/badge.svg?branch=master
[url-coveralls-master]: https://coveralls.io/github/ibm-cloud-security/appid-clientsdk-android?branch=master

[img-codacy]: https://api.codacy.com/project/badge/Grade/d41f8f069dd343769fcbdb55089561fc?branch=master
[url-codacy]: https://www.codacy.com/app/ibm-cloud-security/appid-clientsdk-android
[img-codacy]: https://api.codacy.com/project/badge/Grade/be6f5f4cdae446909279d014bc650b1b
[url-codacy]: https://www.codacy.com/app/rotembr/appid-clientsdk-android?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=ibm-cloud-security/appid-clientsdk-android&amp;utm_campaign=Badge_Grad
Loading

0 comments on commit 7a1ff87

Please sign in to comment.