Giter Club home page Giter Club logo

contacts-api-win10-uwp's Introduction

Contacts-API-Win10-UWP

This repository contains a Universal Windows Platform (UWP) application for Windows 10 that connects to the Office 365 APIs for Contacts using the new WebAccountManager framework.

Environment Setup

The solution was built in Visual Studio 2015 with the Windows Software Development Kit (SDK) for Windows 10.

Office 365 applications are secured by Azure Active Directory, which comes as part of an Office 365 subscription. If you do not have an Office 365 Subscription or associated it with Azure AD, then you should follow the steps to Set up your Office 365 development environment from MSDN.

Registering the App

When you open the solution in Visual Studio 2015, the application will need to be registered for your tenant. Simply right-click the project and select Add > Connected Service. Use the connected service wizard to register the application with Azure AD with permissions to read/write contacts.

Using Windows 10's new WebAccountProvider

This sample uses Windows 10's new WebAccountProvider instead of a traditional WebAuthenticationBroker that the Azure AD Authentication Libraries (ADAL) have used in the past. The sample below shows how to get access tokens with this new framework. Notice we try to get the token silently at first and then with a forced prompt if it needs user intervention:

private static async Task<string> GetAccessToken()
{
	string token = null;

	//first try to get the token silently
	WebAccountProvider aadAccountProvider = await WebAuthenticationCoreManager.FindAccountProviderAsync("https://login.windows.net");
	WebTokenRequest webTokenRequest = new WebTokenRequest(aadAccountProvider, String.Empty, App.Current.Resources["ida:ClientID"].ToString(), WebTokenRequestPromptType.Default);
	webTokenRequest.Properties.Add("authority", "https://login.windows.net");
	webTokenRequest.Properties.Add("resource", "https://outlook.office365.com/");
	WebTokenRequestResult webTokenRequestResult = await WebAuthenticationCoreManager.GetTokenSilentlyAsync(webTokenRequest);
	if (webTokenRequestResult.ResponseStatus == WebTokenRequestStatus.Success)
	{
    	WebTokenResponse webTokenResponse = webTokenRequestResult.ResponseData[0];
    	token = webTokenResponse.Token;
	}
	else if (webTokenRequestResult.ResponseStatus == WebTokenRequestStatus.UserInteractionRequired)
	{
    	//get token through prompt
    	webTokenRequest = new WebTokenRequest(aadAccountProvider, String.Empty, App.Current.Resources["ida:ClientID"].ToString(), WebTokenRequestPromptType.ForceAuthentication);
    	webTokenRequest.Properties.Add("authority", "https://login.windows.net");
    	webTokenRequest.Properties.Add("resource", "https://outlook.office365.com/");
    	webTokenRequestResult = await WebAuthenticationCoreManager.RequestTokenAsync(webTokenRequest);
    	if (webTokenRequestResult.ResponseStatus == WebTokenRequestStatus.Success)
    	{
        	WebTokenResponse webTokenResponse = webTokenRequestResult.ResponseData[0];
        	token = webTokenResponse.Token;
    	}
	}

	return token;
}

Running the Application

The application is built as a Windows 10 UWP application, meaning it can run on both Windows 10 Desktop and Mobile. To debug on a specific device or emulator, simply select the desired option from the debug targets dropdown:

Windows 10 UWP Debug Targets

Windows 10 Desktop:

Win10 Desktop

Windows 10 Mobile:

Win10 Mobile

contacts-api-win10-uwp's People

Contributors

richdizz avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.