├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── README-Localized ├── README-de-de.md ├── README-es-es.md ├── README-fr-fr.md ├── README-ja-jp.md ├── README-pt-br.md ├── README-ru-ru.md ├── README-zh-cn.md └── README-zh-tw.md ├── README.md ├── XamarinConnect.sln ├── XamarinConnect ├── XamarinConnect.Droid │ ├── Assets │ │ └── AboutAssets.txt │ ├── MainActivity.cs │ ├── MainApplication.cs │ ├── MainPageRenderer.cs │ ├── Properties │ │ ├── AndroidManifest.xml │ │ └── AssemblyInfo.cs │ ├── Resources │ │ ├── AboutResources.txt │ │ ├── Resource.Designer.cs │ │ ├── drawable-hdpi │ │ │ └── icon.png │ │ ├── drawable-xhdpi │ │ │ └── icon.png │ │ ├── drawable-xxhdpi │ │ │ └── icon.png │ │ └── drawable │ │ │ └── icon.png │ ├── XamarinConnect.Droid.csproj │ ├── XamarinConnect.Droid.csproj.bak │ ├── app.config │ └── packages.config ├── XamarinConnect.UWP │ ├── App.xaml │ ├── App.xaml.cs │ ├── Assets │ │ ├── LockScreenLogo.scale-200.png │ │ ├── SplashScreen.scale-200.png │ │ ├── Square150x150Logo.scale-200.png │ │ ├── Square44x44Logo.scale-200.png │ │ ├── Square44x44Logo.targetsize-24_altform-unplated.png │ │ ├── StoreLogo.png │ │ └── Wide310x150Logo.scale-200.png │ ├── MainPage.xaml │ ├── MainPage.xaml.cs │ ├── Package.appxmanifest │ ├── Properties │ │ ├── AssemblyInfo.cs │ │ └── Default.rd.xml │ ├── XamarinConnect.UWP.csproj │ └── project.json ├── XamarinConnect.iOS │ ├── AppDelegate.cs │ ├── Entitlements.plist │ ├── Info.plist │ ├── Main.cs │ ├── MainPageRenderer.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Resources │ │ ├── Default-568h@2x.png │ │ ├── Default-Portrait.png │ │ ├── Default-Portrait@2x.png │ │ ├── Default.png │ │ ├── Default@2x.png │ │ ├── Icon-60@2x.png │ │ ├── Icon-60@3x.png │ │ ├── Icon-76.png │ │ ├── Icon-76@2x.png │ │ ├── Icon-Small-40.png │ │ ├── Icon-Small-40@2x.png │ │ ├── Icon-Small-40@3x.png │ │ ├── Icon-Small.png │ │ ├── Icon-Small@2x.png │ │ ├── Icon-Small@3x.png │ │ └── LaunchScreen.storyboard │ ├── XamarinConnect.iOS.csproj │ ├── app.config │ ├── iTunesArtwork │ ├── iTunesArtwork@2x │ └── packages.config └── XamarinConnect │ ├── App.cs │ ├── AppResources.Designer.cs │ ├── AppResources.resx │ ├── AuthenticationHelper.cs │ ├── GettingStarted.Xamarin │ ├── MailHelper.cs │ ├── MainPage.xaml │ ├── MainPage.xaml.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── XamarinConnect.csproj │ ├── app.config │ ├── packages.config │ └── test.jpg ├── readme-images ├── Appdotcs.png ├── Droid.png ├── MSALPackage.png ├── NuGetXamFormsRemove.png ├── PCLProjects.png ├── RemoveWinPhone8.png ├── RemoveWinPhone8Target.png ├── SelectProject.png ├── UWP.png ├── appId.png └── iOS.png └── starter ├── XamarinConnect.sln └── XamarinConnect ├── XamarinConnect.Droid ├── Assets │ └── AboutAssets.txt ├── MainActivity.cs ├── MainApplication.cs ├── MainPageRenderer.cs ├── Properties │ ├── AndroidManifest.xml │ └── AssemblyInfo.cs ├── Resources │ ├── AboutResources.txt │ ├── Resource.Designer.cs │ ├── drawable-hdpi │ │ └── icon.png │ ├── drawable-xhdpi │ │ └── icon.png │ ├── drawable-xxhdpi │ │ └── icon.png │ └── drawable │ │ └── icon.png ├── XamarinConnect.Droid.csproj ├── XamarinConnect.Droid.csproj.bak └── packages.config ├── XamarinConnect.UWP ├── App.xaml ├── App.xaml.cs ├── Assets │ ├── LockScreenLogo.scale-200.png │ ├── SplashScreen.scale-200.png │ ├── Square150x150Logo.scale-200.png │ ├── Square44x44Logo.scale-200.png │ ├── Square44x44Logo.targetsize-24_altform-unplated.png │ ├── StoreLogo.png │ └── Wide310x150Logo.scale-200.png ├── MainPage.xaml ├── MainPage.xaml.cs ├── Package.appxmanifest ├── Properties │ ├── AssemblyInfo.cs │ └── Default.rd.xml ├── XamarinConnect.UWP.csproj └── project.json ├── XamarinConnect.iOS ├── AppDelegate.cs ├── Entitlements.plist ├── Info.plist ├── Main.cs ├── MainPageRenderer.cs ├── Properties │ └── AssemblyInfo.cs ├── Resources │ ├── Default-568h@2x.png │ ├── Default-Portrait.png │ ├── Default-Portrait@2x.png │ ├── Default.png │ ├── Default@2x.png │ ├── Icon-60@2x.png │ ├── Icon-60@3x.png │ ├── Icon-76.png │ ├── Icon-76@2x.png │ ├── Icon-Small-40.png │ ├── Icon-Small-40@2x.png │ ├── Icon-Small-40@3x.png │ ├── Icon-Small.png │ ├── Icon-Small@2x.png │ ├── Icon-Small@3x.png │ └── LaunchScreen.storyboard ├── XamarinConnect.iOS.csproj ├── iTunesArtwork ├── iTunesArtwork@2x └── packages.config └── XamarinConnect ├── App.cs ├── AppResources.Designer.cs ├── AppResources.resx ├── AuthenticationHelper.cs ├── GettingStarted.Xamarin ├── MailHelper.cs ├── MainPage.xaml ├── MainPage.xaml.cs ├── Properties └── AssemblyInfo.cs ├── XamarinConnect.csproj ├── app.config ├── packages.config └── test.jpg /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | 24 | # Visual Studio 2015 cache/options directory 25 | .vs/ 26 | # Uncomment if you have tasks that create the project's static files in wwwroot 27 | #wwwroot/ 28 | 29 | # MSTest test Results 30 | [Tt]est[Rr]esult*/ 31 | [Bb]uild[Ll]og.* 32 | 33 | # NUNIT 34 | *.VisualState.xml 35 | TestResult.xml 36 | 37 | # Build Results of an ATL Project 38 | [Dd]ebugPS/ 39 | [Rr]eleasePS/ 40 | dlldata.c 41 | 42 | # DNX 43 | project.lock.json 44 | artifacts/ 45 | 46 | *_i.c 47 | *_p.c 48 | *_i.h 49 | *.ilk 50 | *.meta 51 | *.obj 52 | *.pch 53 | *.pdb 54 | *.pgc 55 | *.pgd 56 | *.rsp 57 | *.sbr 58 | *.tlb 59 | *.tli 60 | *.tlh 61 | *.tmp 62 | *.tmp_proj 63 | *.log 64 | *.vspscc 65 | *.vssscc 66 | .builds 67 | *.pidb 68 | *.svclog 69 | *.scc 70 | 71 | # Chutzpah Test files 72 | _Chutzpah* 73 | 74 | # Visual C++ cache files 75 | ipch/ 76 | *.aps 77 | *.ncb 78 | *.opendb 79 | *.opensdf 80 | *.sdf 81 | *.cachefile 82 | 83 | # Visual Studio profiler 84 | *.psess 85 | *.vsp 86 | *.vspx 87 | *.sap 88 | 89 | # TFS 2012 Local Workspace 90 | $tf/ 91 | 92 | # Guidance Automation Toolkit 93 | *.gpState 94 | 95 | # ReSharper is a .NET coding add-in 96 | _ReSharper*/ 97 | *.[Rr]e[Ss]harper 98 | *.DotSettings.user 99 | 100 | # JustCode is a .NET coding add-in 101 | .JustCode 102 | 103 | # TeamCity is a build add-in 104 | _TeamCity* 105 | 106 | # DotCover is a Code Coverage Tool 107 | *.dotCover 108 | 109 | # NCrunch 110 | _NCrunch_* 111 | .*crunch*.local.xml 112 | nCrunchTemp_* 113 | 114 | # MightyMoose 115 | *.mm.* 116 | AutoTest.Net/ 117 | 118 | # Web workbench (sass) 119 | .sass-cache/ 120 | 121 | # Installshield output folder 122 | [Ee]xpress/ 123 | 124 | # DocProject is a documentation generator add-in 125 | DocProject/buildhelp/ 126 | DocProject/Help/*.HxT 127 | DocProject/Help/*.HxC 128 | DocProject/Help/*.hhc 129 | DocProject/Help/*.hhk 130 | DocProject/Help/*.hhp 131 | DocProject/Help/Html2 132 | DocProject/Help/html 133 | 134 | # Click-Once directory 135 | publish/ 136 | 137 | # Publish Web Output 138 | *.[Pp]ublish.xml 139 | *.azurePubxml 140 | # TODO: Comment the next line if you want to checkin your web deploy settings 141 | # but database connection strings (with potential passwords) will be unencrypted 142 | *.pubxml 143 | *.publishproj 144 | 145 | # NuGet Packages 146 | *.nupkg 147 | # The packages folder can be ignored because of Package Restore 148 | **/packages/* 149 | # except build/, which is used as an MSBuild target. 150 | !**/packages/build/ 151 | # Uncomment if necessary however generally it will be regenerated when needed 152 | #!**/packages/repositories.config 153 | # NuGet v3's project.json files produces more ignoreable files 154 | *.nuget.props 155 | *.nuget.targets 156 | 157 | # Microsoft Azure Build Output 158 | csx/ 159 | *.build.csdef 160 | 161 | # Microsoft Azure Emulator 162 | ecf/ 163 | rcf/ 164 | 165 | # Microsoft Azure ApplicationInsights config file 166 | ApplicationInsights.config 167 | 168 | # Windows Store app package directory 169 | AppPackages/ 170 | BundleArtifacts/ 171 | 172 | # Visual Studio cache files 173 | # files ending in .cache can be ignored 174 | *.[Cc]ache 175 | # but keep track of directories ending in .cache 176 | !*.[Cc]ache/ 177 | 178 | # Others 179 | ClientBin/ 180 | ~$* 181 | *~ 182 | *.dbmdl 183 | *.dbproj.schemaview 184 | *.pfx 185 | *.publishsettings 186 | node_modules/ 187 | orleans.codegen.cs 188 | 189 | # RIA/Silverlight projects 190 | Generated_Code/ 191 | 192 | # Backup & report files from converting an old project file 193 | # to a newer Visual Studio version. Backup files are not needed, 194 | # because we have git ;-) 195 | _UpgradeReport_Files/ 196 | Backup*/ 197 | UpgradeLog*.XML 198 | UpgradeLog*.htm 199 | 200 | # SQL Server files 201 | *.mdf 202 | *.ldf 203 | 204 | # Business Intelligence projects 205 | *.rdl.data 206 | *.bim.layout 207 | *.bim_*.settings 208 | 209 | # Microsoft Fakes 210 | FakesAssemblies/ 211 | 212 | # GhostDoc plugin setting file 213 | *.GhostDoc.xml 214 | 215 | # Node.js Tools for Visual Studio 216 | .ntvs_analysis.dat 217 | 218 | # Visual Studio 6 build log 219 | *.plg 220 | 221 | # Visual Studio 6 workspace options file 222 | *.opt 223 | 224 | # Visual Studio LightSwitch build output 225 | **/*.HTMLClient/GeneratedArtifacts 226 | **/*.DesktopClient/GeneratedArtifacts 227 | **/*.DesktopClient/ModelManifest.xml 228 | **/*.Server/GeneratedArtifacts 229 | **/*.Server/ModelManifest.xml 230 | _Pvt_Extensions 231 | 232 | # Paket dependency manager 233 | .paket/paket.exe 234 | 235 | # FAKE - F# Make 236 | .fake/ 237 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Microsoft. All rights reserved. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | 24 | -------------------------------------------------------------------------------- /README-Localized/README-ja-jp.md: -------------------------------------------------------------------------------- 1 | # Xamarin Forms 用 Microsoft Graph Connect のサンプル 2 | 3 | ## 目次 4 | 5 | * [はじめに](#introduction) 6 | * [前提条件](#prerequisites) 7 | * [アプリを登録して構成する](#register) 8 | * [ビルドとデバッグ](#build) 9 | * [質問とコメント](#questions) 10 | * [その他のリソース](#additional-resources) 11 | 12 | 13 | ## 概要 14 | 15 | このサンプルでは、Microsoft Graph API を使って Xamarin Forms アプリを Microsoft の職場または学校 (Azure Active Directory) アカウントまたは個人用 (Microsoft) アカウントに接続して、ユーザーのプロフィール画像の取得、OneDrive への画像のアップロード、電子メール (画像が添付され、共有リンクがテキストに含まれる) の送信を行う方法を示します。 [Microsoft Graph .NET クライアント SDK](https://github.com/microsoftgraph/msgraph-sdk-dotnet) を使用して、Microsoft Graph が返すデータを操作します。 16 | 17 | また、サンプルでは認証に [Microsoft 認証ライブラリ (MSAL)](https://www.nuget.org/packages/Microsoft.Identity.Client/) を使用します。MSAL SDK には、[Azure AD v2.0 エンドポイント](https://msdn.microsoft.com/office/office365/howto/authenticate-Office-365-APIs-using-v2)を操作するための機能が用意されており、開発者はユーザーの職場または学校のアカウント、および個人用アカウントの両方に対する認証を処理する 1 つのコード フローを記述することができます。 18 | 19 | 独自の Xamarin Forms アプリで MSAL を開発する場合は、[MSAL で Xamarin Forms プロジェクトをセットアップするためのこれらの手順](https://github.com/microsoftgraph/xamarin-csharp-connect-sample/wiki/Set-up-a-Xamarin-Forms-project-to-use-the-MSAL-.NET-SDK)を実行します。 20 | 21 | ## MSAL プレビューに関する重要な注意事項 22 | 23 | このライブラリは、運用環境での使用に適しています。 このライブラリに対しては、現在の運用ライブラリと同じ運用レベルのサポートを提供します。 プレビュー中にこのライブラリの API、内部キャッシュの形式、および他のメカニズムを変更する場合があります。これは、バグの修正や機能強化の際に実行する必要があります。 これは、アプリケーションに影響を与える場合があります。 例えば、キャッシュ形式を変更すると、再度サインインが要求されるなどの影響をユーザーに与えます。 API を変更すると、コードの更新が要求される場合があります。 一般提供リリースが実施されると、プレビュー バージョンを使って作成されたアプリケーションは動作しなくなるため、6 か月以内に一般提供バージョンに更新することが求められます。 24 | 25 | 26 | ## 前提条件 ## 27 | 28 | このサンプルを実行するには次のものが必要です: 29 | 30 | * [Visual Studio 2015](https://www.visualstudio.com/downloads) 31 | * [Xamarin for Visual Studio](https://www.xamarin.com/visual-studio) 32 | * Windows 10 ([開発モードが有効](https://msdn.microsoft.com/library/windows/apps/xaml/dn706236.aspx)) 33 | * [Microsoft](https://www.outlook.com) または [Office 365 for Business アカウント](https://msdn.microsoft.com/office/office365/howto/setup-development-environment#bk_Office365Account)のいずれか 34 | 35 | このサンプルで iOS プロジェクトを実行する場合は、以下のものが必要です: 36 | 37 | * 最新の iOS SDK 38 | * 最新バージョンの Xcode 39 | * Mac OS X Yosemite(10.10) 以上 40 | * [Xamarin.iOS](https://developer.xamarin.com/guides/ios/getting_started/installation/mac/) 41 | * [Visual Studio に接続されている Xamarin Mac エージェント](https://developer.xamarin.com/guides/ios/getting_started/installation/windows/connecting-to-mac/) 42 | 43 | Android プロジェクトを実行する場合は、[Visual Studio Emulator for Android](https://www.visualstudio.com/features/msft-android-emulator-vs.aspx) を使用できます。 44 | 45 | 46 | ## アプリを登録して構成する 47 | 48 | 1. 個人用アカウント、あるいは職場または学校アカウントのいずれかを使用して、[アプリ登録ポータル](https://apps.dev.microsoft.com/)にサインインします。 49 | 2. **[アプリの追加]** を選択します。 50 | 3. アプリの名前を入力して、**[作成]** を選択します。 51 | 52 | 登録ページが表示され、アプリのプロパティが一覧表示されます。 53 | 54 | 4. **[プラットフォーム]** で、**[プラットフォームの追加]** を選択します。 55 | 5. **[ネイティブ アプリケーション]** を選択します。 56 | 6. **[ネイティブ アプリケーション]** プラットフォームを追加したときに作成されたアプリケーション ID の値とカスタム リダイレクト URI の値 (**[ネイティブ アプリケーション]** ヘッダーの下) をコピーします。 この URI は、お客様のアプリケーション ID の値が含まれており、次の形式である必要があります。`msal://auth` サンプル アプリにこれらの値を入力する必要があります。 57 | 58 | アプリ ID は、アプリの一意識別子です。 59 | 60 | 7. **[保存]** を選択します。 61 | 62 | 63 | ## ビルドとデバッグ ## 64 | 65 | **注:**手順 12 でパッケージのインストール中にエラーが発生した場合は、ソリューションを保存したローカル パスが長すぎたり深すぎたりしていないかご確認ください。ドライブのルート近くにソリューションを移動すると問題が解決します。 66 | 67 | 1. ソリューションの **XamarinConnect (ポータブル)** プロジェクト内にある App.cs ファイルを開きます。 68 | 69 | ![](/readme-images/Appdotcs.png "Open App.cs file in XamarinConnect project") 70 | 71 | 2. Visual Studio にソリューションを読み込んだ後、登録したクライアント ID を App.cs ファイルの **ClientId** 変数の値にして、この値を使用するようにサンプルを構成します。 72 | 73 | 74 | ![](/readme-images/appId.png "Client ID value in App.cs file") 75 | 76 | 3. UserDetailsClient.iOS\info.plist ファイルをテキスト エディターで開きます。 残念ながらこのファイルは Visual Studio では編集できません。 `msalENTER_YOUR_CLIENT_ID` 要素を `CFBundleURLSchemes` キーの下に配置します。 77 | 78 | 4. `ENTER_YOUR_CLIENT_ID` を、アプリの登録時に取得したアプリケーション ID の値と置き換えます。 アプリケーション ID の前に `msal` を保持してください。 結果の文字列値は、次のようになります: `msal`。 79 | 80 | 5. UserDetailsClient.Droid\Properties\AndroidManifest.xml ファイルを開きます。 次の要素を検索します: ``。 81 | 82 | 6. `ENTER_YOUR_CLIENT_ID` を、アプリの登録時に取得したアプリケーション ID の値と置き換えます。 アプリケーション ID の前に `msal` を保持してください。 結果の文字列値は、次のようになります: ``。 83 | 84 | 7. 実行するプロジェクトを選びます。ユニバーサル Windows プラットフォームのオプションを選択すると、ローカル コンピューターでサンプルを実行できます。iOS プロジェクトを実行する場合は、[Xamarin ツールがインストールされた Mac](https://developer.xamarin.com/guides/ios/getting_started/installation/windows/connecting-to-mac/) に接続する必要があります。(また、このソリューションを Mac 上の Xamarin Studio で開いて、そこからサンプルを直接実行することもできます。)Android プロジェクトを実行する場合は、[Visual Studio Emulator for Android](https://www.visualstudio.com/features/msft-android-emulator-vs.aspx) を使用できます。 85 | 86 | ![](/readme-images/SelectProject.png "Select project in Visual Studio") 87 | 88 | 8. F5 キーを押して、ビルドとデバッグを実行します。 ソリューションを実行し、個人用アカウント、あるいは職場または学校のアカウントのいずれかでサインインします。 89 | > **注** ビルド構成マネージャーを開いて、ビルドと展開の手順が UWP プロジェクトに対して選択されていることを確認することが必要な場合があります。 90 | 91 | | UWP | Android | iOS | 92 | | --- | ------- | ----| 93 | | Connect sample on UWP | Connect sample on Android | Connect sample on iOS | 94 | 95 | ### 主なメソッドの概要 96 | 97 | アプリのメイン ページのコードは、比較的単純なため説明が必要ありません。これは認証とメール サービスの呼び出しが実際にはヘルパー クラスで発生するためです。メイン ページのコードは、主に 2 つのボタン用のイベント ハンドラーで構成されています: 98 | 99 | - **OnSignInSignOut** 100 | 101 | このボタンのテキスト値が "connect" の場合、このメソッドは **GetAuthenticatedClient** メソッドを呼び出して、現在のユーザーを表す **GraphServicesClient** オブジェクトを取得します。これはユーザーのメール アドレスと表示名を設定するために使用されます。これが成功すると、**[メールの送信]** ボタンとユーザーがメール アドレスを入力できるテキスト ボックスも有効になり、ユーザー独自のメール アドレスがそのテキスト ボックスに設定されます。 102 | 103 | - **MailButton_Click** 104 | 105 | このメソッドは、**ConnectButton_Click** 中に設定されたメール アドレスと表示名の各変数を使用して、**ComposeAndSendMailAsync** メソッドを呼び出します。このメソッドの呼び出しが成功した場合、これに応じて、UI テキストも更新されます。 106 | 107 | この点を考慮して、ヘルパー クラスの 2 つのメソッドをもう少し詳しく調べてみる必要があります: 108 | 109 | - **GetAuthenticatedClient** 110 | 111 | **AuthenticationHelper** クラスのこのメソッドは、Microsoft 認証ライブラリ (MSAL) を使用してユーザーを認証します。 112 | 113 | これは、MSAL の **PublicClientApplication** オブジェクトから認証トークンを取得して、そのトークンを Microsoft Graph の **DelegateAuthenticationProvider** オブジェクトに渡すことで行われます。 114 | 115 | メイン ページの **SignInCurrentUserAsync** メソッドは、この **GraphServicesClient** オブジェクトからユーザーを読み取って、ユーザーのメール アドレスと表示名を設定することができるようになります。 116 | 117 | - **ComposeAndSendMailAsync** 118 | 119 | **MailHelper** クラスのこのメソッドは、サンプルのメールを作成して送信します。 120 | 121 | 122 | ## 投稿 ## 123 | 124 | このサンプルに投稿する場合は、[CONTRIBUTING.MD](/CONTRIBUTING.md) を参照してください。 125 | 126 | このプロジェクトでは、[Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/) が採用されています。詳細については、「[規範に関する FAQ](https://opensource.microsoft.com/codeofconduct/faq/)」を参照してください。または、その他の質問やコメントがあれば、[opencode@microsoft.com](mailto:opencode@microsoft.com) までにお問い合わせください。 127 | 128 | 129 | ## 質問とコメント 130 | 131 | Xamarin.Forms プロジェクト用 Microsoft Graph Connect のサンプルに関するフィードバックをお寄せください。質問や提案につきましては、このリポジトリの「[問題](https://github.com/MicrosoftGraph/xamarin-csharp-connect-sample/issues)」セクションで送信できます。 132 | 133 | お客様からのフィードバックを重視しています。[スタック オーバーフロー](http://stackoverflow.com/questions/tagged/office365+or+microsoftgraph)でご連絡いただけます。ご質問には [MicrosoftGraph] のタグを付けてください。 134 | 135 | 136 | ## 追加リソース ## 137 | 138 | - [その他の Microsoft Graph Connect サンプル](https://github.com/MicrosoftGraph?utf8=%E2%9C%93&query=-Connect) 139 | - [Microsoft Graph の概要](http://graph.microsoft.io) 140 | - [Office 開発者向けコード サンプル](http://dev.office.com/code-samples) 141 | - [Office デベロッパー センター](http://dev.office.com/) 142 | 143 | 144 | ## 著作権 145 | Copyright (c) 2016 Microsoft. All rights reserved. 146 | 147 | 148 | -------------------------------------------------------------------------------- /README-Localized/README-zh-cn.md: -------------------------------------------------------------------------------- 1 | # Xamarin Forms 的 Microsoft Graph 连接示例 2 | 3 | ## 目录 4 | 5 | * [简介](#introduction) 6 | * [先决条件](#prerequisites) 7 | * [注册和配置应用](#register) 8 | * [构建和调试](#build) 9 | * [问题和意见](#questions) 10 | * [其他资源](#additional-resources) 11 | 12 | 13 | ## 简介 14 | 15 | 此示例展示了如何使用 Microsoft Graph API 将 Xamarin Forms 应用连接到 Microsoft 工作或学校帐户 (Azure Active Directory) 或个人 (Microsoft) 帐户,从而检索用户的个人资料照片,将此照片上传到 OneDrive,并发送将此照片作为附件且文本中包含共享链接的电子邮件。 它使用 [Microsoft Graph .NET 客户端 SDK](https://github.com/microsoftgraph/msgraph-sdk-dotnet) 来处理 Microsoft Graph 返回的数据。 16 | 17 | 此外,此示例使用 [Microsoft 身份验证库 (MSAL)](https://www.nuget.org/packages/Microsoft.Identity.Client/) 进行身份验证。MSAL SDK 提供可使用 [Azure AD v2.0 终结点](https://msdn.microsoft.com/office/office365/howto/authenticate-Office-365-APIs-using-v2)的功能,借助该终结点,开发人员可以编写单个代码流来处理对用户的工作或学校和个人帐户的身份验证。 18 | 19 | 如果想要在你自己的 Xamarin Forms 应用中使用 MSAL,请遵循 [使用 MSAL 设置 Xamarin Forms 项目的这些说明](https://github.com/microsoftgraph/xamarin-csharp-connect-sample/wiki/Set-up-a-Xamarin-Forms-project-to-use-the-MSAL-.NET-SDK)。 20 | 21 | ## 有关 MSAL 预览版的重要说明 22 | 23 | 此库适用于生产环境。 我们为此库提供的生产级支持与为当前生产库提供的支持相同。 在预览期间,我们可能会更改 API、内部缓存格式和此库的其他机制,必须接受这些更改以及 bug 修复或功能改进。 这可能会影响应用。 例如,缓存格式更改可能会对用户造成影响,如要求用户重新登录。 API 更改可能会要求更新代码。 在我们提供通用版后,必须在 6 个月内更新到通用版,因为使用预览版库编写的应用可能不再可用。 24 | 25 | 26 | ## 先决条件 ## 27 | 28 | 此示例需要以下各项: 29 | 30 | * [Visual Studio 2015](https://www.visualstudio.com/downloads) 31 | * [Visual Studio 的 Xamarin](https://www.xamarin.com/visual-studio) 32 | * Windows 10([已启用开发模式](https://msdn.microsoft.com/library/windows/apps/xaml/dn706236.aspx)) 33 | * [Microsoft](https://www.outlook.com) 或 [Office 365 商业版帐户](https://msdn.microsoft.com/office/office365/howto/setup-development-environment#bk_Office365Account) 34 | 35 | 如果想要在此示例中运行 iOS 项目,则要求如下: 36 | 37 | * 最新的 iOS SDK 38 | * Xcode 的最新版本 39 | * Mac OS X Yosemite (10.10) 和更高版本 40 | * [Xamarin.iOS](https://developer.xamarin.com/guides/ios/getting_started/installation/mac/) 41 | * [连接到 Visual Studio 的 Xamarin Mac 代理](https://developer.xamarin.com/guides/ios/getting_started/installation/windows/connecting-to-mac/) 42 | 43 | 如果想要运行 Android 项目,可以使用 [适用于 Android 的 Visual Studio 模拟器](https://www.visualstudio.com/features/msft-android-emulator-vs.aspx)。 44 | 45 | 46 | ## 注册和配置应用 47 | 48 | 1. 使用个人或工作或学校帐户登录到 [应用注册门户](https://apps.dev.microsoft.com/)。 49 | 2. 选择“添加应用”****。 50 | 3. 输入应用名称,然后选择“创建”****。 51 | 52 | 此时,注册页显示,其中列出了应用属性。 53 | 54 | 4. 在“平台”****下,选择“添加平台”****。 55 | 5. 选择“本机应用”****。 56 | 6. 复制“应用 ID”值,以及在添加“本机应用”****平台时创建的“自定义重定向 URI”值(在“本机应用”****标头下)。 此 URI 应包含应用 ID 值,格式如下:`msal://auth`。需要在示例应用中输入这些值。 57 | 58 | 应用 ID 是应用的唯一标识符。 59 | 60 | 7. 选择“**保存**”。 61 | 62 | 63 | ## 构建和调试 ## 64 | 65 | **注意:**如果在第 12 步安装包时看到任何错误消息,请确保解决方案的本地路径并不是太长/太深。若要解决此问题,可以将解决方案移到更接近驱动器根目录的位置。 66 | 67 | 1. 打开解决方案的 **XamarinConnect(可移植)**项目内的 App.cs 文件。 68 | 69 | ![](/readme-images/Appdotcs.png "Open App.cs file in XamarinConnect project") 70 | 71 | 2. 在 Visual Studio 中加载解决方案后,通过将注册的客户端 ID 生成为 App.cs 文件中的 **ClientId** 变量来配置使用注册的客户端 ID 的示例。 72 | 73 | 74 | ![](/readme-images/appId.png "Client ID value in App.cs file") 75 | 76 | 3. 在文本编辑器中,打开 UserDetailsClient.iOS\info.plist 文件。 遗憾的是,不能在 Visual Studio 中编辑此文件。 在 `CFBundleURLSchemes` 键下查找 `msalENTER_YOUR_CLIENT_ID` 元素。 77 | 78 | 4. 将 `ENTER_YOUR_CLIENT_ID` 替换成注册应用时获取的应用 ID 值。 请务必保留应用 ID 前面的 `msal`。 生成的字符串值应如下所示:`msal`。 79 | 80 | 5. 打开 UserDetailsClient.Droid\Properties\AndroidManifest.xml 文件。 查找以下元素:``。 81 | 82 | 6. 将 `ENTER_YOUR_CLIENT_ID` 替换成注册应用时获取的应用 ID 值。 请务必保留应用 ID 前面的 `msal`。 生成的字符串值应如下所示:``。 83 | 84 | 7. 选择想要运行的项目。如果选择“通用 Windows 平台”选项,则可以在本地计算机上运行示例。如果想要运行 iOS 项目,则需连接到安装在其上的 [具有 Xamarin 工具的 Mac](https://developer.xamarin.com/guides/ios/getting_started/installation/windows/connecting-to-mac/)。(还可以在 Mac 上的 Xamarin Studio 中打开此解决方案并直接从此处运行示例。)如果想要运行 Android 项目,可以使用[适用于 Android 的 Visual Studio 模拟器](https://www.visualstudio.com/features/msft-android-emulator-vs.aspx)。 85 | 86 | ![](/readme-images/SelectProject.png "Select project in Visual Studio") 87 | 88 | 8. 按 F5 生成和调试应用。运行此解决方案并使用个人或工作或学校帐户登录。 89 | > **注意** 可能需要打开生成配置管理器,以确保为 UWP 项目选择“生成”和“部署”步骤。 90 | 91 | | UWP | Android | iOS | 92 | | --- | ------- | ----| 93 | | Connect sample on UWP | Connect sample on Android | Connect sample on iOS | 94 | 95 | ### 密钥方法摘要 96 | 97 | 应用主页中的代码相对简单且一目了然,因为对身份验证和电子邮件服务的调用实际出现在帮助程序类中。主页代码主要包括两个按钮的事件处理程序: 98 | 99 | - **OnSignInSignOut** 100 | 101 | 当该按钮的文本值为“连接”时,该方法将调用 **GetAuthenticatedClient** 方法以获取表示当前用户的 **GraphServicesClient** 对象(它将使用该对象设置用户电子邮件地址和显示名称)。如果此操作成功,它还会启用“**发送邮件**”按钮和文本框(用户可以在此处输入电子邮件地址,并使用用户自己的电子邮件地址填充该文本框)。 102 | 103 | - **MailButton_Click** 104 | 105 | 此方法通过在 **ConnectButton_Click** 过程中使用电子邮件地址和显示名称变量设置来调用 **ComposeAndSendMailAsync** 方法。如果此方法调用成功,它还将据此更新 UI 文本。 106 | 107 | 明确这一点后,需要更详细了解帮助程序类中的两种方法: 108 | 109 | - **GetAuthenticatedClient** 110 | 111 | **AuthenticationHelper** 类的此方法使用 Microsoft 身份验证库 (MSAL).对用户进行身份验证。 112 | 113 | 它通过检索 MSAL **PublicClientApplication** 对象的身份验证令牌,然后将该令牌传递给 Microsoft Graph **DelegateAuthenticationProvider** 对象来实现此操作。 114 | 115 | 然后,主页上的 **SignInCurrentUserAsync** 方法可以从该 **GraphServicesClient** 对象读取用户,并设置用户电子邮件地址和显示名称。 116 | 117 | - **ComposeAndSendMailAsync** 118 | 119 | **MailHelper** 类的此方法撰写并发送示例电子邮件。 120 | 121 | 122 | ## 参与 ## 123 | 124 | 如果想要参与本示例,请参阅 [CONTRIBUTING.MD](/CONTRIBUTING.md)。 125 | 126 | 此项目采用 [Microsoft 开源行为准则](https://opensource.microsoft.com/codeofconduct/)。有关详细信息,请参阅 [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)(行为准则常见问题解答),有任何其他问题或意见,也可联系 [opencode@microsoft.com](mailto:opencode@microsoft.com)。 127 | 128 | 129 | ## 问题和意见 130 | 131 | 我们乐意倾听你有关 Xamarin Forms 项目的 Microsoft Graph 连接示例的反馈。你可以在该存储库中的 [问题](https://github.com/MicrosoftGraph/xamarin-csharp-connect-sample/issues) 部分将问题和建议发送给我们。 132 | 133 | 我们非常重视你的反馈意见。请在 [Stack Overflow](http://stackoverflow.com/questions/tagged/office365+or+microsoftgraph) 上与我们联系。使用 [MicrosoftGraph] 标记出你的问题。 134 | 135 | 136 | ## 其他资源 ## 137 | 138 | - [其他 Microsoft Graph Connect 示例](https://github.com/MicrosoftGraph?utf8=%E2%9C%93&query=-Connect) 139 | - [Microsoft Graph 概述](http://graph.microsoft.io) 140 | - [Office 开发人员代码示例](http://dev.office.com/code-samples) 141 | - [Office 开发人员中心](http://dev.office.com/) 142 | 143 | 144 | ## 版权 145 | 版权所有 (c) 2016 Microsoft。保留所有权利。 146 | 147 | 148 | -------------------------------------------------------------------------------- /README-Localized/README-zh-tw.md: -------------------------------------------------------------------------------- 1 | # Microsoft Graph Connect 範例 (適用於 Xamarin Forms) 2 | 3 | ## 目錄 4 | 5 | * [簡介](#introduction) 6 | * [必要條件](#prerequisites) 7 | * [註冊和設定應用程式](#register) 8 | * [建置及偵錯](#build) 9 | * [問題和建議](#questions) 10 | * [其他資源](#additional-resources) 11 | 12 | 13 | ## 簡介 14 | 15 | 這個範例會顯示如何使用 Microsoft Graph API 將 Xamarin Forms 應用程式連線至 Microsoft 工作或學校 (Azure Active Directory) 或個人 (Microsoft) 帳戶,用來擷取使用者的基本資料圖片、將圖片上傳至 OneDrive,並傳送含有相片作為附件且文字中包含共用連結的電子郵件。 它會使用 [Microsoft Graph.NET 用戶端 SDK](https://github.com/microsoftgraph/msgraph-sdk-dotnet),使用 Microsoft Graph 所傳回的資料。 16 | 17 | 此外,範例會使用 [Microsoft 驗證程式庫 (MSAL)](https://www.nuget.org/packages/Microsoft.Identity.Client/) 進行驗證。MSAL SDK 提供功能以使用 [Azure AD v2.0 端點](https://msdn.microsoft.com/office/office365/howto/authenticate-Office-365-APIs-using-v2),可讓開發人員撰寫單一程式碼流程,處理使用者的工作或學校和個人帳戶的驗證。 18 | 19 | 如果您想要在自己的 Xamarin Forms 應用程式中使用 MSAL,請遵循[這些指示以設定 Xamarin Forms 專案與 MSAL](https://github.com/microsoftgraph/xamarin-csharp-connect-sample/wiki/Set-up-a-Xamarin-Forms-project-to-use-the-MSAL-.NET-SDK)。 20 | 21 | ## MSAL 預覽相關的重要事項 22 | 23 | 這個程式庫適合在實際執行環境中使用。 我們為我們目前的實際執行程式庫提供與此程式庫相同的實際執行層級支援。 在預覽期間,我們可能會變更此程式庫的 API、內部快取格式和其他機制,您將必須對此程式庫進行錯誤修復或增強功能。 這可能會影響您的應用程式。 舉例來說,變更快取格式可能會影響您的使用者,例如需要使用者重新登入。 API 變更可能需要更新您的程式碼。 當我們提供「一般可用性」版本時,將要求您在六個月內更新至「一般可用性」版本,因為使用程式庫預覽版本所撰寫的應用程式可能無法運作。 24 | 25 | 26 | ## 必要條件 ## 27 | 28 | 此範例需要下列項目: 29 | 30 | * [Visual Studio 2015](https://www.visualstudio.com/downloads) 31 | * [Xamarin for Visual Studio](https://www.xamarin.com/visual-studio) 32 | * Windows 10 ([已啟用開發模式](https://msdn.microsoft.com/library/windows/apps/xaml/dn706236.aspx)) 33 | * [Microsoft](https://www.outlook.com) 或[商務用 Office 365 帳戶](https://msdn.microsoft.com/office/office365/howto/setup-development-environment#bk_Office365Account) 34 | 35 | 如果您想要執行這個範例中的 iOS 專案,您需要下列項目: 36 | 37 | * 最新的 iOS SDK 38 | * 最新版本的 Xcode 39 | * Mac OS X Yosemite(10.10) 和更新版本 40 | * [Xamarin.iOS](https://developer.xamarin.com/guides/ios/getting_started/installation/mac/) 41 | * [連接至 Visual Studio 的 Xamarin Mac 代理程式](https://developer.xamarin.com/guides/ios/getting_started/installation/windows/connecting-to-mac/) 42 | 43 | 如果您想要執行 Android 專案,您可以使用[適用於 Android 的 Visual Studio 模擬器](https://www.visualstudio.com/features/msft-android-emulator-vs.aspx)。 44 | 45 | 46 | ## 註冊和設定應用程式 47 | 48 | 1. 使用您的個人或工作或學校帳戶登入[應用程式註冊入口網站](https://apps.dev.microsoft.com/)。 49 | 2. 選取 [新增應用程式]****。 50 | 3. 為應用程式輸入名稱,然後選取 [建立]****。 51 | 52 | [註冊] 頁面隨即顯示,列出您的應用程式的屬性。 53 | 54 | 4. 在 [平台]**** 底下,選取 [新增平台]****。 55 | 5. 選取 [原生應用程式]****。 56 | 6. 複製「應用程式識別碼」值和「自訂重新導向 URI」值 (在**原生應用程式**標頭下),這是在您新增 [原生應用程式]**** 平台時所建立的。 此 URI 應包含您的應用程式識別碼值,且格式如下︰`msal://auth`您必須將這些值輸入範例應用程式中。 57 | 58 | 應用程式識別碼是您的應用程式的唯一識別碼。 59 | 60 | 7. 選取 [儲存]****。 61 | 62 | 63 | ## 建置和偵錯 ## 64 | 65 | **附註:**如果您在步驟 12 安裝封裝時看到任何錯誤,請確定您放置解決方案的本機路徑不會太長/太深。將解決方案移靠近您的磁碟機根目錄可解決這個問題。 66 | 67 | 1. 開啟解決方案的 **XamarinConnect (可攜式)** 專案內的 App.cs 檔案。 68 | 69 | ![](/readme-images/Appdotcs.png "Open App.cs file in XamarinConnect project") 70 | 71 | 2. 在 Visual Studio 中載入解決方案之後,設定範例以使用用戶端識別碼,該識別碼是您藉由讓其成為 App.cs 檔案中的 **ClientId** 變數的值來註冊的。 72 | 73 | 74 | ![](/readme-images/appId.png "Client ID value in App.cs file") 75 | 76 | 3. 在文字編輯器中開啟 UserDetailsClient.iOS\info.plist 檔案。 不幸的是,您無法在 Visual Studio 中編輯這個檔案。 在 `CFBundleURLSchemes` 機碼下找到的 `msalENTER_YOUR_CLIENT_ID` 元素。 77 | 78 | 4. 將 `ENTER_YOUR_CLIENT_ID` 取代註冊您的應用程式時所獲得的應用程式識別碼值。 請務必在應用程式識別碼之前保留 `msal`。 產生的字串值應如下所示︰`msal`。 79 | 80 | 5. 開啟 UserDetailsClient.Droid\Properties\AndroidManifest.xml 檔案。 找到此元素︰``。 81 | 82 | 6. 將 `ENTER_YOUR_CLIENT_ID` 取代註冊您的應用程式時所獲得的應用程式識別碼值。 請務必在應用程式識別碼之前保留 `msal`。 產生的字串值應如下所示︰``。 83 | 84 | 7. 選取您要執行的專案。如果您選取 [通用 Windows 平台] 選項,您可以在本機機器上執行範例。如果您想要執行 iOS 專案,您必須連接至[已安裝 Xamarin 工具的 Mac](https://developer.xamarin.com/guides/ios/getting_started/installation/windows/connecting-to-mac/)。(您也可以在 Mac 上,在 Xamarin Studio 中開啟此解決方案,然後直接從那裡執行範例。)如果您想要執行 Android 專案,您可以使用[適用於 Android 的 Visual Studio 模擬器](https://www.visualstudio.com/features/msft-android-emulator-vs.aspx)。 85 | 86 | ![](/readme-images/SelectProject.png "Select project in Visual Studio") 87 | 88 | 8. 按 F5 進行建置和偵錯。執行解決方案並且登入您的個人或工作或學校帳戶。 89 | > **附註** 您可能必須開啟組建組態管理員,以確定針對 UWP 專案選取建置和部署步驟。 90 | 91 | | UWP | Android | iOS | 92 | | --- | ------- | ----| 93 | | Connect sample on UWP | Connect sample on Android | Connect sample on iOS | 94 | 95 | ### 主要方法的摘要 96 | 97 | 應用程式的主頁面中的程式碼相當直覺且淺顯易懂,因為驗證和電子郵件服務的呼叫確實在協助程式類別中發生。主頁面程式碼主要包含兩個按鈕的事件處理常式: 98 | 99 | - **OnSignInSignOut** 100 | 101 | 當此按鈕的文字值為「連接」時,此方法會呼叫 **GetAuthenticatedClient** 方法以取得 **GraphServicesClient** 物件,代表目前的使用者,用來設定使用者電子郵件地址和顯示名稱。如果成功,它也可以啟用 [傳送郵件]**** 按鈕和使用者可以在其中輸入電子郵件地址的文字方塊,並且在該文字方塊中填入使用者自己的電子郵件地址。 102 | 103 | - **MailButton_Click** 104 | 105 | 這個方法會呼叫 **ComposeAndSendMailAsync** 方法,使用在 **ConnectButton_Click** 期間設定的電子郵件地址和顯示名稱變數。如果這個方法呼叫成功,它也會據以更新 UI 文字。 106 | 107 | 謹記這一點,再詳細一些查看協助程式類別中的兩種方法很值得: 108 | 109 | - **GetAuthenticatedClient** 110 | 111 | **AuthenticationHelper** 類別的這個方法會使用 Microsoft 驗證程式庫 (MSAL) 驗證使用者。 112 | 113 | 其作法是從 MSAL **PublicClientApplication** 物件擷取驗證權杖,然後將該權杖傳遞至 Microsoft Graph **DelegateAuthenticationProvider** 物件。 114 | 115 | 然後主頁面上的 **SignInCurrentUserAsync** 方法可以從這個 **GraphServicesClient** 物件讀取使用者,然後設定使用者的電子郵件地址和顯示名稱。 116 | 117 | - **ComposeAndSendMailAsync** 118 | 119 | **MailHelper** 類別的這個方法會撰寫並傳送範例電子郵件。 120 | 121 | 122 | ## 參與 ## 123 | 124 | 如果您想要參與這個範例,請參閱 [CONTRIBUTING.MD](/CONTRIBUTING.md)。 125 | 126 | 此專案已採用 [Microsoft 開放原始碼執行](https://opensource.microsoft.com/codeofconduct/)。如需詳細資訊,請參閱[程式碼執行常見問題集](https://opensource.microsoft.com/codeofconduct/faq/),如果有其他問題或意見,請連絡 [opencode@microsoft.com](mailto:opencode@microsoft.com)。 127 | 128 | 129 | ## 問題和建議 130 | 131 | 我們很樂於收到您對於 Microsoft Graph Connect 範例 (適用於 Xamarin Forms) 專案的意見反應。您可以在此儲存機制的[問題](https://github.com/MicrosoftGraph/xamarin-csharp-connect-sample/issues)區段中,將您的問題及建議傳送給我們。 132 | 133 | 我們很重視您的意見。請透過 [Stack Overflow](http://stackoverflow.com/questions/tagged/office365+or+microsoftgraph) 與我們連絡。以 [MicrosoftGraph] 標記您的問題。 134 | 135 | 136 | ## 其他資源 ## 137 | 138 | - [其他 Microsoft Graph connect 範例](https://github.com/MicrosoftGraph?utf8=%E2%9C%93&query=-Connect) 139 | - [Microsoft Graph 概觀](http://graph.microsoft.io) 140 | - [Office 開發人員程式碼範例](http://dev.office.com/code-samples) 141 | - [Office 開發人員中心](http://dev.office.com/) 142 | 143 | 144 | ## 著作權 145 | Copyright (c) 2016 Microsoft.著作權所有,並保留一切權利。 146 | 147 | 148 | -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.Droid/Assets/AboutAssets.txt: -------------------------------------------------------------------------------- 1 | Any raw assets you want to be deployed with your application can be placed in 2 | this directory (and child directories) and given a Build Action of "AndroidAsset". 3 | 4 | These files will be deployed with you package and will be accessible using Android's 5 | AssetManager, like this: 6 | 7 | public class ReadAsset : Activity 8 | { 9 | protected override void OnCreate (Bundle bundle) 10 | { 11 | base.OnCreate (bundle); 12 | 13 | InputStream input = Assets.Open ("my_asset.txt"); 14 | } 15 | } 16 | 17 | Additionally, some Android functions will automatically load asset files: 18 | 19 | Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf"); 20 | -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.Droid/MainActivity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Android.App; 4 | using Android.Content; 5 | using Android.Content.PM; 6 | using Android.Runtime; 7 | using Android.Views; 8 | using Android.Widget; 9 | using Android.OS; 10 | using Microsoft.Identity.Client; 11 | 12 | namespace XamarinConnect.Droid 13 | { 14 | [Activity(Label = "XamarinConnect", Icon = "@drawable/icon", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] 15 | public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity 16 | { 17 | protected override void OnCreate(Bundle bundle) 18 | { 19 | base.OnCreate(bundle); 20 | 21 | global::Xamarin.Forms.Forms.Init(this, bundle); 22 | LoadApplication(new App()); 23 | App.IdentityClientApp.RedirectUri = App.RedirectUri; 24 | App.UiParent = new UIParent(Xamarin.Forms.Forms.Context as Activity); 25 | } 26 | 27 | protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) 28 | { 29 | base.OnActivityResult(requestCode, resultCode, data); 30 | AuthenticationContinuationHelper.SetAuthenticationContinuationEventArgs(requestCode, resultCode, data); 31 | } 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.Droid/MainApplication.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Android.App; 4 | using Android.OS; 5 | using Android.Runtime; 6 | using Plugin.CurrentActivity; 7 | 8 | namespace XamarinConnect.Droid 9 | { 10 | //You can specify additional application information in this attribute 11 | [Application] 12 | public class MainApplication : Application, Application.IActivityLifecycleCallbacks 13 | { 14 | public MainApplication(IntPtr handle, JniHandleOwnership transer) 15 | :base(handle, transer) 16 | { 17 | } 18 | 19 | public override void OnCreate() 20 | { 21 | base.OnCreate(); 22 | RegisterActivityLifecycleCallbacks(this); 23 | //A great place to initialize Xamarin.Insights and Dependency Services! 24 | } 25 | 26 | public override void OnTerminate() 27 | { 28 | base.OnTerminate(); 29 | UnregisterActivityLifecycleCallbacks(this); 30 | } 31 | 32 | public void OnActivityCreated(Activity activity, Bundle savedInstanceState) 33 | { 34 | CrossCurrentActivity.Current.Activity = activity; 35 | } 36 | 37 | public void OnActivityDestroyed(Activity activity) 38 | { 39 | } 40 | 41 | public void OnActivityPaused(Activity activity) 42 | { 43 | } 44 | 45 | public void OnActivityResumed(Activity activity) 46 | { 47 | CrossCurrentActivity.Current.Activity = activity; 48 | } 49 | 50 | public void OnActivitySaveInstanceState(Activity activity, Bundle outState) 51 | { 52 | } 53 | 54 | public void OnActivityStarted(Activity activity) 55 | { 56 | CrossCurrentActivity.Current.Activity = activity; 57 | } 58 | 59 | public void OnActivityStopped(Activity activity) 60 | { 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.Droid/MainPageRenderer.cs: -------------------------------------------------------------------------------- 1 | using Android.App; 2 | using Android.Content; 3 | using Android.OS; 4 | using Android.Runtime; 5 | using Android.Views; 6 | using Android.Widget; 7 | using Microsoft.Identity.Client; 8 | using Xamarin.Forms.Platform.Android; 9 | using XamarinConnect; 10 | using Xamarin.Forms; 11 | using XamarinConnect.Droid; 12 | 13 | [assembly: ExportRenderer(typeof(MainPage), typeof(MainPageRenderer))] 14 | namespace XamarinConnect.Droid 15 | { 16 | class MainPageRenderer : PageRenderer 17 | { 18 | MainPage page; 19 | 20 | protected override void OnElementChanged(ElementChangedEventArgs e) 21 | { 22 | base.OnElementChanged(e); 23 | page = e.NewElement as MainPage; 24 | var activity = this.Context as Activity; 25 | } 26 | 27 | } 28 | } -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.Droid/Properties/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.Droid/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | using Android.App; 5 | 6 | // General Information about an assembly is controlled through the following 7 | // set of attributes. Change these attribute values to modify the information 8 | // associated with an assembly. 9 | [assembly: AssemblyTitle("XamarinConnect.Droid")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyConfiguration("")] 12 | [assembly: AssemblyCompany("")] 13 | [assembly: AssemblyProduct("XamarinConnect.Droid")] 14 | [assembly: AssemblyCopyright("Copyright © 2014")] 15 | [assembly: AssemblyTrademark("")] 16 | [assembly: AssemblyCulture("")] 17 | [assembly: ComVisible(false)] 18 | 19 | // Version information for an assembly consists of the following four values: 20 | // 21 | // Major Version 22 | // Minor Version 23 | // Build Number 24 | // Revision 25 | // 26 | // You can specify all the values or you can default the Build and Revision Numbers 27 | // by using the '*' as shown below: 28 | // [assembly: AssemblyVersion("1.0.*")] 29 | [assembly: AssemblyVersion("1.0.0.0")] 30 | [assembly: AssemblyFileVersion("1.0.0.0")] 31 | 32 | // Add some common permissions, these can be removed if not needed 33 | [assembly: UsesPermission(Android.Manifest.Permission.Internet)] 34 | [assembly: UsesPermission(Android.Manifest.Permission.WriteExternalStorage)] 35 | -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.Droid/Resources/AboutResources.txt: -------------------------------------------------------------------------------- 1 | Images, layout descriptions, binary blobs and string dictionaries can be included 2 | in your application as resource files. Various Android APIs are designed to 3 | operate on the resource IDs instead of dealing with images, strings or binary blobs 4 | directly. 5 | 6 | For example, a sample Android app that contains a user interface layout (main.xml), 7 | an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png) 8 | would keep its resources in the "Resources" directory of the application: 9 | 10 | Resources/ 11 | drawable-hdpi/ 12 | icon.png 13 | 14 | drawable-ldpi/ 15 | icon.png 16 | 17 | drawable-mdpi/ 18 | icon.png 19 | 20 | layout/ 21 | main.xml 22 | 23 | values/ 24 | strings.xml 25 | 26 | In order to get the build system to recognize Android resources, set the build action to 27 | "AndroidResource". The native Android APIs do not operate directly with filenames, but 28 | instead operate on resource IDs. When you compile an Android application that uses resources, 29 | the build system will package the resources for distribution and generate a class called 30 | "Resource" that contains the tokens for each one of the resources included. For example, 31 | for the above Resources layout, this is what the Resource class would expose: 32 | 33 | public class Resource { 34 | public class drawable { 35 | public const int icon = 0x123; 36 | } 37 | 38 | public class layout { 39 | public const int main = 0x456; 40 | } 41 | 42 | public class strings { 43 | public const int first_string = 0xabc; 44 | public const int second_string = 0xbcd; 45 | } 46 | } 47 | 48 | You would then use R.drawable.icon to reference the drawable/icon.png file, or Resource.layout.main 49 | to reference the layout/main.xml file, or Resource.strings.first_string to reference the first 50 | string in the dictionary file values/strings.xml. 51 | -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.Droid/Resources/drawable-hdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/xamarin-csharp-connect-sample/ae4b6d2be2ddd0667693245d731d31119259505d/XamarinConnect/XamarinConnect.Droid/Resources/drawable-hdpi/icon.png -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.Droid/Resources/drawable-xhdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/xamarin-csharp-connect-sample/ae4b6d2be2ddd0667693245d731d31119259505d/XamarinConnect/XamarinConnect.Droid/Resources/drawable-xhdpi/icon.png -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.Droid/Resources/drawable-xxhdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/xamarin-csharp-connect-sample/ae4b6d2be2ddd0667693245d731d31119259505d/XamarinConnect/XamarinConnect.Droid/Resources/drawable-xxhdpi/icon.png -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.Droid/Resources/drawable/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/xamarin-csharp-connect-sample/ae4b6d2be2ddd0667693245d731d31119259505d/XamarinConnect/XamarinConnect.Droid/Resources/drawable/icon.png -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.Droid/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.Droid/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.UWP/App.xaml: -------------------------------------------------------------------------------- 1 |  7 | 8 | 9 | -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.UWP/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Runtime.InteropServices.WindowsRuntime; 6 | using Windows.ApplicationModel; 7 | using Windows.ApplicationModel.Activation; 8 | using Windows.Foundation; 9 | using Windows.Foundation.Collections; 10 | using Windows.UI.Xaml; 11 | using Windows.UI.Xaml.Controls; 12 | using Windows.UI.Xaml.Controls.Primitives; 13 | using Windows.UI.Xaml.Data; 14 | using Windows.UI.Xaml.Input; 15 | using Windows.UI.Xaml.Media; 16 | using Windows.UI.Xaml.Navigation; 17 | 18 | namespace XamarinConnect.UWP 19 | { 20 | /// 21 | /// Provides application-specific behavior to supplement the default Application class. 22 | /// 23 | sealed partial class App : Application 24 | { 25 | /// 26 | /// Initializes the singleton application object. This is the first line of authored code 27 | /// executed, and as such is the logical equivalent of main() or WinMain(). 28 | /// 29 | public App() 30 | { 31 | this.InitializeComponent(); 32 | this.Suspending += OnSuspending; 33 | } 34 | 35 | /// 36 | /// Invoked when the application is launched normally by the end user. Other entry points 37 | /// will be used such as when the application is launched to open a specific file. 38 | /// 39 | /// Details about the launch request and process. 40 | protected override void OnLaunched(LaunchActivatedEventArgs e) 41 | { 42 | 43 | #if DEBUG 44 | if (System.Diagnostics.Debugger.IsAttached) 45 | { 46 | this.DebugSettings.EnableFrameRateCounter = true; 47 | } 48 | #endif 49 | 50 | Frame rootFrame = Window.Current.Content as Frame; 51 | 52 | // Do not repeat app initialization when the Window already has content, 53 | // just ensure that the window is active 54 | if (rootFrame == null) 55 | { 56 | // Create a Frame to act as the navigation context and navigate to the first page 57 | rootFrame = new Frame(); 58 | 59 | rootFrame.NavigationFailed += OnNavigationFailed; 60 | 61 | Xamarin.Forms.Forms.Init(e); 62 | 63 | if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) 64 | { 65 | //TODO: Load state from previously suspended application 66 | } 67 | 68 | // Place the frame in the current Window 69 | Window.Current.Content = rootFrame; 70 | } 71 | 72 | if (rootFrame.Content == null) 73 | { 74 | // When the navigation stack isn't restored navigate to the first page, 75 | // configuring the new page by passing required information as a navigation 76 | // parameter 77 | rootFrame.Navigate(typeof(MainPage), e.Arguments); 78 | } 79 | // Ensure the current window is active 80 | Window.Current.Activate(); 81 | } 82 | 83 | /// 84 | /// Invoked when Navigation to a certain page fails 85 | /// 86 | /// The Frame which failed navigation 87 | /// Details about the navigation failure 88 | void OnNavigationFailed(object sender, NavigationFailedEventArgs e) 89 | { 90 | throw new Exception("Failed to load Page " + e.SourcePageType.FullName); 91 | } 92 | 93 | /// 94 | /// Invoked when application execution is being suspended. Application state is saved 95 | /// without knowing whether the application will be terminated or resumed with the contents 96 | /// of memory still intact. 97 | /// 98 | /// The source of the suspend request. 99 | /// Details about the suspend request. 100 | private void OnSuspending(object sender, SuspendingEventArgs e) 101 | { 102 | var deferral = e.SuspendingOperation.GetDeferral(); 103 | //TODO: Save application state and stop any background activity 104 | deferral.Complete(); 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.UWP/Assets/LockScreenLogo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/xamarin-csharp-connect-sample/ae4b6d2be2ddd0667693245d731d31119259505d/XamarinConnect/XamarinConnect.UWP/Assets/LockScreenLogo.scale-200.png -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.UWP/Assets/SplashScreen.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/xamarin-csharp-connect-sample/ae4b6d2be2ddd0667693245d731d31119259505d/XamarinConnect/XamarinConnect.UWP/Assets/SplashScreen.scale-200.png -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.UWP/Assets/Square150x150Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/xamarin-csharp-connect-sample/ae4b6d2be2ddd0667693245d731d31119259505d/XamarinConnect/XamarinConnect.UWP/Assets/Square150x150Logo.scale-200.png -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.UWP/Assets/Square44x44Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/xamarin-csharp-connect-sample/ae4b6d2be2ddd0667693245d731d31119259505d/XamarinConnect/XamarinConnect.UWP/Assets/Square44x44Logo.scale-200.png -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.UWP/Assets/Square44x44Logo.targetsize-24_altform-unplated.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/xamarin-csharp-connect-sample/ae4b6d2be2ddd0667693245d731d31119259505d/XamarinConnect/XamarinConnect.UWP/Assets/Square44x44Logo.targetsize-24_altform-unplated.png -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.UWP/Assets/StoreLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/xamarin-csharp-connect-sample/ae4b6d2be2ddd0667693245d731d31119259505d/XamarinConnect/XamarinConnect.UWP/Assets/StoreLogo.png -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.UWP/Assets/Wide310x150Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/xamarin-csharp-connect-sample/ae4b6d2be2ddd0667693245d731d31119259505d/XamarinConnect/XamarinConnect.UWP/Assets/Wide310x150Logo.scale-200.png -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.UWP/MainPage.xaml: -------------------------------------------------------------------------------- 1 |  10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.UWP/MainPage.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Runtime.InteropServices.WindowsRuntime; 6 | using Windows.Foundation; 7 | using Windows.Foundation.Collections; 8 | using Windows.UI.Xaml; 9 | using Windows.UI.Xaml.Controls; 10 | using Windows.UI.Xaml.Controls.Primitives; 11 | using Windows.UI.Xaml.Data; 12 | using Windows.UI.Xaml.Input; 13 | using Windows.UI.Xaml.Media; 14 | using Windows.UI.Xaml.Navigation; 15 | 16 | namespace XamarinConnect.UWP 17 | { 18 | public sealed partial class MainPage 19 | { 20 | public MainPage() 21 | { 22 | this.InitializeComponent(); 23 | 24 | LoadApplication(new XamarinConnect.App()); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.UWP/Package.appxmanifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 8 | 9 | 13 | 14 | 15 | 16 | 17 | FPCL.WIndows 18 | joaqu 19 | Assets\StoreLogo.png 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 34 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.UWP/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("XamarinConnect.UWP")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("XamarinConnect.UWP")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Version information for an assembly consists of the following four values: 18 | // 19 | // Major Version 20 | // Minor Version 21 | // Build Number 22 | // Revision 23 | // 24 | // You can specify all the values or you can default the Build and Revision Numbers 25 | // by using the '*' as shown below: 26 | // [assembly: AssemblyVersion("1.0.*")] 27 | [assembly: AssemblyVersion("1.0.0.0")] 28 | [assembly: AssemblyFileVersion("1.0.0.0")] 29 | [assembly: ComVisible(false)] -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.UWP/Properties/Default.rd.xml: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.UWP/XamarinConnect.UWP.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | x86 7 | {552CEAE3-168A-4293-8E77-6A84846ACD6C} 8 | AppContainerExe 9 | Properties 10 | XamarinConnect.UWP 11 | XamarinConnect.UWP 12 | en-US 13 | UAP 14 | 10.0.16299.0 15 | 10.0.10586.0 16 | 14 17 | true 18 | 512 19 | {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 20 | Windows_TemporaryKey.pfx 21 | 22 | 23 | true 24 | bin\ARM\Debug\ 25 | DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP 26 | ;2008 27 | full 28 | ARM 29 | false 30 | prompt 31 | true 32 | 33 | 34 | bin\ARM\Release\ 35 | TRACE;NETFX_CORE;WINDOWS_UWP 36 | true 37 | ;2008 38 | pdbonly 39 | ARM 40 | false 41 | prompt 42 | true 43 | true 44 | 45 | 46 | true 47 | bin\x64\Debug\ 48 | DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP 49 | ;2008 50 | full 51 | x64 52 | false 53 | prompt 54 | true 55 | 56 | 57 | bin\x64\Release\ 58 | TRACE;NETFX_CORE;WINDOWS_UWP 59 | true 60 | ;2008 61 | pdbonly 62 | x64 63 | false 64 | prompt 65 | true 66 | true 67 | 68 | 69 | true 70 | bin\x86\Debug\ 71 | DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP 72 | ;2008 73 | full 74 | x86 75 | false 76 | prompt 77 | true 78 | 79 | 80 | bin\x86\Release\ 81 | TRACE;NETFX_CORE;WINDOWS_UWP 82 | true 83 | ;2008 84 | pdbonly 85 | x86 86 | false 87 | prompt 88 | true 89 | true 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | App.xaml 98 | 99 | 100 | MainPage.xaml 101 | 102 | 103 | 104 | 105 | 106 | Designer 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | MSBuild:Compile 123 | Designer 124 | 125 | 126 | MSBuild:Compile 127 | Designer 128 | 129 | 130 | 131 | 132 | XamarinConnect 133 | 134 | 135 | 136 | 14.0 137 | 138 | 139 | 146 | -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.UWP/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "Microsoft.Identity.Client": "1.1.2-preview0008", 4 | "Microsoft.NETCore.UniversalWindowsPlatform": "5.3.1", 5 | "Xamarin.Forms": "2.5.0.122203" 6 | }, 7 | "frameworks": { 8 | "uap10.0.10586": {} 9 | }, 10 | "runtimes": { 11 | "win10-arm": {}, 12 | "win10-arm-aot": {}, 13 | "win10-x86": {}, 14 | "win10-x86-aot": {}, 15 | "win10-x64": {}, 16 | "win10-x64-aot": {} 17 | } 18 | } -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.iOS/AppDelegate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | using Foundation; 6 | using UIKit; 7 | using Microsoft.Identity.Client; 8 | 9 | namespace XamarinConnect.iOS 10 | { 11 | // The UIApplicationDelegate for the application. This class is responsible for launching the 12 | // User Interface of the application, as well as listening (and optionally responding) to 13 | // application events from iOS. 14 | [Register("AppDelegate")] 15 | public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate 16 | { 17 | // 18 | // This method is invoked when the application has loaded and is ready to run. In this 19 | // method you should instantiate the window, load the UI into it and then make the window 20 | // visible. 21 | // 22 | // You have 17 seconds to return from this method, or iOS will terminate your application. 23 | // 24 | public override bool FinishedLaunching(UIApplication app, NSDictionary options) 25 | { 26 | global::Xamarin.Forms.Forms.Init(); 27 | LoadApplication(new App()); 28 | App.IdentityClientApp.RedirectUri = App.RedirectUri; 29 | return base.FinishedLaunching(app, options); 30 | 31 | } 32 | 33 | public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options) 34 | { 35 | AuthenticationContinuationHelper.SetAuthenticationContinuationEventArgs(url); 36 | return true; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.iOS/Entitlements.plist: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.iOS/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | UIDeviceFamily 6 | 7 | 1 8 | 2 9 | 10 | UISupportedInterfaceOrientations 11 | 12 | UIInterfaceOrientationPortrait 13 | UIInterfaceOrientationLandscapeLeft 14 | UIInterfaceOrientationLandscapeRight 15 | 16 | UISupportedInterfaceOrientations~ipad 17 | 18 | UIInterfaceOrientationPortrait 19 | UIInterfaceOrientationPortraitUpsideDown 20 | UIInterfaceOrientationLandscapeLeft 21 | UIInterfaceOrientationLandscapeRight 22 | 23 | CFBundleURLTypes 24 | 25 | 26 | CFBundleTypeRole 27 | Editor 28 | CFBundleURLName 29 | com.yourcompany.UserDetailsClient 30 | CFBundleURLSchemes 31 | 32 | msalENTER_YOUR_CLIENT_ID 33 | 34 | 35 | 36 | MinimumOSVersion 37 | 7.0 38 | CFBundleDisplayName 39 | XamarinConnect 40 | CFBundleIdentifier 41 | com.yourcompany.XamarinConnect 42 | CFBundleVersion 43 | 1.0 44 | CFBundleIconFiles 45 | 46 | Icon-60@2x 47 | Icon-60@3x 48 | Icon-76 49 | Icon-76@2x 50 | Default 51 | Default@2x 52 | Default-568h@2x 53 | Default-Portrait 54 | Default-Portrait@2x 55 | Icon-Small-40 56 | Icon-Small-40@2x 57 | Icon-Small-40@3x 58 | Icon-Small 59 | Icon-Small@2x 60 | Icon-Small@3x 61 | 62 | UILaunchStoryboardName 63 | LaunchScreen 64 | 65 | 66 | -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.iOS/Main.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | using Foundation; 6 | using UIKit; 7 | 8 | namespace XamarinConnect.iOS 9 | { 10 | public class Application 11 | { 12 | // This is the main entry point of the application. 13 | static void Main(string[] args) 14 | { 15 | // if you want to use a different Application Delegate class from "AppDelegate" 16 | // you can specify it here. 17 | UIApplication.Main(args, null, "AppDelegate"); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.iOS/MainPageRenderer.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Identity.Client; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | using XamarinConnect; 6 | using XamarinConnect.iOS; 7 | using Xamarin.Forms; 8 | using Xamarin.Forms.Platform.iOS; 9 | 10 | [assembly: ExportRenderer(typeof(MainPage), typeof(MainPageRenderer))] 11 | namespace XamarinConnect.iOS 12 | { 13 | class MainPageRenderer : PageRenderer 14 | { 15 | MainPage page; 16 | protected override void OnElementChanged(VisualElementChangedEventArgs e) 17 | { 18 | base.OnElementChanged(e); 19 | page = e.NewElement as MainPage; 20 | } 21 | public override void ViewDidLoad() 22 | { 23 | base.ViewDidLoad(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.iOS/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("XamarinConnect.iOS")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("XamarinConnect.iOS")] 13 | [assembly: AssemblyCopyright("Copyright © 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("72bdc44f-c588-44f3-b6df-9aace7daafdd")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.iOS/Resources/Default-568h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/xamarin-csharp-connect-sample/ae4b6d2be2ddd0667693245d731d31119259505d/XamarinConnect/XamarinConnect.iOS/Resources/Default-568h@2x.png -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.iOS/Resources/Default-Portrait.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/xamarin-csharp-connect-sample/ae4b6d2be2ddd0667693245d731d31119259505d/XamarinConnect/XamarinConnect.iOS/Resources/Default-Portrait.png -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.iOS/Resources/Default-Portrait@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/xamarin-csharp-connect-sample/ae4b6d2be2ddd0667693245d731d31119259505d/XamarinConnect/XamarinConnect.iOS/Resources/Default-Portrait@2x.png -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.iOS/Resources/Default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/xamarin-csharp-connect-sample/ae4b6d2be2ddd0667693245d731d31119259505d/XamarinConnect/XamarinConnect.iOS/Resources/Default.png -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.iOS/Resources/Default@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/xamarin-csharp-connect-sample/ae4b6d2be2ddd0667693245d731d31119259505d/XamarinConnect/XamarinConnect.iOS/Resources/Default@2x.png -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.iOS/Resources/Icon-60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/xamarin-csharp-connect-sample/ae4b6d2be2ddd0667693245d731d31119259505d/XamarinConnect/XamarinConnect.iOS/Resources/Icon-60@2x.png -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.iOS/Resources/Icon-60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/xamarin-csharp-connect-sample/ae4b6d2be2ddd0667693245d731d31119259505d/XamarinConnect/XamarinConnect.iOS/Resources/Icon-60@3x.png -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.iOS/Resources/Icon-76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/xamarin-csharp-connect-sample/ae4b6d2be2ddd0667693245d731d31119259505d/XamarinConnect/XamarinConnect.iOS/Resources/Icon-76.png -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.iOS/Resources/Icon-76@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/xamarin-csharp-connect-sample/ae4b6d2be2ddd0667693245d731d31119259505d/XamarinConnect/XamarinConnect.iOS/Resources/Icon-76@2x.png -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.iOS/Resources/Icon-Small-40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/xamarin-csharp-connect-sample/ae4b6d2be2ddd0667693245d731d31119259505d/XamarinConnect/XamarinConnect.iOS/Resources/Icon-Small-40.png -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.iOS/Resources/Icon-Small-40@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/xamarin-csharp-connect-sample/ae4b6d2be2ddd0667693245d731d31119259505d/XamarinConnect/XamarinConnect.iOS/Resources/Icon-Small-40@2x.png -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.iOS/Resources/Icon-Small-40@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/xamarin-csharp-connect-sample/ae4b6d2be2ddd0667693245d731d31119259505d/XamarinConnect/XamarinConnect.iOS/Resources/Icon-Small-40@3x.png -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.iOS/Resources/Icon-Small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/xamarin-csharp-connect-sample/ae4b6d2be2ddd0667693245d731d31119259505d/XamarinConnect/XamarinConnect.iOS/Resources/Icon-Small.png -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.iOS/Resources/Icon-Small@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/xamarin-csharp-connect-sample/ae4b6d2be2ddd0667693245d731d31119259505d/XamarinConnect/XamarinConnect.iOS/Resources/Icon-Small@2x.png -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.iOS/Resources/Icon-Small@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/xamarin-csharp-connect-sample/ae4b6d2be2ddd0667693245d731d31119259505d/XamarinConnect/XamarinConnect.iOS/Resources/Icon-Small@3x.png -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.iOS/Resources/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.iOS/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.iOS/iTunesArtwork: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/xamarin-csharp-connect-sample/ae4b6d2be2ddd0667693245d731d31119259505d/XamarinConnect/XamarinConnect.iOS/iTunesArtwork -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.iOS/iTunesArtwork@2x: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/xamarin-csharp-connect-sample/ae4b6d2be2ddd0667693245d731d31119259505d/XamarinConnect/XamarinConnect.iOS/iTunesArtwork@2x -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect.iOS/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect/App.cs: -------------------------------------------------------------------------------- 1 | //Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. 2 | //See LICENSE in the project root for license information. 3 | 4 | using Microsoft.Identity.Client; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Text; 9 | 10 | using Xamarin.Forms; 11 | 12 | namespace XamarinConnect 13 | { 14 | public class App : Application 15 | { 16 | public static PublicClientApplication IdentityClientApp; 17 | public static string ClientID = "ENTER_YOUR_CLIENT_ID"; 18 | public static string RedirectUri = "msal" + ClientID + "://auth"; 19 | public static string[] Scopes = { "User.Read", "Mail.Send", "Files.ReadWrite" }; 20 | public static string Username = string.Empty; 21 | public static string UserEmail = string.Empty; 22 | 23 | public static UIParent UiParent; 24 | public App() 25 | { 26 | IdentityClientApp = new PublicClientApplication(ClientID); 27 | MainPage = new NavigationPage(new XamarinConnect.MainPage()); 28 | } 29 | 30 | protected override void OnStart() 31 | { 32 | // Handle when your app starts 33 | } 34 | 35 | protected override void OnSleep() 36 | { 37 | // Handle when your app sleeps 38 | } 39 | 40 | protected override void OnResume() 41 | { 42 | // Handle when your app resumes 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect/AppResources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace XamarinConnect { 12 | using System; 13 | using System.Reflection; 14 | 15 | 16 | /// 17 | /// A strongly-typed resource class, for looking up localized strings, etc. 18 | /// 19 | // This class was auto-generated by the StronglyTypedResourceBuilder 20 | // class via a tool like ResGen or Visual Studio. 21 | // To add or remove a member, edit your .ResX file then rerun ResGen 22 | // with the /str option, or rebuild your VS project. 23 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 24 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 25 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 26 | internal class AppResources { 27 | 28 | private static global::System.Resources.ResourceManager resourceMan; 29 | 30 | private static global::System.Globalization.CultureInfo resourceCulture; 31 | 32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 33 | internal AppResources() { 34 | } 35 | 36 | /// 37 | /// Returns the cached ResourceManager instance used by this class. 38 | /// 39 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 40 | internal static global::System.Resources.ResourceManager ResourceManager { 41 | get { 42 | if (object.ReferenceEquals(resourceMan, null)) { 43 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("XamarinConnect.AppResources", typeof(AppResources).GetTypeInfo().Assembly); 44 | resourceMan = temp; 45 | } 46 | return resourceMan; 47 | } 48 | } 49 | 50 | /// 51 | /// Overrides the current thread's CurrentUICulture property for all 52 | /// resource lookups using this strongly typed resource class. 53 | /// 54 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 55 | internal static global::System.Globalization.CultureInfo Culture { 56 | get { 57 | return resourceCulture; 58 | } 59 | set { 60 | resourceCulture = value; 61 | } 62 | } 63 | 64 | /// 65 | /// Looks up a localized string similar to Oops! 66 | ///We couldn't connect to Office 365. Check your debug output for errors.. 67 | /// 68 | internal static string AuthenticationErrorMessage { 69 | get { 70 | return ResourceManager.GetString("AuthenticationErrorMessage", resourceCulture); 71 | } 72 | } 73 | 74 | /// 75 | /// Looks up a localized string similar to Tap the "connect" button to connect to your personal or work or school account.. 76 | /// 77 | internal static string ConnectPrompt { 78 | get { 79 | return ResourceManager.GetString("ConnectPrompt", resourceCulture); 80 | } 81 | } 82 | 83 | /// 84 | /// Looks up a localized string similar to <html><head> 85 | ///<meta http-equiv='Content-Type' content='text/html; charset=us-ascii'> 86 | ///<title></title> 87 | ///</head> 88 | ///<body style='font-family:calibri'> 89 | ///<h2>Congratulations!</h2> 90 | ///<p>This is a message from the Microsoft Graph Connect Sample. You are well on your way to incorporating Microsoft Graph endpoints in your apps.</p><a href='{0}'>See the photo you just uploaded!</a> 91 | ///<h3>What's next?</h3><ul> 92 | ///<li>Check out <a href='https://developer.microsoft.com/graph'>developer.microsoft.com/graph</a> to start buildi [rest of string was truncated]";. 93 | /// 94 | internal static string MailContents { 95 | get { 96 | return ResourceManager.GetString("MailContents", resourceCulture); 97 | } 98 | } 99 | 100 | /// 101 | /// Looks up a localized string similar to Oops! 102 | /// 103 | ///We couldn't send an mail. Check your debug output for errors.. 104 | /// 105 | internal static string MailErrorMessage { 106 | get { 107 | return ResourceManager.GetString("MailErrorMessage", resourceCulture); 108 | } 109 | } 110 | 111 | /// 112 | /// Looks up a localized string similar to Hi from the Microsoft Graph Connect sample.. 113 | /// 114 | internal static string MailSubject { 115 | get { 116 | return ResourceManager.GetString("MailSubject", resourceCulture); 117 | } 118 | } 119 | 120 | /// 121 | /// Looks up a localized string similar to Oops - It looks like this app is not registered with the v2.0 authentication endpoint, because we don't see a client id in App.xaml. To run this sample, register it in the App Registration Portal. See Readme for more info.. 122 | /// 123 | internal static string NoClientIdMessage { 124 | get { 125 | return ResourceManager.GetString("NoClientIdMessage", resourceCulture); 126 | } 127 | } 128 | 129 | /// 130 | /// Looks up a localized string similar to You're now connected to Microsoft Graph. Tap "send mail" to send a message from your account using Microsoft Graph.. 131 | /// 132 | internal static string SendMailPrompt { 133 | get { 134 | return ResourceManager.GetString("SendMailPrompt", resourceCulture); 135 | } 136 | } 137 | 138 | /// 139 | /// Looks up a localized string similar to We successfully sent an email to {0} !. 140 | /// 141 | internal static string SendMailSuccess { 142 | get { 143 | return ResourceManager.GetString("SendMailSuccess", resourceCulture); 144 | } 145 | } 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect/AuthenticationHelper.cs: -------------------------------------------------------------------------------- 1 | //Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. 2 | //See LICENSE in the project root for license information. 3 | 4 | using Microsoft.Graph; 5 | using System; 6 | using System.Diagnostics; 7 | using System.Net.Http.Headers; 8 | using System.Threading.Tasks; 9 | using Microsoft.Identity.Client; 10 | 11 | namespace XamarinConnect 12 | { 13 | public class AuthenticationHelper 14 | { 15 | 16 | public static string TokenForUser = null; 17 | public static DateTimeOffset expiration; 18 | 19 | private static GraphServiceClient graphClient = null; 20 | 21 | // Get an access token for the given context and resourceId. An attempt is first made to 22 | // acquire the token silently. If that fails, then we try to acquire the token by prompting the user. 23 | public static GraphServiceClient GetAuthenticatedClient() 24 | { 25 | if (graphClient == null) 26 | { 27 | // Create Microsoft Graph client. 28 | try 29 | { 30 | graphClient = new GraphServiceClient( 31 | "https://graph.microsoft.com/v1.0", 32 | new DelegateAuthenticationProvider( 33 | async (requestMessage) => 34 | { 35 | var token = await GetTokenForUserAsync(); 36 | requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", token); 37 | // This header has been added to identify our sample in the Microsoft Graph service. If extracting this code for your project please remove. 38 | requestMessage.Headers.Add("SampleID", "xamarin-csharp-connect-sample"); 39 | 40 | })); 41 | return graphClient; 42 | } 43 | 44 | catch (Exception ex) 45 | { 46 | Debug.WriteLine("Could not create a graph client: " + ex.Message); 47 | } 48 | } 49 | 50 | return graphClient; 51 | } 52 | 53 | 54 | /// 55 | /// Get Token for User. 56 | /// 57 | /// Token for user. 58 | public static async Task GetTokenForUserAsync() 59 | { 60 | if (TokenForUser == null || expiration <= DateTimeOffset.UtcNow.AddMinutes(5)) 61 | { 62 | AuthenticationResult authResult = await App.IdentityClientApp.AcquireTokenAsync(App.Scopes, App.UiParent); 63 | 64 | TokenForUser = authResult.AccessToken; 65 | expiration = authResult.ExpiresOn; 66 | } 67 | 68 | return TokenForUser; 69 | } 70 | 71 | 72 | /// 73 | /// Signs the user out of the service. 74 | /// 75 | public static void SignOut() 76 | { 77 | foreach (var user in App.IdentityClientApp.Users) 78 | { 79 | App.IdentityClientApp.Remove(user); 80 | } 81 | graphClient = null; 82 | TokenForUser = null; 83 | 84 | } 85 | 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect/GettingStarted.Xamarin: -------------------------------------------------------------------------------- 1 | 2 | GS\XF\CS\App\GettingStarted.html 3 | false 4 | -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect/MailHelper.cs: -------------------------------------------------------------------------------- 1 | //Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. 2 | //See LICENSE in the project root for license information. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.IO; 7 | using System.Linq; 8 | using System.Reflection; 9 | using System.Text; 10 | using System.Threading.Tasks; 11 | using Microsoft.Graph; 12 | 13 | namespace XamarinConnect 14 | { 15 | public class MailHelper 16 | { 17 | /// 18 | /// Compose and send a new email. 19 | /// 20 | /// The subject line of the email. 21 | /// The body of the email. 22 | /// A semicolon-separated list of email addresses. 23 | /// 24 | public async Task ComposeAndSendMailAsync(string subject, 25 | string bodyContent, 26 | string recipients) 27 | { 28 | 29 | // Get current user photo 30 | Stream photoStream = await GetCurrentUserPhotoStreamAsync(); 31 | 32 | 33 | // If the user doesn't have a photo, or if the user account is MSA, we use a default photo 34 | 35 | if (photoStream == null) 36 | { 37 | var assembly = typeof(MailHelper).GetTypeInfo().Assembly; 38 | photoStream = assembly.GetManifestResourceStream("XamarinConnect.test.jpg"); 39 | } 40 | 41 | MemoryStream photoStreamMS = new MemoryStream(); 42 | // Copy stream to MemoryStream object so that it can be converted to byte array. 43 | photoStream.CopyTo(photoStreamMS); 44 | 45 | DriveItem photoFile = await UploadFileToOneDriveAsync(photoStreamMS.ToArray()); 46 | 47 | MessageAttachmentsCollectionPage attachments = new MessageAttachmentsCollectionPage(); 48 | attachments.Add(new FileAttachment 49 | { 50 | ODataType = "#microsoft.graph.fileAttachment", 51 | ContentBytes = photoStreamMS.ToArray(), 52 | ContentType = "image/png", 53 | Name = "me.png" 54 | }); 55 | 56 | // Get the sharing link and insert it into the message body. 57 | Permission sharingLink = await GetSharingLinkAsync(photoFile.Id); 58 | string bodyContentWithSharingLink = String.Format(bodyContent, sharingLink.Link.WebUrl); 59 | 60 | 61 | // Prepare the recipient list 62 | string[] splitter = { ";" }; 63 | var splitRecipientsString = recipients.Split(splitter, StringSplitOptions.RemoveEmptyEntries); 64 | List recipientList = new List(); 65 | 66 | foreach (string recipient in splitRecipientsString) 67 | { 68 | recipientList.Add(new Recipient { EmailAddress = new EmailAddress { Address = recipient.Trim() } }); 69 | } 70 | 71 | try 72 | { 73 | var graphClient = AuthenticationHelper.GetAuthenticatedClient(); 74 | 75 | var email = new Message 76 | { 77 | Body = new ItemBody 78 | { 79 | Content = bodyContentWithSharingLink, 80 | ContentType = BodyType.Html, 81 | }, 82 | Subject = subject, 83 | ToRecipients = recipientList, 84 | Attachments = attachments 85 | }; 86 | 87 | try 88 | { 89 | await graphClient.Me.SendMail(email, true).Request().PostAsync(); 90 | } 91 | catch (ServiceException exception) 92 | { 93 | throw new Exception("We could not send the message: " + exception.Error == null ? "No error message returned." : exception.Error.Message); 94 | } 95 | 96 | 97 | } 98 | 99 | catch (Exception e) 100 | { 101 | throw new Exception("We could not send the message: " + e.Message); 102 | } 103 | } 104 | 105 | // Gets the stream content of the signed-in user's photo. 106 | // This snippet doesn't work with consumer accounts. 107 | public async Task GetCurrentUserPhotoStreamAsync() 108 | { 109 | Stream currentUserPhotoStream = null; 110 | 111 | try 112 | { 113 | var graphClient = AuthenticationHelper.GetAuthenticatedClient(); 114 | currentUserPhotoStream = await graphClient.Me.Photo.Content.Request().GetAsync(); 115 | 116 | } 117 | 118 | // If the user account is MSA (not work or school), the service will throw an exception. 119 | catch (ServiceException) 120 | { 121 | return null; 122 | } 123 | 124 | return currentUserPhotoStream; 125 | 126 | } 127 | 128 | // Uploads the specified file to the user's root OneDrive directory. 129 | public async Task UploadFileToOneDriveAsync(byte[] file) 130 | { 131 | DriveItem uploadedFile = null; 132 | 133 | try 134 | { 135 | var graphClient = AuthenticationHelper.GetAuthenticatedClient(); 136 | MemoryStream fileStream = new MemoryStream(file); 137 | uploadedFile = await graphClient.Me.Drive.Root.ItemWithPath("me.png").Content.Request().PutAsync(fileStream); 138 | 139 | } 140 | 141 | 142 | catch (ServiceException) 143 | { 144 | return null; 145 | } 146 | 147 | return uploadedFile; 148 | } 149 | 150 | public static async Task GetSharingLinkAsync(string Id) 151 | { 152 | Permission permission = null; 153 | 154 | try 155 | { 156 | var graphClient = AuthenticationHelper.GetAuthenticatedClient(); 157 | permission = await graphClient.Me.Drive.Items[Id].CreateLink("view").Request().PostAsync(); 158 | } 159 | 160 | catch (ServiceException) 161 | { 162 | return null; 163 | } 164 | 165 | return permission; 166 | } 167 | 168 | 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /XamarinConnect/XamarinConnect/MainPage.xaml: -------------------------------------------------------------------------------- 1 |  2 | 4 | 8 | 9 | 10 |