Hooking SharePoint APIs with Android

31

Transcript of Hooking SharePoint APIs with Android

Page 1: Hooking SharePoint APIs with Android
Page 2: 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

Page 3: Hooking SharePoint APIs with Android
Page 4: Hooking SharePoint APIs with Android
Page 5: Hooking SharePoint APIs with Android
Page 6: Hooking SharePoint APIs with Android

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

Page 7: Hooking SharePoint APIs with Android
Page 8: Hooking SharePoint APIs with Android
Page 9: Hooking SharePoint APIs with Android

Android Client

Azure AD O365 SharePoint

Linked

JSON/REST

OAuth

Page 10: Hooking SharePoint APIs with Android
Page 11: Hooking SharePoint APIs with Android

Android Client

Azure AD O365 SharePoint

Linked

JSON/REST

OAuth

Page 12: Hooking SharePoint APIs with Android
Page 13: Hooking SharePoint APIs with Android

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

Page 14: Hooking SharePoint APIs with Android
Page 15: Hooking SharePoint APIs with Android

dependencies {

//Include the Active Directory Authentication Library

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

}

Page 16: Hooking SharePoint APIs with Android

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

Page 17: Hooking SharePoint APIs with Android

//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);

Page 18: Hooking SharePoint APIs with Android

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. "[email protected]"

promptBehaviour,

extraQueryArgs,

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

);

Page 19: Hooking SharePoint APIs with Android

mAuthContext.acquireTokenSilently(

resource,

clientId,

userId, //acquired by call to acquireToken

callback

);

Page 20: Hooking SharePoint APIs with Android

Start

Show splash screen

acquireToken()AuthenticationActivity

Show main screen

End

storeTokens() callback(accessToken)

Page 21: Hooking SharePoint APIs with Android

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()

Page 22: Hooking SharePoint APIs with Android
Page 23: Hooking SharePoint APIs with Android
Page 24: Hooking SharePoint APIs with Android

Android Client

Azure AD O365 SharePoint

Linked

JSON/REST

OAuth

Page 25: Hooking SharePoint APIs with Android
Page 26: Hooking SharePoint APIs with Android

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

Page 27: Hooking SharePoint APIs with Android

ListClient client = new ListClient(

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

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

credentials

);

Credentials credentials = new OAuthCredentials(accessToken);

Page 28: Hooking SharePoint APIs with Android

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();

Page 29: Hooking SharePoint APIs with Android

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();

Page 30: Hooking SharePoint APIs with Android
Page 31: Hooking SharePoint APIs with Android