Skip to content

Commit fca9b59

Browse files
author
Kalyan Krishna
committed
Minor fixes and enhancements
1 parent d0301f3 commit fca9b59

File tree

5 files changed

+45
-29
lines changed

5 files changed

+45
-29
lines changed

AppCreationScripts/Configure.ps1

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
[CmdletBinding()]
2+
param(
3+
[PSCredential] $Credential,
4+
[Parameter(HelpMessage='Tenant ID (This is a GUID which represents the "Directory ID" of the AzureAD tenant into which you want to create the apps')]
5+
[string] $tenantId
6+
)
7+
18
<#
29
This script creates the Azure AD applications needed for this sample and updates the configuration files
310
for the visual Studio projects from the data in the Azure AD applications.
@@ -8,6 +15,10 @@
815
2) in the PowerShell window, type: Install-Module AzureAD
916
1017
There are four ways to run this script. For more information, read the AppCreationScripts.md file in the same folder as this script.
18+
19+
# Parameters
20+
# $tenantId is the Active Directory Tenant. This is a GUID which represents the "Directory ID" of the AzureAD tenant
21+
# into which you want to create the apps. Look it up in the Azure portal in the "Properties" of the Azure AD.
1122
#>
1223

1324
# Adds the requiredAccesses (expressed as a pipe separated string) to the requiredAccess structure
@@ -92,18 +103,7 @@ Function ConfigureApplications
92103
This function creates the Azure AD applications for the sample in the provided Azure AD tenant and updates the
93104
configuration files in the client and service project of the visual studio solution (App.Config and Web.Config)
94105
so that they are consistent with the Applications parameters
95-
#>
96-
[CmdletBinding()]
97-
param(
98-
[PSCredential] $Credential,
99-
[Parameter(HelpMessage='Tenant ID (This is a GUID which represents the "Directory ID" of the AzureAD tenant into which you want to create the apps')]
100-
[string] $tenantId
101-
)
102-
103-
process
104-
{
105-
# $tenantId is the Active Directory Tenant. This is a GUID which represents the "Directory ID" of the AzureAD tenant
106-
# into which you want to create the apps. Look it up in the Azure portal in the "Properties" of the Azure AD.
106+
#>
107107

108108
# Login to Azure PowerShell (interactive if credentials are not already provided:
109109
# you'll need to sign-in with creds enabling your to create apps in the tenant)
@@ -140,6 +140,12 @@ Function ConfigureApplications
140140

141141
$currentAppId = $serviceAadApplication.AppId
142142
$serviceServicePrincipal = New-AzureADServicePrincipal -AppId $currentAppId -Tags {WindowsAzureActiveDirectoryIntegratedApp}
143+
144+
# add this user as app owner
145+
$user = Get-AzureADUser -ObjectId $creds.Account.Id
146+
Add-AzureADApplicationOwner -ObjectId $serviceAadApplication.ObjectId -RefObjectId $user.ObjectId
147+
Write-Host "'$($user.UserPrincipalName)' added as an application owner to app '$($serviceAadApplication.DisplayName)'"
148+
143149
Write-Host "Done."
144150

145151
# URL of the AAD application in the Azure portal
@@ -155,6 +161,11 @@ Function ConfigureApplications
155161

156162
$currentAppId = $clientAadApplication.AppId
157163
$clientServicePrincipal = New-AzureADServicePrincipal -AppId $currentAppId -Tags {WindowsAzureActiveDirectoryIntegratedApp}
164+
165+
# add this user as app owner
166+
Add-AzureADApplicationOwner -ObjectId $clientAadApplication.ObjectId -RefObjectId $user.ObjectId
167+
Write-Host "'$($user.UserPrincipalName)' added as an application owner to app '$($clientServicePrincipal.DisplayName)'"
168+
158169
Write-Host "Done."
159170

160171
# URL of the AAD application in the Azure portal
@@ -186,8 +197,7 @@ Function ConfigureApplications
186197
ReplaceSetting -configFilePath $configFile -key "todo:TodoListResourceId" -newValue $serviceAadApplication.IdentifierUris
187198
ReplaceSetting -configFilePath $configFile -key "todo:TodoListBaseAddress" -newValue $serviceAadApplication.HomePage
188199
Add-Content -Value "</tbody></table></body></html>" -Path createdApps.html
189-
190-
}
200+
191201
}
192202

193203

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,14 @@ A token represents the outcome of an authentication operation with some artifact
2727

2828
With Azure Active Directory taking the full responsibility of verifying user's raw credentials, the token receiver's responsibility shifts from verifying raw credentials to verifying that their caller did indeed go through your identity provider of choice and successfully authenticated. The identity provider represents successful authentication operations by issuing a token, hence the job now becomes to validate that token.
2929

30+
### What to validate
31+
While you should always validate tokens issued to the resources (audience) that you are developineg, your application will also obtain access tokens for other resources from AAD. AAD will provide an access token in whatever token format that is appropriate to that resource.
32+
This access token itself should be treated like an opaque blob by your application, as your app isn’t the access token’s intended audience and thus your app should not bother itself with looking into the contents of this access token.
33+
Your app should just pass it in the call to the resource. It's the called resource's responsibility to validate this access token token.
34+
3035
### Validating the claims
3136

32-
When an application receives an ID token upon user sign-in, it should also perform a few checks against the claims in the ID token. These verifications include but are not limited to:
37+
When an application receives an access token upon user sign-in, it should also perform a few checks against the claims in the access token. These verifications include but are not limited to:
3338

3439
- **audience** claim, to verify that the ID token was intended to be given to your application
3540
- **not before** and "expiration time" claims, to verify that the ID token has not expired
@@ -95,7 +100,7 @@ of the Azure Active Directory window respectively as *Name* and *Directory ID*
95100
#### Register the TodoListClient client app
96101

97102
1. Click on **App registrations** and choose **New application registration**.
98-
1. Enter a friendly name for the application, for example 'TodoListClient-DotNet' and select 'Native' as the Application Type. For the redirect URI, enter `https://TodoListClient`. Please note that the Redirect URI will not be used in this sample, but it needs to be defined nonetheless. Click on **Create** to create the application.
103+
1. Enter a friendly name for the application, for example 'TodoListClient-ManualJwt' and select 'Native' as the Application Type. For the redirect URI, enter `https://TodoListClient`. Please note that the Redirect URI will not be used in this sample, but it needs to be defined nonetheless. Click on **Create** to create the application.
99104
1. In the succeeding page, Find the **Application ID** value and copy it to the clipboard.
100105
1. Then click on **Settings** and choose **Properties**.
101106
1. Configure Permissions for your application - in the Settings menu, choose the **Required permissions** section, click on **Add**, then **Select an API**, and type 'TodoListService' in the textbox and hit enter. Select 'TodoListService-ManualJwt' from the results and click the 'Select' button. Then, click on **Select Permissions** and select 'Access TodoListService-ManualJwt'. Click the 'Select' button again to close this screen. Click on **Done** to finish adding the permission.

TodoListClient/App.config

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<configuration>
3-
<startup>
4-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
5-
</startup>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
5+
</startup>
66
<appSettings>
77
<add key="ida:Tenant" value="[Enter tenant name, e.g. contoso.onmicrosoft.com]" />
88
<add key="ida:ClientId" value="[Enter client ID as obtained from Azure Portal, e.g. 82692da5-a86f-44c9-9d53-2f88d52b478b]" />

TodoListClient/FileCache.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ class FileCache : TokenCache
3737
private static readonly object FileLock = new object();
3838

3939
// Initializes the cache against a local file.
40-
// If the file is already rpesent, it loads its content in the ADAL cache
40+
// If the file is already present, it loads its content in the ADAL cache
4141
public FileCache(string filePath=@".\TokenCache.dat")
4242
{
43-
CacheFilePath = filePath;
44-
this.AfterAccess = AfterAccessNotification;
45-
this.BeforeAccess = BeforeAccessNotification;
43+
this.CacheFilePath = filePath;
44+
this.AfterAccess = this.AfterAccessNotification;
45+
this.BeforeAccess = this.BeforeAccessNotification;
4646
lock (FileLock)
4747
{
48-
this.Deserialize(File.Exists(CacheFilePath) ? ProtectedData.Unprotect(File.ReadAllBytes(CacheFilePath), null, DataProtectionScope.CurrentUser) : null);
48+
this.Deserialize(File.Exists(this.CacheFilePath) ? ProtectedData.Unprotect(File.ReadAllBytes(this.CacheFilePath), null, DataProtectionScope.CurrentUser) : null);
4949
}
5050
}
5151

@@ -62,7 +62,7 @@ void BeforeAccessNotification(TokenCacheNotificationArgs args)
6262
{
6363
lock (FileLock)
6464
{
65-
this.Deserialize(File.Exists(CacheFilePath) ? ProtectedData.Unprotect(File.ReadAllBytes(CacheFilePath),null,DataProtectionScope.CurrentUser) : null);
65+
this.Deserialize(File.Exists(this.CacheFilePath) ? ProtectedData.Unprotect(File.ReadAllBytes(this.CacheFilePath),null,DataProtectionScope.CurrentUser) : null);
6666
}
6767
}
6868

@@ -75,7 +75,7 @@ void AfterAccessNotification(TokenCacheNotificationArgs args)
7575
lock (FileLock)
7676
{
7777
// reflect changes in the persistent store
78-
File.WriteAllBytes(CacheFilePath, ProtectedData.Protect(this.Serialize(),null,DataProtectionScope.CurrentUser));
78+
File.WriteAllBytes(this.CacheFilePath, ProtectedData.Protect(this.Serialize(),null,DataProtectionScope.CurrentUser));
7979
// once the write operation took place, restore the HasStateChanged bit to false
8080
this.HasStateChanged = false;
8181
}

TodoListService-ManualJwt/Web.config

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<compilation debug="true" targetFramework="4.5" />
1919
<httpRuntime targetFramework="4.5" />
2020
</system.web>
21-
21+
2222
<runtime>
2323
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
2424
<dependentAssembly>
@@ -59,11 +59,12 @@
5959
</dependentAssembly>
6060
</assemblyBinding>
6161
</runtime>
62-
<system.webServer>
62+
<system.webServer>
6363
<handlers>
6464
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
6565
<remove name="OPTIONSVerbHandler" />
6666
<remove name="TRACEVerbHandler" />
6767
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
6868
</handlers>
69-
</system.webServer></configuration>
69+
</system.webServer>
70+
</configuration>

0 commit comments

Comments
 (0)