Skip to content

Instantly share code, notes, and snippets.

@ricalo
ricalo / AuthenticationManager.java
Last active August 29, 2015 14:18
Java class for an Android project that handles setup of ADAL Dependency Resolver for use in Office 365 API clients.
/*
* Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file.
* Portions of this class are adapted from the AuthenticationController.java file from Microsoft Open Technologies, Inc.
* located at https://github.com/OfficeDev/Office-365-SDK-for-Android/blob/master/samples/outlook/app/src/main/java/com/microsoft/services/controllers/AuthenticationController.java
*/
package com.microsoft.office365.connect;
import android.app.Activity;
import android.util.Log;
@ricalo
ricalo / setSecretKey.java
Last active August 29, 2015 14:18
Randomly generates an encryption key for devices with API level lower than 18.
// Devices with API level lower than 18 must setup an encryption key.
if (Build.VERSION.SDK_INT < 18 && AuthenticationSettings.INSTANCE.getSecretKeyData() == null) {
AuthenticationSettings.INSTANCE.setSecretKey(generateSecretKey());
}
/**
* Randomly generates an encryption key for devices with API level lower than 18.
* @return The encryption key in a 32 byte long array.
*/
protected byte[] generateSecretKey() {
@ricalo
ricalo / setSkipBroker.java
Last active August 29, 2015 14:18
Tell ADAL to not try to use a broker account for Microsoft Intune. Note that if you don't skip the broker or if you don't have Microsoft Intune portal app installed you'll get a warning. The warning alerts that you need the following permissions in your app manifest:- GET_ACCOUNTS- USE_CREDENTIALS- MANAGE_ACCOUNTS
// We're not using Microsoft Intune's Company portal app,
// skip the broker check.
AuthenticationSettings.INSTANCE.setSkipBroker(true);
@ricalo
ricalo / onActivityResult.java
Last active August 29, 2015 14:18
Implementation of the onActivityResult method required if you use ADAL's acquireToken with a signature that receives an activity as a parameter.
/**
* This activity gets notified about the completion of the ADAL activity through this method.
* @param requestCode The integer request code originally supplied to startActivityForResult(),
* allowing you to identify who this result came from.
* @param resultCode The integer result code returned by the child activity through its
* setResult().
* @param data An Intent, which can return result data to the caller (various data
* can be attached to Intent "extras").
*/
@Override
@ricalo
ricalo / AndroidManifest.xml
Created March 30, 2015 22:35
Android permissions required to connect to Office 365 and use Outlook services.
<!-- Required to connect to Office 365 -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Required to use outlook services -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
@ricalo
ricalo / build.gradle
Created March 30, 2015 23:08
Gradle dependencies to use ADAL and the Office 365 SDK for Android
// base OData library:
compile group: 'com.microsoft.services', name: 'odata-engine-core', version: '0.12.1'
compile group: 'com.microsoft.services', name: 'odata-engine-android-impl', version: '0.12.1', ext:'aar'
// choose the discovery and outlook services
compile group: 'com.microsoft.services', name: 'discovery-services', version: '0.12.1'
compile group: 'com.microsoft.services', name: 'outlook-services', version: '0.12.1'
// Azure Active Directory Library
compile group: 'com.microsoft.aad', name: 'adal', version: '1.1.1'
@ricalo
ricalo / Disconnect.java
Last active August 29, 2015 14:18
Function to remove the entries in the ADAL token cache, delete the cookies and set the relevant objects to null.This allows the app to disconnect from Office 365 and then connect with a different user.
private void disconnect(){
//Clear tokens.
AuthenticationManager
.getInstance()
.getAuthenticationContext()
.getCache()
.removeAll();
//Set manager objects to null.
MailManager.resetInstance();
@ricalo
ricalo / Constants.java
Created April 6, 2015 19:38
Constants that my team uses in our Office 365 Android projects.
/*
* Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file.
*/
package com.microsoft.office365.profile;
interface Constants {
public static final String AUTHORITY_URL = "https://login.microsoftonline.com/common";
public static final String DISCOVERY_RESOURCE_URL = "https://api.office.com/discovery/v1.0/me/";
public static final String DISCOVERY_RESOURCE_ID = "https://api.office.com/discovery/";
public static final String MAIL_CAPABILITY = "Mail";
@ricalo
ricalo / gist:4aabeb31d43f5097036b
Created December 11, 2015 19:06
Solve $'\r': command not found error when running a script on Cygwin for Windows without altering the source file
bash -o igncr <script_file>
@ricalo
ricalo / ADB.md
Last active February 8, 2016 19:54
ADB commands

Log relevant stuff for some Office 365 projects

adb -s [device] logcat -s Retrofit AuthenticationContext StorageHelp TokenCacheItem HttpWebRequest Oauth BasicWebViewClient BasicWebViewClientonPageStarted MyMeetingsService eglCodecCommon:S *:s