SlideShare a Scribd company logo
Module 6: Hooking into SharePoint APIs with Android
Registration for Los Angeles June 16 2015
http://aka.ms/O365campLA
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
Ivan Sanders
SharePoint MVP/MCT
ivan@dimension-si.com
@iasanders
O365 DEVCamp Los Angeles June 16, 2015 Module 06 Hook into SharePoint APIs with ANDFROID
O365 DEVCamp Los Angeles June 16, 2015 Module 06 Hook into SharePoint APIs with ANDFROID
http://developer.android.com/sdk/index.html
O365 DEVCamp Los Angeles June 16, 2015 Module 06 Hook into SharePoint APIs with ANDFROID
O365 DEVCamp Los Angeles June 16, 2015 Module 06 Hook into SharePoint APIs with ANDFROID
Android Client
Azure AD O365 SharePoint
Linked
JSON/REST
OAuth
O365 DEVCamp Los Angeles June 16, 2015 Module 06 Hook into SharePoint APIs with ANDFROID
Android Client
Azure AD O365 SharePoint
Linked
JSON/REST
OAuth
O365 DEVCamp Los Angeles June 16, 2015 Module 06 Hook into SharePoint APIs with ANDFROID
https://github.com/AzureAD/azure-activedirectory-
library-for-android
O365 DEVCamp Los Angeles June 16, 2015 Module 06 Hook into SharePoint APIs with ANDFROID
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()
O365 DEVCamp Los Angeles June 16, 2015 Module 06 Hook into SharePoint APIs with ANDFROID
O365 DEVCamp Los Angeles June 16, 2015 Module 06 Hook into SharePoint APIs with ANDFROID
Android Client
Azure AD O365 SharePoint
Linked
JSON/REST
OAuth
O365 DEVCamp Los Angeles June 16, 2015 Module 06 Hook into SharePoint APIs with ANDFROID
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();
O365 DEVCamp Los Angeles June 16, 2015 Module 06 Hook into SharePoint APIs with ANDFROID
O365 DEVCamp Los Angeles June 16, 2015 Module 06 Hook into SharePoint APIs with ANDFROID

More Related Content

PPTX
O365 DEVCamp Los Angeles June 16, 2015 Module 05 Hook into Apps for Office
PPTX
O365 DEVCamp Los Angeles June 16, 2015 Module 03 Hook into Apps for Sharepoint
PPTX
O365 DEVCamp Los Angeles June 16, 2015 Module 04 Hook into Office 365 APIs
PPTX
O365 DEVCamp Los Angeles June 16, 2015 Module 02 Setting up the Environments
PPTX
SharePoint Saturday Los Angeles 2011 SharePoint 2010 as The Business Intellig...
PPTX
#OCSPUG SharePoint 2013 Best Practices
PPTX
Practical Business Intelligence in SharePoint 2013 - Honolulu
PPTX
SharePoint Saturday Silicon Valley - SharePoint Apps - Ryan Schouten
O365 DEVCamp Los Angeles June 16, 2015 Module 05 Hook into Apps for Office
O365 DEVCamp Los Angeles June 16, 2015 Module 03 Hook into Apps for Sharepoint
O365 DEVCamp Los Angeles June 16, 2015 Module 04 Hook into Office 365 APIs
O365 DEVCamp Los Angeles June 16, 2015 Module 02 Setting up the Environments
SharePoint Saturday Los Angeles 2011 SharePoint 2010 as The Business Intellig...
#OCSPUG SharePoint 2013 Best Practices
Practical Business Intelligence in SharePoint 2013 - Honolulu
SharePoint Saturday Silicon Valley - SharePoint Apps - Ryan Schouten

What's hot (20)

PDF
How to create custom Connector for Microsoft Flow
PPTX
Using office add ins to solve business problems-SharePoint Saturday Redmond 2015
PPTX
Practical Business Intelligence in SharePoint 2013 - Helsinki Finalnd
PPTX
So You Want To Be A SharePoint Developer-SPS Silicon Valley 2015
PDF
How to: Create a custom connector for Microsoft Flow
PPTX
Introducción a las Apps para SharePoint
PPTX
Deep dive into office 365 ap is for calendar mail and contacts
PDF
How to create custom connector for Microsoft Flow - SPSNL18
PPTX
Introducción a las Apps para Office
PPTX
Getting started with Office 365 API's
PPTX
Deep dive into office 365 api for one drive for business
PPTX
SharePoint Framework SPS Madrid 2016
PPTX
Microsoft Office Web Applications
PPTX
Office 365 Development Overview
PDF
Technical Overview of Microsoft SharePoint Online - Presented by Atidan
PDF
Build & Ignite Cloud Notes
PPTX
Office 365 - Introduction to SharePoint Online Development - SharePoint Conne...
PPTX
Apps for SharePoint Online 2013
PDF
Microsoft PowerApps Let’s change the way we build business apps
PDF
O365con14 - the new sharepoint online apps - napa in action
How to create custom Connector for Microsoft Flow
Using office add ins to solve business problems-SharePoint Saturday Redmond 2015
Practical Business Intelligence in SharePoint 2013 - Helsinki Finalnd
So You Want To Be A SharePoint Developer-SPS Silicon Valley 2015
How to: Create a custom connector for Microsoft Flow
Introducción a las Apps para SharePoint
Deep dive into office 365 ap is for calendar mail and contacts
How to create custom connector for Microsoft Flow - SPSNL18
Introducción a las Apps para Office
Getting started with Office 365 API's
Deep dive into office 365 api for one drive for business
SharePoint Framework SPS Madrid 2016
Microsoft Office Web Applications
Office 365 Development Overview
Technical Overview of Microsoft SharePoint Online - Presented by Atidan
Build & Ignite Cloud Notes
Office 365 - Introduction to SharePoint Online Development - SharePoint Conne...
Apps for SharePoint Online 2013
Microsoft PowerApps Let’s change the way we build business apps
O365con14 - the new sharepoint online apps - napa in action
Ad

Viewers also liked (8)

PPTX
Overview of Office 365 - Presentation By Sajid
PDF
Introduction to O365 E5 Plan
PDF
O365 Groups- Best Practices and Solutions
PPTX
36.5 Office 365 Features That Will Increase Your Productivity
PPTX
Office 365 Sales Presentation
PPTX
Office 365 presentation
PPSX
Microsoft Office 365 Presentation
PDF
Office 365 introduction and technical overview
Overview of Office 365 - Presentation By Sajid
Introduction to O365 E5 Plan
O365 Groups- Best Practices and Solutions
36.5 Office 365 Features That Will Increase Your Productivity
Office 365 Sales Presentation
Office 365 presentation
Microsoft Office 365 Presentation
Office 365 introduction and technical overview
Ad

Similar to O365 DEVCamp Los Angeles June 16, 2015 Module 06 Hook into SharePoint APIs with ANDFROID (15)

PDF
Hooking SharePoint APIs with Android
PPTX
Get started with building native mobile apps interacting with SharePoint
PPTX
Connect SharePoint Framework solutions to APIs secured with Azure AD
PPTX
SharePoint Saturday Belgium 2018 - APIs, APIs everywhere!
PPTX
APIs, APIs Everywhere!
PPTX
SharePoint Conference 2018 - APIs, APIs everywhere!
PPTX
SPConnect2014 Office 365 APIs
PPTX
Office 365 api vs share point app model
PPTX
SPFx Webinar Loading SharePoint data in a SPFx Webpart
PDF
Leveraging APIs from SharePoint Framework solutions
PDF
O365Con18 - Connect SharePoint Framework Solutions to API's secured with Azur...
PPTX
harePoint Framework Webinar Series: Consume Graph APIs in SharePoint Framework
PPTX
Mobile for SharePoint with Windows Phone
PDF
Made for Mobile - Let Office 365 Power Your Mobile Apps
PDF
Office 365 Groups and Tasks API - Getting Started
Hooking SharePoint APIs with Android
Get started with building native mobile apps interacting with SharePoint
Connect SharePoint Framework solutions to APIs secured with Azure AD
SharePoint Saturday Belgium 2018 - APIs, APIs everywhere!
APIs, APIs Everywhere!
SharePoint Conference 2018 - APIs, APIs everywhere!
SPConnect2014 Office 365 APIs
Office 365 api vs share point app model
SPFx Webinar Loading SharePoint data in a SPFx Webpart
Leveraging APIs from SharePoint Framework solutions
O365Con18 - Connect SharePoint Framework Solutions to API's secured with Azur...
harePoint Framework Webinar Series: Consume Graph APIs in SharePoint Framework
Mobile for SharePoint with Windows Phone
Made for Mobile - Let Office 365 Power Your Mobile Apps
Office 365 Groups and Tasks API - Getting Started

More from Ivan Sanders (20)

PPTX
Real world business workflow with SharePoint designer 2013
PPTX
Practical Business Intelligence with SharePoint 2013
PPTX
SharePoint 2013 Business Intelligence Demos to build your businesss 2.0
PPTX
Self-Service Business Intelligence in SharePoint 2013
PPTX
Practical businerss intelligence in share point 2013
PPTX
San Fernando Valley SharePoint UserGroup Jully 11, 2012
PPTX
Enterprise Content Management in SharePoint 2010 inplace autotagging with ter...
PPTX
Creating Business Intelligence With Share Point 2010
PPTX
SharePoint Saturday Orlando 2012 Creating Business Intelligence with SharePoi...
PPTX
SharePoint 2010 Application Lifecycle Management
PPTX
SharePoint Saturday Houston 2012
PPTX
Creating Business Intelligence with SharePoint 2010
PPTX
SharePoint Intelligence Real World Business Workflow With Share Point Designe...
PPTX
SharePoint Intelligence Introduction To Share Point Designer Workflows
PPTX
SharePoint Intelligence Extending Share Point Designer 2010 Workflows With Cu...
PPTX
SharePoint Saturday NYC - Business Intelligence
PPTX
SharePoint Saturday Sacramento Business Intelligence with SharePoint 2010
PPTX
Ep structured share point development - v.4
PPTX
Developer application lifecycle process and tools - v.5
PPTX
SharePoint Connections Coast to Coast Developer Boot Camp Crash Course v3
Real world business workflow with SharePoint designer 2013
Practical Business Intelligence with SharePoint 2013
SharePoint 2013 Business Intelligence Demos to build your businesss 2.0
Self-Service Business Intelligence in SharePoint 2013
Practical businerss intelligence in share point 2013
San Fernando Valley SharePoint UserGroup Jully 11, 2012
Enterprise Content Management in SharePoint 2010 inplace autotagging with ter...
Creating Business Intelligence With Share Point 2010
SharePoint Saturday Orlando 2012 Creating Business Intelligence with SharePoi...
SharePoint 2010 Application Lifecycle Management
SharePoint Saturday Houston 2012
Creating Business Intelligence with SharePoint 2010
SharePoint Intelligence Real World Business Workflow With Share Point Designe...
SharePoint Intelligence Introduction To Share Point Designer Workflows
SharePoint Intelligence Extending Share Point Designer 2010 Workflows With Cu...
SharePoint Saturday NYC - Business Intelligence
SharePoint Saturday Sacramento Business Intelligence with SharePoint 2010
Ep structured share point development - v.4
Developer application lifecycle process and tools - v.5
SharePoint Connections Coast to Coast Developer Boot Camp Crash Course v3

Recently uploaded (20)

PPTX
522797556-Unit-2-Temperature-measurement-1-1.pptx
PPTX
Introuction about ICD -10 and ICD-11 PPT.pptx
PDF
The Internet -By the Numbers, Sri Lanka Edition
DOCX
Unit-3 cyber security network security of internet system
PPTX
QR Codes Qr codecodecodecodecocodedecodecode
PDF
The New Creative Director: How AI Tools for Social Media Content Creation Are...
PPTX
Module 1 - Cyber Law and Ethics 101.pptx
PPTX
presentation_pfe-universite-molay-seltan.pptx
PPTX
artificial intelligence overview of it and more
PPTX
Slides PPTX World Game (s) Eco Economic Epochs.pptx
PDF
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
PPTX
Digital Literacy And Online Safety on internet
PDF
An introduction to the IFRS (ISSB) Stndards.pdf
PDF
WebRTC in SignalWire - troubleshooting media negotiation
PPTX
INTERNET------BASICS-------UPDATED PPT PRESENTATION
PPTX
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
PPTX
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
PPTX
Internet___Basics___Styled_ presentation
PDF
Slides PDF The World Game (s) Eco Economic Epochs.pdf
PPTX
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx
522797556-Unit-2-Temperature-measurement-1-1.pptx
Introuction about ICD -10 and ICD-11 PPT.pptx
The Internet -By the Numbers, Sri Lanka Edition
Unit-3 cyber security network security of internet system
QR Codes Qr codecodecodecodecocodedecodecode
The New Creative Director: How AI Tools for Social Media Content Creation Are...
Module 1 - Cyber Law and Ethics 101.pptx
presentation_pfe-universite-molay-seltan.pptx
artificial intelligence overview of it and more
Slides PPTX World Game (s) Eco Economic Epochs.pptx
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
Digital Literacy And Online Safety on internet
An introduction to the IFRS (ISSB) Stndards.pdf
WebRTC in SignalWire - troubleshooting media negotiation
INTERNET------BASICS-------UPDATED PPT PRESENTATION
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
Internet___Basics___Styled_ presentation
Slides PDF The World Game (s) Eco Economic Epochs.pdf
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx

O365 DEVCamp Los Angeles June 16, 2015 Module 06 Hook into SharePoint APIs with ANDFROID

Editor's Notes

  • #7: Android Studio is the current state-of-the-art for Android development. It is built on top of the IntelliJ IDEA IDE, a popular Java IDE developed by JetBrains. The editor will feel familiar for users of JetBrain’s popular ReSharper plugin for Visual Studio.
  • #8: Gradle makes the world go round. Dependencies can be pulled from e.g. Maven Central or jCenter. Android Studio automatically keeps it’s own project files in sync with the Gradle build files, so adding a dependency to a project is as simple as adding a line to the appropriate build.gradle file. The above line of code adds a dependency on the Active Directory Authentication Library for Android, a library maintained by MSOpenTech. The dependency is automatically downloaded in the background, so you immediately get autocomplete on all types in that library.
  • #9: Use the Android SDK manager to download different SDK Levels. The hands-on-lab will be targeting API Level 21 (Android 5.0.1 Lollipop), but should run fine on devices running API Levels as low as 18 (Android 4.3.1 KitKat).
  • #10: This is the high-level architecture of our app and the services which it consumes. Authentication is provided directly by Azure AD, via OAuth. After authentication, we communicate with the O365 SharePoint instance via its REST APIs.
  • #12: In this section we will look at authenticating an Android app with Azure AD using the Active Directory Library for Android
  • #14: ADAL simplifies authentication with Azure AD. Provides support for user authentication via sign-in (UI) or refresh tokens. Can be found on GitHub at https://github.com/AzureAD/azure-activedirectory-library-for-android
  • #15: This does require you to have access to the Azure Active Directory for your O365 Instance. You can do this by Adding a new Active Directory to your Azure Subscription, and selecting the “Use existing directory” option. After completing this step, creating the Application is simple – we cover that in the lab.
  • #16: First we must update the build.gradle file to include the ADAL. Android Studio will prompt you to Sync the changes to the Gradle file – this downloads the dependency and puts it in the right place for the IDE to find it, enabling autocompletion etc.
  • #17: Next we update the AndroidManifest.xml file with some permissions that ADAL requires (Internet/network permissions) We must also register the AuthenticationActivity activity which does the heavy-lifting of the OAuth flow. ADAL launches this activity which allows the user to enter their credentials.
  • #18: These basic code snippets must be added to your Activity class. Step 4 is only required if you intend to call mContext.acquireToken which will automatically launch an instance AuthenticationActivity. The onActivityResult function is invoked when that activity completes with a result.
  • #19: acquireToken launches the Oauth UI, and prompts the user to sign in with their O365 SharePoint credentials. The returned AuthenticationResult instance contains an Access Token (which will expire) and a Refresh Token. The refresh token will also eventually expire, but only after a much longer time. The callback argument is an instance of the AuthenticationCallback interface. Generally this is done using a Java Anonymous Class. The callback is invoked by mContext.onActivityResult from the previous slide, so it is important to call that if you are using this function. Note: ADAL automatically caches the access token and refresh token securely, so you don’t have to! It uses the Android secure keychain to do so.
  • #20: The callback argument is an instance of the AuthenticationCallback interface. Generally this is done using a Java Anonymous Class. Generally you will invoke acquireToken only when the user first starts the application, and then use acquireTokenSilently from then on. The ADAL automatically caches the Access Token and Refresh Token securely in the Android Keychain, and acquireTokenSilently attempts the following: Return the current Access Token (if still valid) Acquire a new Access Token using the current Refresh Token (if still valid) If this function fails, you must prompt the user to sign in using acquireToken. This function returns a new Access Token.
  • #21: In this pattern full authentication is only done on application startup. The Splash Screen here is the gateway to your app – the user must authenticate to continue. The app launches and starts the default activity or splash screen. The user clicks “sign in” button, which invokes acquireToken() The AuthenticationActivity is launched and the OAuth flow takes place – the user authenticates with Azure AD. The authentication result (an Access Token and a Refresh Token) is cached securely. The Access Token is returned to the app. The splash screen logic resumes and launches the next Activity. Finally, the splash screen calls finish() to remove itself from the activity stack.
  • #22: Next we write some code to support re-entrancy into potentially any location within the app. The user may at any time dismiss our app, do some work and then return to our app after their token has expired. In this situation we may need to refresh the Access Token or re-authenticate (or we may not). The user initiates some action (e.g. Refresh the current view) We first call acquireTokenSilently() to acquire an access token. We need to pass a callback because this function may asynchronously refresh the token. If the cached token is still valid then acquireTokenSilently returns it immediately and we continue with the API call (this may happen completely synchronously). Otherwise, the ADAL attempts to refresh the token using a cached refresh token. This happens asynchronously and requires an internet connection. If successful, we continue with the API call. If the refresh operation fails, then we must prompt the user to let them know, and restart the app so that they may authenticate again. We can wrap all of this behaviour into a few helper methods.
  • #23: Demo the authentication flow in StartActivity. Demo the refresh token handling code in AuthUtil.ensureAuthenticated, DefaultAuthHandler and the two activites ListTasksActivity and EditTaskActivity.
  • #27: The O365 SDK takes care of setting headers, serialization etc. Queries are automatically executed asynchronously on a background thread, so library functions may be safely called from the UI thread. Can be found on GitHub at https://github.com/OfficeDev/Office-365-SDK-for-Android.
  • #28: To use the SDK… Create am OAuthCredentials object from the Access Token obtained using ADAL (you must already be authenticated to use this class). Create an instance of ListClient. This class allows you to query and update SharePoint lists. This library supports: Authentication via Azure AD with OAuthCredentials Basic authentication with BasicAuthenticationCredentials Cookie authentication with CookieCredentials
  • #29: This simple code queries sharepoint for all Lists with the title “My List”. The object returned is a Future, also known as a Promise, which will be resolved when the call completes and the data is available. This means that the getLists call is non-blocking and can be safely used from the UI thread. Warning! The final line calls ListenableFuture.get(), which blocks the current thread until the results are available. Do no use this on the UI thread!
  • #30: This simple code queries sharepoint for all list items in the list with the name “My List”. The object returned is a Future, also known as a Promise, which will be resolved when the call completes and the data is available. This means that the getListItems call is non-blocking and can be safely used from the UI thread. Warning! The final line calls ListenableFuture.get(), which blocks the current thread until the results are available. Do no use this on the UI thread!
  • #31: Demo the sharepoint data access code in TaskListItemDataSource. Note that these functions are blocking and can only safely be called from a background thread!