Git Product home page Git Product logo

msgraph-sample-maui's Introduction

page_type description products languages
sample
This sample demonstrates how to use the Microsoft Graph .NET SDK to access data in Office 365 from .NET MAUI apps.
ms-graph
office-exchange-online
csharp

Microsoft Graph sample .NET MAUI app

.NET License.

This sample demonstrates how to use the Microsoft Graph .NET SDK to access data in Office 365 from .NET MAUI apps.

NOTE: This sample was originally built from a tutorial published on the Microsoft Graph tutorials page. That tutorial has been removed.

Prerequisites

To run the completed project in this folder, you need the following:

  • Visual Studio 2022 Version 14.4.4 or later (Windows) or Visual Studio for Mac Version 14.4.2 or later (MacOS).
  • Either a personal Microsoft account with a mailbox on Outlook.com, or a Microsoft work or school account.

If you don't have a Microsoft account, there are a couple of options to get a free account:

Register a web application with the Azure Active Directory admin center

  1. Open a browser and navigate to the Azure Active Directory admin center. Login using a personal account (aka: Microsoft Account) or Work or School Account.

  2. Select Azure Active Directory in the left-hand navigation, then select App registrations under Manage.

  3. Select New registration. On the Register an application page, set the values as follows.

    • Set Name to .NET MAUI Graph Sample.
    • Set Supported account types to Accounts in any organizational directory and personal Microsoft accounts.
    • Leave Redirect URI empty.
  4. Select Register. On the .NET MAUI Graph Sample page, copy the value of the Application (client) ID and save it, you will need it in the next step.

  5. Select Authentication under Manage.

  6. Select Add a platform, then select Mobile and desktop applications.

  7. Enable the value that starts with msal, then select Configure.

Configure the sample

  1. Replace YOUR_CLIENT_ID_HERE with your Application (client) ID value in the following files:

Run the sample

Open GraphMAUI.sln in Visual Studio or Visual Studio for Mac and press F5 to build and run the sample.

Code of conduct

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.

Disclaimer

THIS CODE IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.

msgraph-sample-maui's People

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  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

msgraph-sample-maui's Issues

In iOS asking to set Team ID

When run in iOS, the app is breaking at PCA = builder.Build(); statement, asking to set 'team id'. No clue where to set it. I even tried Automatic Provisioning which didn't help.

Build in Release mode never ending

Building solution in Release mode never ends when Microsoft.Graph 5.X is referenced.

Steps to reproduce the behavior:

  1. Download this repo
  2. Switch from Debug to Release
  3. Build the solution

Expected behavior
The compilation of the solution finishes.

Tested with "Windows Machine" and also "Android Emulator", in both cases, it never ends.

Demo solutions don't build with latest VS

Downloaded latest version of the repo.
Open in VS latest public preview.
Build results in:

image

With no pending nuget restores or anything. Added binlog from running msbuild -bl -r for the main netstandard lib project

msbuild.zip

During signin is there a way to allow personal microsoft accounts?

I registered the app in my personal azure account. But when I launch the app and I try to sign in I get the following error.

'You can't sign in here with a personal account. Use your work or school account instead.'

Is there a way to modify the code or the app registration to allow sigin with per personal microsoft account?

Function definition missing - GetUtcStartOfWeekInTimeZone

Where did you get the code?

Describe the bug
A function definition is missing

To Reproduce
Steps to reproduce the behavior:

  1. Follow the tutorial till here https://docs.microsoft.com/en-us/graph/tutorials/xamarin?tutorial-step=4
  2. In this steps CalendarPage-xaml and .cs file has been explained
  3. You have refer to a function GetUtcStartOfWeekInTimeZone in the .cs file
  4. But this method is not defined in the tutorial hence a build error will occur

Expected behavior
There should not be a build error

Desktop (please complete the following information):

  • OS: Windows Andriod emulator

Dependency versions

  • Authentication library (MSAL, etc.) version:
  • Graph library (Graph SDK, REST library, etc.) version:

Additional context
to solve the problem I used below function definition but for this the line var startOfWeek = GetUtcStartOfWeekInTimeZone(DateTime.Today, App.UserTimeZone); needs to be changed to var startOfWeek = GetUtcStartOfWeekInTimeZone(DateTime.Today, App.UserTimeZone.ToString()); in CalendarPage.xaml.cs file

        private static DateTime GetUtcStartOfWeekInTimeZone(DateTime today, string timeZoneId)
        {
            // Time zone returned by Graph could be Windows or IANA style
            // .NET Core's FindSystemTimeZoneById needs IANA on Linux/MacOS,
            // and needs Windows style on Windows.
            // TimeZoneConverter can handle this for us
            TimeZoneInfo userTimeZone = TZConvert.GetTimeZoneInfo(timeZoneId);

            // Assumes Sunday as first day of week
            int diff = System.DayOfWeek.Sunday - today.DayOfWeek;

            // create date as unspecified kind
            var unspecifiedStart = DateTime.SpecifyKind(today.AddDays(diff), DateTimeKind.Unspecified);

            // convert to UTC
            return TimeZoneInfo.ConvertTimeToUtc(unspecifiedStart, userTimeZone);
        }

The example doesn't work in iPhone

I followed the explanation steps, but it doesn't work on an iPhone, it never returns after var interactiveAuthResult = await interactiveRequest.ExecuteAsync ();

Android.OS.NetworkOnMainThreadException, following this sample

Hi, I am getting Android.OS.NetworkOnMainThreadException when trying to retrieve the users photo with this code:

	_userPhoto = await graphClient.Me
	   .Photo
	   .Content
	   .GetAsync();

i cant figure out why any tips?

this code runs before just fine:

   _user = await graphClient.Me.GetAsync(
       requestConfiguration =>
       {
           requestConfiguration.QueryParameters.Select =
               new[] { "displayName", "mail" };
       });

Update for MSAL 3.x

Unfortunately, this sample is outdated and cannot be easily built after upgrading the referenced nuget packages. Are there any plans on updating this to the new version?

Provisioning Profiles

Hi.
While running this sample on iPhone simulator i am facing this error:
Could not find any available provisioning profiles for GraphTutorial.iOS on iOS.

What am I missing? Also on the simulator.

Thanks.

UWP crash

Microsoft.Identity.Client.MsalClientException: 'User canceled authentication.' Happens just trying to signin.

Happens at

    private async void OnSignIn(object sender, EventArgs e)
    {
        await (Application.Current as App).SignIn();
    }

Not working on iOS device (iPad)

Hello, I followed the tutorial step by step and everything works on simulator, but not a device...this line of code just hangs there which attempting to login....what am I doing wrong? I have been struggling with for days now.

var authResult = await interactiveRequest.ExecuteAsync();

PLEASE HELP!

Does not Work in Windows on Visual Studio 17.4

Runs and immediately exits. Output from debug:
"The program '[19916] GraphMAUI.exe: Program Trace' has exited with code 0 (0x0).
The program '[19916] GraphMAUI.exe' has exited with code 3762504530 (0xe0434352)."

There is an issue with Visual Studio 17.4 about immediate exit that recommends a work around of adding "false" to the .csproj. However, when this is done, it stops with an exception as follows:
System.DllNotFoundException
HResult=0x80131524
Message=Unable to load DLL 'Microsoft.ui.xaml.dll' or one of its dependencies: The specified module could not be found. (0x8007007E)
Source=GraphMAUI
StackTrace:
at GraphMAUI.WinUI.Program.XamlCheckProcessRequirements()
at GraphMAUI.WinUI.Program.Main(String[] args) in C:\Users\brianmiller1\git\msgraph-sample-maui\GraphMAUI\obj\Debug\net7.0-windows10.0.19041.0\win10-x64\Platforms\Windows\App.g.i.cs:line 28

Steps to reproduce the behavior:
Clone solution, launch in windows.

Expected behavior
Launches normally.

Desktop (please complete the following information):

  • OS: Windows 10 (although a teammate is also having this problem on Windows 11).

MPN ID required for App Registration (is it possible to add chapter about setting up "Accounts in this organizational directory only (<tenant> only - Single tenant)")

This example is great. However it shows scenario where user accessing API is "Accounts in any organizational directory (Any Azure AD directory - Multitenant)". To do App registration - it would require MPN ID - basically developer has to be MS Partner company employee. Is it possible to explain how to do App registration for scenario where user accessing APIS is "Accounts in this organizational directory only ( only - Single tenant)" ?
Thank you. Nikola

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.