Permalink
Browse files

Initial check-in of repository from Mercurial.

Check in just before publication of blog post.
  • Loading branch information...
1 parent c8d0db1 commit 8ced86ac41b64c0c1a34d2a7e1c962653d333d96 @arvindsuthar arvindsuthar committed Mar 6, 2014
Showing with 42,126 additions and 0 deletions.
  1. +5 −0 .hg_archival.txt
  2. +13 −0 .hgignore
  3. +6 −0 .nuget/NuGet.Config
  4. +136 −0 .nuget/NuGet.targets
  5. +5 −0 .nuget/packages.config
  6. +172 −0 GraphHelper/AzureADAuthentication.cs
  7. +446 −0 GraphHelper/DirectoryClass.cs
  8. +55 −0 GraphHelper/DirectorySchemaExtensions.cs
  9. +87 −0 GraphHelper/GraphHelper.csproj
  10. +116 −0 GraphHelper/Logging/EventSource.cs
  11. +36 −0 GraphHelper/Properties/AssemblyInfo.cs
  12. +43 −0 GraphHelper/StringConstants.cs
  13. +2,651 −0 GraphHelper/WebRequest.cs
  14. +11 −0 GraphHelper/app.config
  15. +11 −0 GraphHelper/bin/Debug/Microsoft.WindowsAzure.ActiveDirectory.GraphHelper.dll.config
  16. +1,826 −0 GraphHelper/bin/Debug/System.IdentityModel.Tokens.Jwt.xml
  17. +53 −0 GraphHelper/obj/Debug/GraphHelper.csproj.FileListAbsolute.txt
  18. 0 GraphHelper/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
  19. 0 GraphHelper/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
  20. 0 GraphHelper/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
  21. +6 −0 GraphHelper/packages.config
  22. +26 −0 OrgChart.Tests/App.config
  23. +70 −0 OrgChart.Tests/Controllers/HomeControllerTest.cs
  24. +146 −0 OrgChart.Tests/OrgChart.Tests.csproj
  25. +39 −0 OrgChart.Tests/Properties/AssemblyInfo.cs
  26. 0 OrgChart.Tests/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
  27. 0 OrgChart.Tests/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
  28. 0 OrgChart.Tests/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
  29. +18 −0 OrgChart.Tests/packages.config
  30. +42 −0 OrgChart.sln
  31. +57 −0 OrgChart/App_Start/BundleConfig.cs
  32. +24 −0 OrgChart/App_Start/FilterConfig.cs
  33. +33 −0 OrgChart/App_Start/RouteConfig.cs
  34. +34 −0 OrgChart/App_Start/WebApiConfig.cs
  35. +774 −0 OrgChart/Content/Site.css
  36. BIN OrgChart/Content/themes/base/images/ui-bg_flat_0_aaaaaa_40x100.png
  37. BIN OrgChart/Content/themes/base/images/ui-bg_flat_75_ffffff_40x100.png
  38. BIN OrgChart/Content/themes/base/images/ui-bg_glass_55_fbf9ee_1x400.png
  39. BIN OrgChart/Content/themes/base/images/ui-bg_glass_65_ffffff_1x400.png
  40. BIN OrgChart/Content/themes/base/images/ui-bg_glass_75_dadada_1x400.png
  41. BIN OrgChart/Content/themes/base/images/ui-bg_glass_75_e6e6e6_1x400.png
  42. BIN OrgChart/Content/themes/base/images/ui-bg_glass_95_fef1ec_1x400.png
  43. BIN OrgChart/Content/themes/base/images/ui-bg_highlight-soft_75_cccccc_1x100.png
  44. BIN OrgChart/Content/themes/base/images/ui-icons_222222_256x240.png
  45. BIN OrgChart/Content/themes/base/images/ui-icons_2e83ff_256x240.png
  46. BIN OrgChart/Content/themes/base/images/ui-icons_454545_256x240.png
  47. BIN OrgChart/Content/themes/base/images/ui-icons_888888_256x240.png
  48. BIN OrgChart/Content/themes/base/images/ui-icons_cd0a0a_256x240.png
  49. +464 −0 OrgChart/Content/themes/base/jquery-ui.css
  50. +19 −0 OrgChart/Content/themes/base/jquery.ui.accordion.css
  51. +11 −0 OrgChart/Content/themes/base/jquery.ui.all.css
  52. +53 −0 OrgChart/Content/themes/base/jquery.ui.autocomplete.css
  53. +21 −0 OrgChart/Content/themes/base/jquery.ui.base.css
  54. +38 −0 OrgChart/Content/themes/base/jquery.ui.button.css
  55. +38 −0 OrgChart/Content/themes/base/jquery.ui.core.css
  56. +66 −0 OrgChart/Content/themes/base/jquery.ui.datepicker.css
  57. +21 −0 OrgChart/Content/themes/base/jquery.ui.dialog.css
  58. +11 −0 OrgChart/Content/themes/base/jquery.ui.progressbar.css
  59. +20 −0 OrgChart/Content/themes/base/jquery.ui.resizable.css
  60. +10 −0 OrgChart/Content/themes/base/jquery.ui.selectable.css
  61. +24 −0 OrgChart/Content/themes/base/jquery.ui.slider.css
  62. +18 −0 OrgChart/Content/themes/base/jquery.ui.tabs.css
  63. +247 −0 OrgChart/Content/themes/base/jquery.ui.theme.css
  64. BIN OrgChart/Content/themes/base/minified/images/ui-bg_flat_0_aaaaaa_40x100.png
  65. BIN OrgChart/Content/themes/base/minified/images/ui-bg_flat_75_ffffff_40x100.png
  66. BIN OrgChart/Content/themes/base/minified/images/ui-bg_glass_55_fbf9ee_1x400.png
  67. BIN OrgChart/Content/themes/base/minified/images/ui-bg_glass_65_ffffff_1x400.png
  68. BIN OrgChart/Content/themes/base/minified/images/ui-bg_glass_75_dadada_1x400.png
  69. BIN OrgChart/Content/themes/base/minified/images/ui-bg_glass_75_e6e6e6_1x400.png
  70. BIN OrgChart/Content/themes/base/minified/images/ui-bg_glass_95_fef1ec_1x400.png
  71. BIN OrgChart/Content/themes/base/minified/images/ui-bg_highlight-soft_75_cccccc_1x100.png
  72. BIN OrgChart/Content/themes/base/minified/images/ui-icons_222222_256x240.png
  73. BIN OrgChart/Content/themes/base/minified/images/ui-icons_2e83ff_256x240.png
  74. BIN OrgChart/Content/themes/base/minified/images/ui-icons_454545_256x240.png
  75. BIN OrgChart/Content/themes/base/minified/images/ui-icons_888888_256x240.png
  76. BIN OrgChart/Content/themes/base/minified/images/ui-icons_cd0a0a_256x240.png
  77. +5 −0 OrgChart/Content/themes/base/minified/jquery-ui.min.css
  78. +5 −0 OrgChart/Content/themes/base/minified/jquery.ui.accordion.min.css
  79. +5 −0 OrgChart/Content/themes/base/minified/jquery.ui.autocomplete.min.css
  80. +5 −0 OrgChart/Content/themes/base/minified/jquery.ui.button.min.css
  81. +5 −0 OrgChart/Content/themes/base/minified/jquery.ui.core.min.css
  82. +5 −0 OrgChart/Content/themes/base/minified/jquery.ui.datepicker.min.css
  83. +5 −0 OrgChart/Content/themes/base/minified/jquery.ui.dialog.min.css
  84. +5 −0 OrgChart/Content/themes/base/minified/jquery.ui.progressbar.min.css
  85. +5 −0 OrgChart/Content/themes/base/minified/jquery.ui.resizable.min.css
  86. +5 −0 OrgChart/Content/themes/base/minified/jquery.ui.selectable.min.css
  87. +5 −0 OrgChart/Content/themes/base/minified/jquery.ui.slider.min.css
  88. +5 −0 OrgChart/Content/themes/base/minified/jquery.ui.tabs.min.css
  89. +5 −0 OrgChart/Content/themes/base/minified/jquery.ui.theme.min.css
  90. +182 −0 OrgChart/Controllers/HomeController.cs
  91. +1 −0 OrgChart/Global.asax
  92. +45 −0 OrgChart/Global.asax.cs
  93. BIN OrgChart/Images/accent.png
  94. BIN OrgChart/Images/bullet.png
  95. BIN OrgChart/Images/heroAccent.png
  96. BIN OrgChart/Images/orderedList0.png
  97. BIN OrgChart/Images/orderedList1.png
  98. BIN OrgChart/Images/orderedList2.png
  99. BIN OrgChart/Images/orderedList3.png
  100. BIN OrgChart/Images/orderedList4.png
  101. BIN OrgChart/Images/orderedList5.png
  102. BIN OrgChart/Images/orderedList6.png
  103. BIN OrgChart/Images/orderedList7.png
  104. BIN OrgChart/Images/orderedList8.png
  105. BIN OrgChart/Images/orderedList9.png
  106. +243 −0 OrgChart/Models/DirectoryExtensions.cs
  107. +294 −0 OrgChart/Models/Org.cs
  108. +321 −0 OrgChart/OrgChart.csproj
  109. +38 −0 OrgChart/Properties/AssemblyInfo.cs
  110. +603 −0 OrgChart/Scripts/NameControl.js
  111. BIN OrgChart/Scripts/_references.js
  112. +2,494 −0 OrgChart/Scripts/jquery-1.8.2.intellisense.js
  113. +9,440 −0 OrgChart/Scripts/jquery-1.8.2.js
  114. +2 −0 OrgChart/Scripts/jquery-1.8.2.min.js
  115. +8 −0 OrgChart/Scripts/jquery-1.8.2.min.js.map
  116. +11,377 −0 OrgChart/Scripts/jquery-ui-1.8.24.js
  117. +5 −0 OrgChart/Scripts/jquery-ui-1.8.24.min.js
  118. +163 −0 OrgChart/Scripts/jquery.unobtrusive-ajax.js
  119. +5 −0 OrgChart/Scripts/jquery.unobtrusive-ajax.min.js
  120. +1,291 −0 OrgChart/Scripts/jquery.validate-vsdoc.js
  121. +1,248 −0 OrgChart/Scripts/jquery.validate.js
  122. +4 −0 OrgChart/Scripts/jquery.validate.min.js
  123. +367 −0 OrgChart/Scripts/jquery.validate.unobtrusive.js
  124. +5 −0 OrgChart/Scripts/jquery.validate.unobtrusive.min.js
  125. +3,577 −0 OrgChart/Scripts/knockout-2.2.0.debug.js
  126. +85 −0 OrgChart/Scripts/knockout-2.2.0.js
  127. +1,393 −0 OrgChart/Scripts/modernizr-2.6.2.js
  128. +34 −0 OrgChart/Views/Home/About.cshtml
  129. +50 −0 OrgChart/Views/Home/Contact.cshtml
  130. +399 −0 OrgChart/Views/Home/Index.cshtml
  131. +10 −0 OrgChart/Views/Shared/Error.cshtml
  132. +49 −0 OrgChart/Views/Shared/_Layout.cshtml
  133. +59 −0 OrgChart/Views/Web.config
  134. +3 −0 OrgChart/Views/_ViewStart.cshtml
  135. +30 −0 OrgChart/Web.Debug.config
  136. +31 −0 OrgChart/Web.Release.config
  137. +64 −0 OrgChart/Web.config
  138. BIN OrgChart/favicon.ico
  139. 0 OrgChart/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
  140. 0 OrgChart/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
  141. 0 OrgChart/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
  142. +31 −0 OrgChart/packages.config
  143. +102 −0 OrgChart/readme.txt
  144. +6 −0 packages/repositories.config
View
@@ -0,0 +1,5 @@
+repo: eab2ccc70985df82df8f4e391181a8c801ae251a
+node: a43218e1313725ee84e6f79ac5eb0641adeacad6
+branch: default
+latesttag: null
+latesttagdistance: 52
View
@@ -0,0 +1,13 @@
+syntax: glob
+
+TestResults/*
+*[Bb]in/
+*[Dd]ebug/
+*[Oo]bj/
+*[Rr]elease/
+*_[Rr]e[Ss]harper.*/
+*.docstates
+*.user
+*.suo
+*.xap
+[pP]ackages/
View
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <solution>
+ <add key="disableSourceControlIntegration" value="true" />
+ </solution>
+</configuration>
View
@@ -0,0 +1,136 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>
+
+ <!-- Enable the restore command to run before builds -->
+ <RestorePackages Condition=" '$(RestorePackages)' == '' ">false</RestorePackages>
+
+ <!-- Property that enables building a package from a project -->
+ <BuildPackage Condition=" '$(BuildPackage)' == '' ">false</BuildPackage>
+
+ <!-- Determines if package restore consent is required to restore packages -->
+ <RequireRestoreConsent Condition=" '$(RequireRestoreConsent)' != 'false' ">true</RequireRestoreConsent>
+
+ <!-- Download NuGet.exe if it does not already exist -->
+ <DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">false</DownloadNuGetExe>
+ </PropertyGroup>
+
+ <ItemGroup Condition=" '$(PackageSources)' == '' ">
+ <!-- Package sources used to restore packages. By default, registered sources under %APPDATA%\NuGet\NuGet.Config will be used -->
+ <!-- The official NuGet package source (https://www.nuget.org/api/v2/) will be excluded if package sources are specified and it does not appear in the list -->
+ <!--
+ <PackageSource Include="https://www.nuget.org/api/v2/" />
+ <PackageSource Include="https://my-nuget-source/nuget/" />
+ -->
+ </ItemGroup>
+
+ <PropertyGroup Condition=" '$(OS)' == 'Windows_NT'">
+ <!-- Windows specific commands -->
+ <NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>
+ <PackagesConfig>$([System.IO.Path]::Combine($(ProjectDir), "packages.config"))</PackagesConfig>
+ </PropertyGroup>
+
+ <PropertyGroup Condition=" '$(OS)' != 'Windows_NT'">
+ <!-- We need to launch nuget.exe with the mono command if we're not on windows -->
+ <NuGetToolsPath>$(SolutionDir).nuget</NuGetToolsPath>
+ <PackagesConfig>packages.config</PackagesConfig>
+ </PropertyGroup>
+
+ <PropertyGroup>
+ <!-- NuGet command -->
+ <NuGetExePath Condition=" '$(NuGetExePath)' == '' ">$(NuGetToolsPath)\NuGet.exe</NuGetExePath>
+ <PackageSources Condition=" $(PackageSources) == '' ">@(PackageSource)</PackageSources>
+
+ <NuGetCommand Condition=" '$(OS)' == 'Windows_NT'">"$(NuGetExePath)"</NuGetCommand>
+ <NuGetCommand Condition=" '$(OS)' != 'Windows_NT' ">mono --runtime=v4.0.30319 $(NuGetExePath)</NuGetCommand>
+
+ <PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir>
+
+ <RequireConsentSwitch Condition=" $(RequireRestoreConsent) == 'true' ">-RequireConsent</RequireConsentSwitch>
+ <NonInteractiveSwitch Condition=" '$(VisualStudioVersion)' != '' AND '$(OS)' == 'Windows_NT' ">-NonInteractive</NonInteractiveSwitch>
+
+ <PaddedSolutionDir Condition=" '$(OS)' == 'Windows_NT'">"$(SolutionDir) "</PaddedSolutionDir>
+ <PaddedSolutionDir Condition=" '$(OS)' != 'Windows_NT' ">"$(SolutionDir)"</PaddedSolutionDir>
+
+ <!-- Commands -->
+ <RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir)</RestoreCommand>
+ <BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols</BuildCommand>
+
+ <!-- We need to ensure packages are restored prior to assembly resolve -->
+ <BuildDependsOn Condition="$(RestorePackages) == 'true'">
+ RestorePackages;
+ $(BuildDependsOn);
+ </BuildDependsOn>
+
+ <!-- Make the build depend on restore packages -->
+ <BuildDependsOn Condition="$(BuildPackage) == 'true'">
+ $(BuildDependsOn);
+ BuildPackage;
+ </BuildDependsOn>
+ </PropertyGroup>
+
+ <Target Name="CheckPrerequisites">
+ <!-- Raise an error if we're unable to locate nuget.exe -->
+ <Error Condition="'$(DownloadNuGetExe)' != 'true' AND !Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" />
+ <!--
+ Take advantage of MsBuild's build dependency tracking to make sure that we only ever download nuget.exe once.
+ This effectively acts as a lock that makes sure that the download operation will only happen once and all
+ parallel builds will have to wait for it to complete.
+ -->
+ <MsBuild Targets="_DownloadNuGet" Projects="$(MSBuildThisFileFullPath)" Properties="Configuration=NOT_IMPORTANT;DownloadNuGetExe=$(DownloadNuGetExe)" />
+ </Target>
+
+ <Target Name="_DownloadNuGet">
+ <DownloadNuGet OutputFilename="$(NuGetExePath)" Condition=" '$(DownloadNuGetExe)' == 'true' AND !Exists('$(NuGetExePath)')" />
+ </Target>
+
+ <Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
+ <Exec Command="$(RestoreCommand)"
+ Condition="'$(OS)' != 'Windows_NT' And Exists('$(PackagesConfig)')" />
+
+ <Exec Command="$(RestoreCommand)"
+ LogStandardErrorAsError="true"
+ Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" />
+ </Target>
+
+ <Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites">
+ <Exec Command="$(BuildCommand)"
+ Condition=" '$(OS)' != 'Windows_NT' " />
+
+ <Exec Command="$(BuildCommand)"
+ LogStandardErrorAsError="true"
+ Condition=" '$(OS)' == 'Windows_NT' " />
+ </Target>
+
+ <UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
+ <ParameterGroup>
+ <OutputFilename ParameterType="System.String" Required="true" />
+ </ParameterGroup>
+ <Task>
+ <Reference Include="System.Core" />
+ <Using Namespace="System" />
+ <Using Namespace="System.IO" />
+ <Using Namespace="System.Net" />
+ <Using Namespace="Microsoft.Build.Framework" />
+ <Using Namespace="Microsoft.Build.Utilities" />
+ <Code Type="Fragment" Language="cs">
+ <![CDATA[
+ try {
+ OutputFilename = Path.GetFullPath(OutputFilename);
+
+ Log.LogMessage("Downloading latest version of NuGet.exe...");
+ WebClient webClient = new WebClient();
+ webClient.DownloadFile("https://www.nuget.org/nuget.exe", OutputFilename);
+
+ return true;
+ }
+ catch (Exception ex) {
+ Log.LogErrorFromException(ex);
+ return false;
+ }
+ ]]>
+ </Code>
+ </Task>
+ </UsingTask>
+</Project>
View
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="HgIgnore" version="1.5" />
+ <package id="NuGetPowerTools" version="0.29" />
+</packages>
@@ -0,0 +1,172 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Microsoft.IdentityModel.Clients;
+using Microsoft.IdentityModel.Clients.ActiveDirectory;
+using System.Threading;
+using System.Diagnostics;
+
+namespace Microsoft.WindowsAzure.ActiveDirectory.GraphClient
+{
+ public class AzureADAuthentication
+ {
+ public AuthenticationResult AadAuthenticationResult;
+
+ // First Authn method OAuth Client credential flow (2-legged, S2S)
+ //
+ // 2-legged OAuth, describes a typical client-server scenario, without any user involvement.
+ // An example for such a scenario could be your Azure AD application accessing a consented tenant with no user interaction.
+ //
+ // On a conceptual level 2-legged OAuth simply consists of the first and last steps of 3-legged OAuth (see below):
+ // Client has signed up to the server and got his client credentials (also known as “consumer key and secret”)
+ // Client uses his client credentials (and empty token credentials) to access the protected resources on the server
+ //
+ public string GetToken(string tenant, string clientId, string clientSecret, string resource, string authnEndpoint, ref string strErrors)
+ {
+ string authString = authnEndpoint + tenant;
+ AuthenticationContext authenticationContext = new AuthenticationContext(authString);
+ try
+ {
+ ClientCredential clientCred = new ClientCredential(clientId, clientSecret);
+ AuthenticationResult authenticationResult = authenticationContext.AcquireToken(resource, clientCred);
+ Console.WriteLine("Token: \nToken Type: {0} \nExpires: {1}", authenticationResult.AccessTokenType, authenticationResult.ExpiresOn);
+ return authenticationResult.AccessToken;
+ }
+ catch (ActiveDirectoryAuthenticationException ex)
+ {
+ GraphHelperEventSourceLogger.Log(ex, ref strErrors);
+ return "";
+ }
+ }
+
+ // Second Authn method using OAuth Authorization Code grant flow (3-legged OAuth, user impersonation/delegation)
+ //
+ // 3-legged OAuth describes the scenario for which OAuth was originally developed: a resource owner wants to give a client
+ // access to a server without sharing his credentials (i.e. username/password).
+ //
+ // A typical example is a Facebook user (resource owner) who wants to give a facebook app (client) ability to write to her wall (server).
+ //
+ // On a conceptual level it works in the following way:
+ // Client has signed up to the server and got his client credentials (also known as “consumer key and secret”) ahead of time
+ // User wants to give the client access to his protected resources on the server
+ // Client retrieves the temporary credentials (also known as “request token”) from the server
+ // Client redirects the resource owner to the server
+ // Resource owner grants the client access to his protected resources on the server
+ // Server redirects the user back to the client
+ // Client uses the temporary credentials to retrieve the token credentials (also known as “access token”) from the server
+ // Client uses the token credentials to access the protected resources on the server
+ //
+ public string GetToken(string tenant, string clientId, Uri redirectUri, string resourceAppIdUri, string authnEndpoint, ref string strErrors)
+ {
+ // This method requests OAuth token using client code authn flow (3-legged)
+ // user must authenticate
+ string authString = authnEndpoint + tenant;
+ AuthenticationContext authenticationContext = new AuthenticationContext(authString);
+ AuthenticationResult userAuthnResult = null;
+ try
+ {
+ userAuthnResult = authenticationContext.AcquireToken(resourceAppIdUri, clientId, redirectUri);
+ Console.WriteLine("Token: \nToken Type: {0} \nExpires: {1}", userAuthnResult.AccessTokenType, userAuthnResult.ExpiresOn);
+ //Console.WriteLine("RefreshToken: {0}", userAuthnResult.RefreshToken);
+ return userAuthnResult.AccessToken;
+ }
+ catch (ActiveDirectoryAuthenticationException ex)
+ {
+ GraphHelperEventSourceLogger.Log(ex, ref strErrors);
+ return "";
+ }
+ }
+
+ // Third Authn method OAuth Client credential flow (2-legged, S2S)
+ // returns entire Authentication Result
+ public AuthenticationResult GetAuthenticationResult(string tenant, string clientId, string clientSecret,
+ string resource, string authnEndpoint, ref string strErrors)
+ {
+ string authString = authnEndpoint + tenant;
+ AuthenticationContext authenticationContext = new AuthenticationContext(authString);
+ try
+ {
+ ClientCredential clientCred = new ClientCredential(clientId, clientSecret);
+ AuthenticationResult authenticationResult = authenticationContext.AcquireToken(resource, clientCred);
+ //Console.WriteLine("Token: \nToken Type: {0} \nExpires: {1}", authenticationResult.AccessTokenType, authenticationResult.ExpiresOn);
+ return authenticationResult;
+ }
+ catch (ActiveDirectoryAuthenticationException ex)
+ {
+ GraphHelperEventSourceLogger.Log(ex, ref strErrors);
+ return null;
+ }
+ }
+
+ // Fourth Authn method OAuth Client Authorization Code grant flow (3-legged, user impersonation/delagion)
+ // returns entire Authentication Result
+ public AuthenticationResult GetAuthenticationResult(string tenant, string clientId, Uri redirectUri,
+ string resourceAppIdUri, string authnEndpoint, ref string strErrors)
+ {
+ // This method requests OAuth token using client code authn flow (3-legged)
+ // user must authenticate
+
+ string authString = authnEndpoint + tenant;
+ AuthenticationContext authenticationContext = new AuthenticationContext(authString);
+ AuthenticationResult userAuthnResult = null;
+
+ try
+ {
+ userAuthnResult = authenticationContext.AcquireToken(resourceAppIdUri, clientId, redirectUri);
+ Console.WriteLine("Token: \nToken Type: {0} \nExpires: {1}", userAuthnResult.AccessTokenType, userAuthnResult.ExpiresOn);
+ //Console.WriteLine("RefreshToken: {0}", userAuthnResult.RefreshToken);
+ return userAuthnResult;
+ }
+ catch (ActiveDirectoryAuthenticationException ex)
+ {
+ GraphHelperEventSourceLogger.Log(ex, ref strErrors);
+ return null;
+ }
+ }
+
+ // methods will get a new token.
+ public AuthenticationResult GetNewAuthenticationResult(ref string strErrors)
+ {
+ // check which type of token to acquire by checking to see if a refresh token is available
+ // (indicating OAuth Authz code grant flow)
+ if (this.AadAuthenticationResult.RefreshToken == null)
+ {
+ AzureADAuthentication appToken = new AzureADAuthentication();
+ AuthenticationResult applicationAuthnResult = appToken.GetAuthenticationResult(StringConstants.Tenant,
+ StringConstants.ClientId, StringConstants.ClientSecret,
+ StringConstants.Resource, StringConstants.AuthenticationEndpoint, ref strErrors);
+ return applicationAuthnResult;
+ }
+ else
+ {
+ AzureADAuthentication appToken = new AzureADAuthentication();
+ AuthenticationResult userAuthnResult = appToken.GetAuthenticationResult(StringConstants.Tenant,
+ StringConstants.ClientId, StringConstants.RedirectUri,
+ StringConstants.Resource, StringConstants.AuthenticationEndpoint, ref strErrors);
+ return userAuthnResult;
+ }
+
+ }
+ }
+}
+
+// Extension methods for Azure AD Authentication Library (ADAL)
+// check if token is expired or about to expire in specified minutes)
+namespace ExtensionMethods
+{
+ public static class MicrosoftIdentityModelExtensions
+ {
+ public static bool IsExpired(this AuthenticationResult authenticationResult)
+ {
+ return WillExpireIn(authenticationResult, 0);
+ }
+
+ public static bool WillExpireIn(this AuthenticationResult authenticationResult, double minutes)
+ {
+ DateTimeOffset datetimeoffset = DateTimeOffset.Now.UtcDateTime;
+ return datetimeoffset.AddMinutes(minutes) > authenticationResult.ExpiresOn;
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit 8ced86a

Please sign in to comment.