Skip to content

Instantly share code, notes, and snippets.

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