Git Product home page Git Product logo

uwp-csharp-connect-sample's Introduction

[ARCHIVED] Microsoft Graph Connect Sample for UWP (Library)

IMPORTANT

This project is being archived and replaced with the Build UWP apps with Microsoft Graph. As part of the archival process, we're closing all open issues and pull requests.

You can continue to use this sample "as-is", but it won't be maintained moving forward. We apologize for any inconvenience.

Building apps for enterprise customers? Your app may not work if your enterprise customer turns on enterprise mobility security features like conditional device access. In this case, you may not know and your customers may experience errors.

To support all enterprise customers across all enterprise scenarios, you must use the Azure AD endpoint and manage your apps using the Azure Management Portal. For more information, see Deciding between the Azure AD and Azure AD v2.0 endpoints.

Important Note about the MSAL Preview

This library is suitable for use in a production environment. We provide the same production level support for this library as we do our current production libraries. During the preview we may make changes to the API, internal cache format, and other mechanisms of this library, which you will be required to take along with bug fixes or feature improvements. This may impact your application. For instance, a change to the cache format may impact your users, such as requiring them to sign in again. An API change may require you to update your code. When we provide the General Availability release we will require you to update to the General Availability version within six months, as applications written using a preview version of library may no longer work.

Table of contents

Introduction

This sample shows how to connect your Windows 10 Universal app to Office 365 using the Microsoft Graph API (previously called Office 365 unified API) to retrieve a user's profile picture, upload the picture to OneDrive, create a sharing link, and send an email that contains the photo as an attachment and the sharing link in its text. It uses the Microsoft Graph .NET Client Library to work with data returned by Microsoft Graph. The sample uses the Azure AD v2.0 endpoint, which enables users to sign in with either their personal or work or school Microsoft accounts.

Prerequisites

This sample requires the following:

Register and configure the app

  1. Sign into the App Registration Portal using either your personal or work or school account.

  2. Select Add an app.

  3. Enter a name for the app, and select Create application.

    The registration page displays, listing the properties of your app.

  4. Under Platforms, select Add platform.

  5. Select Native Application.

  6. Copy both the Application Id and Redirect URI values to the clipboard. You'll need to enter these values into the sample app.

    The app id is a unique identifier for your app. The redirect URI is a unique URI provided by Windows 10 for each application to ensure that messages sent to that URI are only sent to that application.

  7. Select Save.

Build and debug

Note: If you see any errors while installing packages during step 2, make sure the local path where you placed the solution is not too long/deep. Moving the solution closer to the root of your drive resolves this issue.

  1. After you've loaded the solution in Visual Studio, configure the sample to use the application (client) id and redirectURI that you registered by adding the corresponding values for these keys in the Application.Resources node of the App.xaml file. Office 365 UWP Microsoft Graph connect sample`

  2. Press F5 to build and debug. Run the solution and sign in with either your personal or work or school account.

Summary of key methods

The code in the main page of the app is relatively straight-forward and self-explanatory, as the calls for authentication and email service actually occur in the helper classes. The main page code primarily consists of event handlers for the two buttons:

  • ConnectButton_Click

    This method calls the GetAuthenticatedClientAsync method to acquire a GraphServicesClient object representing the current user, which it uses to set user email address and display name. If this is successful, it also enables the send mail button and the text box where the user can enter an email address, and populates that text box with the user's own email address.

  • MailButton_Click

    This method calls the ComposeAndSendMailAsync method, using the email address and display name variables set during ConnectButton_Click. If this method call is successful, it also updates the UI text accordingly.

With that in mind, it's worth looking at two methods in the helper classes in a little more detail:

  • GetAuthenticatedClientAsync

    This method of the AuthenticationHelper class authenticates the user with the Azure AD v2.0 endpoint.

    It does this by creating an AppConfig object that specifies the app client ID, return URL, and the scopes requested by the app. It then uses this AppConfig object to construct an OAuth2AuthenticationProvider object, and calls the AuthenticateAsync method on the authentication provider. Finally, it creates a GraphServicesClient object using the OAuth2AuthenticationProvider object.

    The SignInCurrentUserAsync method on the main page can then read user from this GraphServicesClient object and set the user email address and display name.

  • ComposeAndSendMailAsync

    This method of the MailHelper class uses the Microsoft Graph SDK to authenticate the user with the Azure AD v2.0 endpoint, compose a sample email, and then send the email using the user's account.

    It does this by declaring a GraphServicesClient object and setting it equal to the return value of AuthenticationHelper.GetAuthenticatedClientAsync. The method then composes the sample email, using various objects in the Microsoft.Graph namespace. Finally, it calls the SendMail method.

Contributing

If you'd like to contribute to this sample, see CONTRIBUTING.MD.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Questions and comments

We'd love to get your feedback about the UWP Microsoft Graph Connect SDK project. You can send your questions and suggestions to us in the Issues section of this repository.

Your feedback is important to us. Connect with us on Stack Overflow. Tag your questions with [MicrosoftGraph] and [office365].

Additional resources

Copyright

Copyright (c) 2016 Microsoft. All rights reserved.

uwp-csharp-connect-sample's People

Contributors

andrewjmay avatar ginach avatar jasonjoh avatar johnmaustin avatar o365devx avatar ricalo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

uwp-csharp-connect-sample's Issues

Repo name doesn't indicate this is a sample

Feedback from HackNYC: the messaging around this repo is unclear. The name would seem to indicate that it is a library, but the README indicates that it is a sample.

If it is a library, we should offer a nuget pkg w/ integration instructions, etc.

Can we include something in our namespacing like Graph.Microsoft.Sample?

2 factor authentication error.

I'm getting an error '

An error occurred 

No valid client certificate found in the request. No valid certificates found in the user's certificate store. Please try again choosing a different authentication method. 

when attempting to login with an account that has 2 factor authentication enabled.
Steps to reproduce:

  1. Build and run this sample. (Microsoft-Graph-UWP-Connect)
  2. Click 'Connect'
  3. Login with account that has 2 factor authentication enabled (a @Microsoft.com account for example).
  4. Click 'Sign in with PIN or smartcard'
  5. A message about a pop up is briefly displayed. Followed by the error mentioned above.

How can I login using my 2 factor PIN or certificate?

Getting "We can't connect to the service you need right now. Check your network connection or try this again later"

I am getting the error "We can't connect to the service you need right now. Check your network connection or try this again later"
When I use my work account to login.
However I am able to login using my live account with which I have associated my Azure AD which is my org tenant , I am global admin.

with the App V2 Model not able to sign in .. with live account don't have permission to perform any operations that my app do like SharePoint, OneDrive etc.

Not able to login with Micorsoft account

After adding the correct "ida:ClientID" from my app registration portal to the 'Application.Resources' tag and building the solution I run into the following error upon logging into my MS account:

We're unable to complete your request
Microsoft account is experiencing technical problems. Please try again later.

Any ideas how to troubleshoot this?

Thanks!

How to connect O365?

I try this sample. But I get the exception as follows;
Is there any right for a native application to access O365 with Graph API ?
{Microsoft.Identity.Client.MsalServiceException: AADSTS70001: Application '' is not supported for this API version.
Trace ID: a7299a00-43a4-4f23-9b57-2cc586710d00
Correlation ID: af6c6500-d619-4b21-befc-ec5cf0090257
Timestamp: 2017-11-15 09:35:22Z
at Microsoft.Identity.Client.Internal.Requests.InteractiveRequest.VerifyAuthorizationResult()
at Microsoft.Identity.Client.Internal.Requests.InteractiveRequest.d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Identity.Client.Internal.Requests.RequestBase.d__33.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Identity.Client.PublicClientApplication.d__21.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Identity.Client.PublicClientApplication.d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at Microsoft_Graph_UWP_Connect_SDK.AuthenticationHelper.<GetTokenForUserAsync>d__7.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at Microsoft_Graph_UWP_Connect_SDK.AuthenticationHelper.<>c.<b__6_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.BaseRequest.d__36.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.BaseRequest.d__321.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Graph.UserRequest.<GetAsync>d__6.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at Microsoft_Graph_UWP_Connect_SDK.MainPage.d__6.MoveNext()
ErrorCode: unauthorized_client
StatusCode: 0
Claims: } Microsoft.Identity.Client.MsalServiceException

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.