Hooking SharePoint APIs with Android

Post on 07-Aug-2015

325 views 3 download

Tags:

Transcript of Hooking SharePoint APIs with Android

Course Agenda

Office Camp

Module 1: Introduction to the Day

Module 2: Setting up the Environments

Module 3: Hooking into Apps for SharePoint

Module 4: Hooking into Office 365 APIs

Module 5: Hooking into Apps for Office

Module 6: Hooking into SharePoint APIs with Android

http://developer.android.com/sdk/index.html

Android Client

Azure AD O365 SharePoint

Linked

JSON/REST

OAuth

Android Client

Azure AD O365 SharePoint

Linked

JSON/REST

OAuth

https://github.com/AzureAD/azure-activedirectory-library-for-android

dependencies {

//Include the Active Directory Authentication Library

compile group: 'com.microsoft.aad', name: 'adal', version: '1.0.5'

}

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

<application ...>

...

<activity

android:name="com.microsoft.aad.adal.AuthenticationActivity"

android:label="Authenticate with AD"

android:screenOrientation="portrait">

</activity>

</application>

//in Activity

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

super.onActivityResult(requestCode, resultCode, data);

//complete any authentication requests

mContext.onActivityResult(requestCode, resultCode, data);

}

//in Activity.onCreate()

mContext = new AuthenticationContext(application, authority, false);

mAuthContext.acquireToken(currentActivity,

sharepointUrl, //e.g. http://mydomain.sharepoint.com

clientId, //an Azure AD client id

redirectUrl, //e.g. "http://android/callback" (also configured with AD)

loginHint, //e.g. "user@mydomain.onmicrosoft.com"

promptBehaviour,

extraQueryArgs,

callback //e.g. new AuthenticationCallback<AuthenticationResult>() {...}

);

mAuthContext.acquireTokenSilently(

resource,

clientId,

userId, //acquired by call to acquireToken

callback

);

Start

Show splash screen

acquireToken()AuthenticationActivity

Show main screen

End

storeTokens() callback(accessToken)

Start

User initiates API call

acquireTokenSilently()

callback(accessToken)

Complete API call

End

Cache valid? NO

YES

refreshToken()

Success?YES NO

Restart app for auth

End

storeTokens()

Android Client

Azure AD O365 SharePoint

Linked

JSON/REST

OAuth

https://github.com/OfficeDev/Office-365-SDK-for-Android

ListClient client = new ListClient(

sharePointUrl, //e.g. "http://mydomain.sharepoint.com/"

sharePointSitePath, //e.g. "/client/site"

credentials

);

Credentials credentials = new OAuthCredentials(accessToken);

final String listName = "My List";

//this produces the odata query: $filter=Title+eq+"My list"

Query query = QueryOperations.field("Title").eq(listName);

//we can attach callbacks to f which will run when the data is available

ListenableFuture<List<SPList>> f = client.getLists(query);

//Or... calling .get() will block this thread until the data is available

//DO NOT DO THIS ON THE UI THREAD!

List<SPList> results = f.get();

final String listName = "My List";

//this produces the odata query: $filter=startsWith(Title,"Item #")

Query query = QueryOperations.startsWith("Title", "Item #");

//we can attach callbacks to f which will run when the data is available

ListenableFuture<List<SPListItem>> f = client.getListItems(listName, query);

//Or... calling .get() will block this thread until the data is available

//DO NOT DO THIS ON THE UI THREAD!

List<SPListItem> results = f.get();