Skip to content

Commit

Permalink
console+desktop-update (Azure-Samples#98)
Browse files Browse the repository at this point in the history
* console+desktop-update

* remove-portal-refs

* fix-tempaltes
  • Loading branch information
OwenRichards1 authored Oct 16, 2024
1 parent fbba4e2 commit 14f812f
Show file tree
Hide file tree
Showing 22 changed files with 78 additions and 91 deletions.
4 changes: 2 additions & 2 deletions console-cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

var config = new PublicClientApplicationOptions
{
// 'Directory (tenant) ID' of the app registration in the Microsoft Entra Admin Center
// 'Directory (tenant) ID' of the app registration in the Microsoft Entra admin center
TenantId = "Enter the client ID obtained from the Microsoft Entra admin center",

// 'Application (client) ID' of the app registration in the Microsoft Entra Admin Center
// 'Application (client) ID' of the app registration in the Microsoft Entra admin center
ClientId = "Enter the tenant ID obtained from the Microsoft Entra admin center"
};

Expand Down
9 changes: 4 additions & 5 deletions console-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ products:
urlFragment: ms-identity-docs-code-console-cli-csharp
---

<!-- SAMPLE ID: DOCS-CODE-030 -->
# .NET (C#) | console | user sign-in, protected web API access (Microsoft Graph) | Microsoft identity platform

This .NET8 (C#) console application authenticates a user via the device code flow, and then makes a request to the Graph API as the authenticated user. The response to the request is printed to the console.
This .NET 8 (C#) console application authenticates a user via the device code flow, and then makes a request to the Graph API as the authenticated user. The response to the request is printed to the console.

```console
$ dotnet run
Expand Down Expand Up @@ -57,15 +56,15 @@ Use these settings in your app registration.
| **Platform type** | _None_ | No redirect URI required; don't select a platform. |
| **Allow public client flows** | **Yes** | Required value for this sample. |

> :information_source: **Bold text** in the tables above matches (or is similar to) a UI element in the Azure portal, while `code formatting` indicates a value you enter into a text box in the Azure portal.
> :information_source: **Bold text** in the tables above matches (or is similar to) a UI element in the Microsoft Entra admin center, while `code formatting` indicates a value you enter into a text box in the Microsoft Entra admin center.
### 2. Update the _Program.cs_ file with app registration values

```csharp
// 'Directory (tenant) ID' of app registration in the Azure portal - this value is a GUID
// 'Directory (tenant) ID' of app registration in the Microsoft Entra admin center - this value is a GUID
TenantId = "",

// 'Application (client) ID' of app registration in Azure portal - this value is a GUID
// 'Application (client) ID' of app registration in Microsoft Entra admin center - this value is a GUID
ClientId = ""
```

Expand Down
6 changes: 3 additions & 3 deletions console-daemon/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
var config = new {
// Full directory URL, in the form of https://login.microsoftonline.com/<tenant_id>
Authority = " https://login.microsoftonline.com/Enter the tenant ID obtained from the Microsoft Entra admin center",
// 'Enter the client ID obtained from the Microsoft Entra Admin Center
// Enter the client ID obtained from the Microsoft Entra admin center
ClientId = "Enter the client ID obtained from the Microsoft Entra admin center",
// Client secret 'Value' (not its ID) from 'Client secrets' in the Microsoft Entra Admin Center
// Client secret 'Value' (not its ID) from 'Client secrets' in the Microsoft Entra admin center
ClientSecret = "Enter the client secret value obtained from the Microsoft Entra admin center",
// Client 'Object ID' of app registration in Microsoft Entra Admin Center - this value is a GUID
// Client 'Object ID' of app registration in Microsoft Entra admin center - this value is a GUID
ClientObjectId = "Enter the client Object ID obtained from the Microsoft Entra admin center"
};

Expand Down
14 changes: 6 additions & 8 deletions console-daemon/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<!-- Updated, but leaving commented out until we're ready to ship in samples browser
---
# Metadata required by https://docs.microsoft.com/samples/browse/
# Metadata properties: https://review.docs.microsoft.com/help/contribute/samples/process/onboarding?branch=main#add-metadata-to-readme
Expand All @@ -13,8 +12,7 @@ products:
- ms-graph
urlFragment: ms-identity-docs-code-dotnet-console
---
-->
<!-- SAMPLE ID: DOCS-CODE-010 -->

# .NET | console | .NET (C#) console app that accesses a protected web API access (Microsoft Graph) | Microsoft identity platform


Expand Down Expand Up @@ -59,7 +57,7 @@ Use these settings in your app registration.
| **Platform type** | _None_ | No redirect URI required; don't select a platform. |
| **Client secret** | _**Value** of the client secret (not its ID)_ | :warning: Record this value immediately! <br/> It's shown only _once_ (when you create it). |

> :information_source: **Bold text** in the tables above matches (or is similar to) a UI element in the Azure portal, while `code formatting` indicates a value you enter into a text box in the Azure portal.
> :information_source: **Bold text** in the tables above matches (or is similar to) a UI element in the Microsoft Entra admin center, while `code formatting` indicates a value you enter into a text box in the Microsoft Entra admin center.
### 2. Update application code with values from app registration

Expand All @@ -68,11 +66,11 @@ In _Program.cs_, update each variable with values from the app registration you
```csharp
// Full directory URL, in the form of https://login.microsoftonline.com/<tenant_id>
Authority = " https://login.microsoftonline.com/Enter the tenant ID obtained from the Microsoft Entra admin center",
// 'Enter the client ID obtained from the Microsoft Entra Admin Center
// 'Enter the client ID obtained from the Microsoft Entra admin center
ClientId = "Enter the client ID obtained from the Microsoft Entra admin center",
// Client secret 'Value' (not its ID) from 'Client secrets' in the Microsoft Entra Admin Center
// Client secret 'Value' (not its ID) from 'Client secrets' in the Microsoft Entra admin center
ClientSecret = "Enter the client secret value obtained from the Microsoft Entra admin center",
// Client 'Object ID' of app registration in Microsoft Entra Admin Center - this value is a GUID
// Client 'Object ID' of app registration in Microsoft Entra admin center - this value is a GUID
ClientObjectId = "Enter the client Object ID obtained from the Microsoft Entra admin center"
```

Expand Down Expand Up @@ -118,7 +116,7 @@ If you can't get the sample working, you've checked [Stack Overflow](http://stac
### All other issues

> :warning: WARNING: Any issue in this repository _not_ limited to running one of its sample apps will be closed without being addressed.
For all other requests, see [Support and help options for developers | Microsoft identity platform](https://docs.microsoft.com/azure/active-directory/develop/developer-support-help-options).
For all other requests, see [Support and help options for developers | Microsoft identity platform](https://learn.microsoft.com/entra/identity-platform/developer-support-help-options).

## Contributing

Expand Down
20 changes: 10 additions & 10 deletions desktop-winforms/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ public MainWindow()
msalPublicClientApp = PublicClientApplicationBuilder
.CreateWithApplicationOptions(new PublicClientApplicationOptions
{
// 'Tenant ID' of your Microsoft Entra instance - this value is a GUID
TenantId = "",
// Enter the tenant ID obtained from the Microsoft Entra admin center
TenantId = "Enter the client ID obtained from the Microsoft Entra admin center",

// 'Application (client) ID' of app registration in Azure portal - this value is a GUID
ClientId = ""
// Enter the client ID obtained from the Microsoft Entra admin center
ClientId = "Enter the tenant ID obtained from the Microsoft Entra admin center"
})
.WithDefaultRedirectUri() // http://localhost
.Build();
}

/// <summary>
/// Handle the "Sign In" button click. This will acquire an access token scoped to
/// Microsoft Graph, either from the cache or from an interactive session. It will
/// then use that access token in an HTTP request to Microsoft Graph and display
/// the results.
/// </summary>
// <summary>
// Handle the "Sign In" button click. This will acquire an access token scoped to
// Microsoft Graph, either from the cache or from an interactive session. It will
// then use that access token in an HTTP request to Microsoft Graph and display
// the results.
// </summary>
private async void SignInButton_Click(object sender, EventArgs e)
{
AuthenticationResult? msalAuthenticationResult = null;
Expand Down
25 changes: 10 additions & 15 deletions desktop-winforms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ urlFragment: ms-identity-docs-code-app-csharp-winforms

# .NET | Windows Forms | user sign-in, protected web API access (Microsoft Graph) | Microsoft identity platform

<!-- Build badges here
![Build passing.](https://img.shields.io/badge/build-passing-brightgreen.svg) ![Code coverage.](https://img.shields.io/badge/coverage-100%25-brightgreen.svg) ![License.](https://img.shields.io/badge/license-MIT-green.svg)
-->

This .NET Windows Forms application authenticates a user and then makes a request to the Graph API as the authenticated user. The response to the request is presented to the user.

![A screenshot of a Windows Forms application displaying a response from Microsoft Graph.](./app.png)
Expand All @@ -43,7 +39,7 @@ Use these settings in your app registration.
| **Platform type** | **Mobile and desktop applications** | Required value for this sample |
| **Redirect URIs** | `http://localhost` | Required value for this sample |

> :information_source: **Bold text** in the tables above matches (or is similar to) a UI element in the Azure portal, while `code formatting` indicates a value you enter into a text box in the Azure portal.
> :information_source: **Bold text** in the tables above matches (or is similar to) a UI element in the Microsoft Entra admin center, while `code formatting` indicates a value you enter into a text box in the Microsoft Entra admin center.
### 2. Open the project in Visual Studio

Expand All @@ -54,39 +50,38 @@ Next, open the _MsalExamples.csproj_ project in Visual Studio.
Finally, set the following values in _MainWindow.cs_.

```csharp
// 'Tenant ID' of your Microsoft Entra instance - this value is a GUID
TenantId = "",
// Enter the tenant ID obtained from the Microsoft Entra admin center
TenantId = "Enter the client ID obtained from the Microsoft Entra admin center",

// 'Application (client) ID' of app registration in Azure portal - this value is a GUID
ClientId = ""
// Enter the client ID obtained from the Microsoft Entra admin center
ClientId = "Enter the tenant ID obtained from the Microsoft Entra admin center"
```

## Run the application

Run the application by pressing <kbd>F5</kbd> in Visual Studio.
Run the application by pressing **F5** in Visual Studio.

The appliction will open allowing you to click the **Sign In (if needed) & Call Graph** button to use the authentication flow.

![A screenshot of a Windows Forms application guiding the user to click the "Sign In" button.](./app-launch.png)

## About the code

This .NET 8 Windows Forms application presents a button that initiates an authentication flow using the Microsoft Authentication Library (MSAL). The user completes this flow in their default web browser. Upon successful authentication, an HTTP GET request to the Microsoft Graph /me endpoint is issued with the user's access token in the HTTP header. The response from the GET request is then displayed to the user. The MSAL client first looks to its token cache, refreshing if necessary, before acquiring a new access token.
This .NET 8 Windows Forms application presents a button that initiates an authentication flow using the Microsoft Authentication Library (MSAL). The user completes this flow in their default web browser. Upon successful authentication, an HTTP GET request to the Microsoft Graph /me endpoint is issued with the user's access token in the HTTP header. The response from the GET request is then displayed to the user. The MSAL client first looks to its token cache, refreshing if necessary, before acquiring a new access token.

## Reporting problems

### Sample app not working?

If you can't get the sample working, you've checked [Stack Overflow](http://stackoverflow.com/questions/tagged/msal), and you've already searched the issues in this sample's repository, open an issue report the problem.
1. Search the [GitHub issues](/issues) in the repository - your problem might already have been reported or have an answer.
1. Nothing similar? [Open an issue](/issues/new) that clearly explains the problem you're having running the sample app.
1. Search the [GitHub issues](../../issues) in the repository - your problem might already have been reported or have an answer.
1. Nothing similar? [Open an issue](../../issues/new) that clearly explains the problem you're having running the sample app.

### All other issues

> :warning: WARNING: Any issue in this repository _not_ limited to running one of its sample apps will be closed without being addressed.

For all other requests, see [Support and help options for developers | Microsoft identity platform](https://docs.microsoft.com/azure/active-directory/develop/developer-support-help-options).
For all other requests, see [Support and help options for developers | Microsoft identity platform](https://learn.microsoft.com/entra/identity-platform/developer-support-help-options).
## Contributing

Expand Down
8 changes: 4 additions & 4 deletions desktop-winui/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public MainWindow()
msalPublicClientApp = PublicClientApplicationBuilder
.CreateWithApplicationOptions(new PublicClientApplicationOptions
{
// 'Tenant ID' of your Microsoft Entra instance - this value is a GUID
TenantId = "",
// Enter the tenant ID obtained from the Microsoft Entra admin center
TenantId = "Enter the tenant ID obtained from the Microsoft Entra admin center",

// 'Application (client) ID' of app registration in Azure portal - this value is a GUID
ClientId = ""
// Enter the client ID obtained from the Microsoft Entra admin center
ClientId = "Enter the client ID obtained from the Microsoft Entra admin center"
})
.WithDefaultRedirectUri()
.Build();
Expand Down
6 changes: 3 additions & 3 deletions desktop-winui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ Use these settings in your app registration.
| **Platform type** | **Mobile and desktop applications** | Required value for this sample |
| **Redirect URIs** | `https://login.microsoftonline.com/common/oauth2/nativeclient` | Required value for this sample |

> :information_source: **Bold text** in the tables above matches (or is similar to) a UI element in the Azure portal, while `code formatting` indicates a value you enter into a text box in the Azure portal.
> :information_source: **Bold text** in the tables above matches (or is similar to) a UI element in the Microsoft Entra admin center, while `code formatting` indicates a value you enter into a text box in the Microsoft Entra admin center.
### 2. Open the project in Visual Studio

Next, open the _MsalExamples.csproj_ project in Visual Studio.
Next, open the _WinUIApp.csproj_ project in Visual Studio.

### 3. Update code sample in _MainWindow.xaml.cs_ with app registration values

Expand All @@ -58,7 +58,7 @@ Finally, set the following values in _MainWindow.xaml.cs_.
// 'Tenant ID' of your Microsoft Entra instance - this value is a GUID
TenantId = "",

// 'Application (client) ID' of app registration in Azure portal - this value is a GUID
// 'Application (client) ID' of app registration in Microsoft Entra admin center - this value is a GUID
ClientId = ""
```

Expand Down
4 changes: 2 additions & 2 deletions desktop-winui/WinUIApp.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.17763.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<RootNamespace>WinUIApp</RootNamespace>
<ApplicationManifest>app.manifest</ApplicationManifest>
Expand Down Expand Up @@ -36,6 +36,6 @@
Tools extension to be activated for this project even if the Windows App SDK Nuget
package has not yet been restored -->
<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnablePreviewMsixTooling)'=='true'">
<ProjectCapability Include="Msix"/>
<ProjectCapability Include="Msix" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion desktop-wpf/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public MainWindow()
// 'Tenant ID' of your Microsoft Entra instance - this value is a GUID
TenantId = "",

// 'Application (client) ID' of app registration in Azure portal - this value is a GUID
// 'Application (client) ID' of app registration in Microsoft Entra admin center - this value is a GUID
ClientId = ""
})
.WithDefaultRedirectUri() // http://localhost
Expand Down
4 changes: 2 additions & 2 deletions desktop-wpf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Use these settings in your app registration.
| **Platform type** | **Mobile and desktop applications** | Required value for this sample |
| **Redirect URIs** | `http://localhost` | Required value for this sample |

> :information_source: **Bold text** in the tables above matches (or is similar to) a UI element in the Azure portal, while `code formatting` indicates a value you enter into a text box in the Azure portal.
> :information_source: **Bold text** in the tables above matches (or is similar to) a UI element in the Microsoft Entra admin center, while `code formatting` indicates a value you enter into a text box in the Microsoft Entra admin center.
### 2. Open the project in Visual Studio

Expand All @@ -57,7 +57,7 @@ Finally, set the following values in _MainWindow.xaml.cs_.
// 'Tenant ID' of your Microsoft Entra instance - this value is a GUID
TenantId = "",

// 'Application (client) ID' of app registration in Azure portal - this value is a GUID
// 'Application (client) ID' of app registration in Microsoft Entra admin center - this value is a GUID
ClientId = ""
```

Expand Down
2 changes: 1 addition & 1 deletion spa-blazor-wasm/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
return new HttpClient(authorizationMessageHandler);
});

await builder.Build().RunAsync();
await builder.Build().RunAsync(CoreDispatcherPriority.Normal);
Loading

0 comments on commit 14f812f

Please sign in to comment.