You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: powerapps-docs/developer/common-data-service/webapi/quick-start-blazor-server-app.md
+45-43Lines changed: 45 additions & 43 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,13 @@
1
1
---
2
-
title: "Quickstart: Web API sample (C#) (Common Data Service)| Microsoft Docs"
3
-
description: "This sample demonstrates how to authenticate with a Common Data Service Server and then call a basic Web API operation, the WhoAmI Function"
2
+
title: "Quickstart: Blazor Server Web API sample (C#) (Common Data Service)| Microsoft Docs"
3
+
description: "This sample demonstrates how to authenticate with a Common Data Service from a Blazor Server application and then call a basic WhoAmI Web API function."
4
4
ms.custom: ""
5
-
ms.date: 06/23/2020
5
+
ms.date: 07/07/2020
6
6
ms.service: powerapps
7
7
ms.topic: "article"
8
8
author: "JeremyLikness"# GitHub ID
9
9
ms.author: "jeliknes"# MSFT alias of Microsoft employees only
10
-
ms.reviewer: ""
10
+
ms.reviewer: "pehecke"
11
11
manager: ""# MSFT alias of manager or PM counterpart
12
12
search.audienceType:
13
13
- developer
@@ -19,49 +19,51 @@ search.app:
19
19
20
20
In this quickstart, you'll create a Blazor Server application to connect to your Common Data Service environment using the Web API.
21
21
22
-
You'll authenticate and use an <xref:System.Net.Http.HttpClient> to send a `GET` request to the <xrefhref="Microsoft.Dynamics.CRM.WhoAmI?text=WhoAmI Function" /> the response will be a <xrefhref="Microsoft.Dynamics.CRM.WhoAmIResponse?text=WhoAmIResponse ComplexType" />. You will display the `UserId` property value.
22
+
You'll authenticate and use <xref:System.Net.Http.HttpClient> to send a `GET` request containing the [WhoAmI](/dynamics365/customer-engagement/web-api/whoami) function. The response will be a [WhoAmIResponse](/dynamics365/customer-engagement/web-api/whoamiresponse) complex type. After call completion, the `UserId` property value is displayed.
23
23
24
24
> [!NOTE]
25
-
> This is a very simple example to show how to get connected with a minimum of code. The following [Enhanced quickstart](enhanced-quick-start.md) will build upon this sample to apply better design patterns.
25
+
> This is a very simple example to show how to get connected with a minimum of code. The [Enhanced quickstart](enhanced-quick-start.md) will build upon this sample to apply better design patterns.
26
26
27
27
## Prerequisites
28
28
29
-
- Visual Studio (2019 16.6.2 recommended)
30
-
- Familiarity with the Azure portal
29
+
- Visual Studio 2019 (version 16.6.2 or later recommended)
30
+
- Familiarity with the Microsoft Azure portal
31
31
- Internet connection
32
32
- Valid user account for a Common Data Service instance
33
-
-Admin access to grant application registrations
33
+
-Administrator access to grant application registrations
34
34
- URL to the Common Data Service environment you want to connect with
35
35
- Basic understanding of the Visual C# language
36
36
37
37
> [!NOTE]
38
38
> To authenticate you must have an app registered in Azure Active Directory. The registration will happen automatically as part of the template creation, but will require additional updates in the Azure portal.
39
39
40
-
## Create Visual Studio project
40
+
## Create a Visual Studio project
41
41
42
-
1. Create a new Blazor Server App using **.NET Core 3.1** - _don't_ click "Create" yet
42
+
1. Create a new Blazor Server app using .NET Core 3.1 but don't choose **Create** just yet.
43
43
44
44

45
45
46
-
1.Click "Change" under "Authentication" and choose "Work or School Accounts." Choose the appropriate dropdown. Replace `CRM520451` in the example with your organization name.
46
+
1.Select **Change** under **Authentication** and then choose **Work or School Accounts**.
1.Choose the appropriate dropdown and then replace `CRM520451` in the example with your environment's name.
51
51
52
-
## Configure the Application in Active Directory
52
+
1. Select **Create**.
53
53
54
-
By default, the template will create a registered application. Connecting to Common Data Services will require additional permissions. Open the Azure portal and log in with your credentials. Navigate to "Active Directory" and "App Registrations" and choose the entry with the same name as your application.
54
+
## Configure the applicationin Active Directory
55
55
56
-
1. Choose "Authentication" and check "Access tokens" under "Implicit grant" then click "Save".
56
+
By default, the template will create a registered application. Connecting to Common Data Service will require additional permissions. Open the Azure portal and log in with your credentials. Navigate to **Active Directory** and **App Registrations**, and then choose the entry with the same name as your application.
57
+
58
+
1. Choose **Authentication**, select (check) **Access tokens** under **Implicit grant**, and then click **Save**.
1. Click on the newly created permission to highlight it and click "Grant admin consent for organization" (organization will have your organization name).
93
+
1. Select the newly created permission to highlight it, and then shoose **Grant admin consent for organization** (your environment name is shown)
92
94
93
-
1. Verify the permissions have green checkboxes in the "status" column
95
+
1. Verify the permissions have green checkboxes in the **status** column
94
96
95
97
## Prepare the app to use Azure AD tokens
96
98
97
99
The application requires some extra steps to capture the authentication token and pass it to the Web API request.
98
100
99
-
1. Right-click on the `Data` folder and add a new class named `TokenProvider`
101
+
1. Right-click on the **Data** folder and add a new class named `TokenProvider`.
100
102
101
103
```csharp
102
104
public class TokenProvider
@@ -105,14 +107,14 @@ The application requires some extra steps to capture the authentication token an
105
107
}
106
108
```
107
109
108
-
1. Open `App.razor` and add these statements to the top. Change the namespace to match the name of your application.
110
+
1. Open the App.razor file and add the following statements to the top of the file. Change the namespace to match the name of your application.
109
111
110
112
```razor
111
113
@using BlazorWebAPIExample.Data
112
114
@inject TokenProvider Service
113
115
```
114
116
115
-
1. Add a `@code` block to accept a parameter and move the token into the service
117
+
1. Add a `@code` block to accept a parameter and move the token into the service.
116
118
117
119
```csharp
118
120
[Parameter]
@@ -125,14 +127,14 @@ The application requires some extra steps to capture the authentication token an
125
127
}
126
128
```
127
129
128
-
1. Open `Pages/_Host.cshtml` and add the following using statements after the namespace declaration:
130
+
1. Open the Pages/\_Host.cshtml file and add the following using statements after the namespace declaration.
129
131
130
132
```razor
131
133
@using BlazorCommonDataService.Data
132
134
@using Microsoft.AspNetCore.Authentication
133
135
```
134
136
135
-
1. After the `<body>` tag, add the following code and update the app component to acquire and pass the token:
137
+
1. After the `<body>` tag, add the following code and update the app component to acquire and pass the token.
136
138
137
139
```razor
138
140
@{
@@ -146,21 +148,21 @@ The application requires some extra steps to capture the authentication token an
146
148
</app>
147
149
```
148
150
149
-
1. Obtain the organization name for the Common Data Services management API. If you're not sure what the name is, open the [Power Platform admin center](https://admin.powerplatform.microsoft.com/environments), navigate to "environments" then choose "open environment." You will see a URL like this: `https://{org}.crm.dynamics.com`
151
+
1. Obtain the environment name for the Common Data Services management API. If you're not sure what the name is, open the [Power Platform admin center](https://admin.powerplatform.microsoft.com/environments), navigate to **Environments** then choose **Open environment**. You will see a URL like this: `https://{org}.crm.dynamics.com` where {org} is the environment name.
150
152
151
-
1. Add an entry to `appsettings.json` named `CDSAPI` with the URL. Add `/api/data/v.9.0/` to the end, so it looks like this:
153
+
1. Add an entry named `CDSAPI` to the appsettings.json file with the environment URL as the value. Append `/api/data/v.9.0/` to the end of the URL so it looks like this:
1. Add this `using` statement to the file Startup.cs.
158
160
159
161
```csharp
160
162
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
161
163
```
162
164
163
-
1. In the `Startup.cs` class, add registrations to retrieve the tokens and configure a client ready to use the token. Place this code between `services.AddAuthentication` and `services.AddControllersWithViews`.
165
+
1. In the `Startup.cs` class, add registrations to retrieve the authentication token and configure a client ready to use the token. Place this code between `services.AddAuthentication` and `services.AddControllersWithViews`.
@@ -181,13 +183,13 @@ The application requires some extra steps to capture the authentication token an
181
183
});
182
184
```
183
185
184
-
The first registration allows requesting the token with the proper scope. The second registers the service that tracks the token, and the third creates a client with the base API address pre-configured.
186
+
The first registration allows requesting the token with the proper scope. The second registers the service that tracks the token, and the third creates a client with the base API address pre-configured.
185
187
186
188
## Make a call to the Web API
187
189
188
190
Next, you'll update the `Index.razor` component to call the Web API.
189
191
190
-
1. Open `Index.razor` and add these statements to the top:
192
+
1. Open the Index.razor file and add these statements to the top:
191
193
192
194
```razor
193
195
@using System.Text.Json
@@ -247,7 +249,7 @@ Next, you'll update the `Index.razor` component to call the Web API.
247
249
}
248
250
```
249
251
250
-
The application is ready!
252
+
The application is now ready!
251
253
252
254
## Run the program
253
255
@@ -257,14 +259,14 @@ Press F5 to run the program. The output should look like this:
257
259
258
260
**Congratulations!** You have successfully connected to the Web API.
259
261
260
-
This quickstart sample shows a simple approach to create a Visual Studio project without any exception handling or method to refresh the access token. You can expand on the example to perform more complex operations, and wrap the `HttpClient` in a service class to handle the permissions.
262
+
This quickstart sample shows a simple approach to create a Visual Studio project without any exception handling or method to refresh the access token. You can expand on the example to perform more complex operations, and wrap the `HttpClient` object in a service class to handle the permissions.
261
263
262
264
The [Enhanced quickstart](enhanced-quick-start.md) topic shows how to:
263
265
264
-
- implement exception handling methods
265
-
- basic authentication method using a connection string
266
-
- create a reusable method to refresh the access token
267
-
- build reusable methods for data operations
266
+
- Implement exception handling methods
267
+
- Use basic authentication with a connection string
268
+
- Create a reusable method to refresh the access token
0 commit comments