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: articles/active-directory/develop/scenario-daemon-acquire-token.md
+76-36Lines changed: 76 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,11 +22,23 @@ After you've constructed a confidential client application, you can acquire a to
22
22
23
23
The scope to request for a client credential flow is the name of the resource followed by `/.default`. This notation tells Azure Active Directory (Azure AD) to use the *application-level permissions* declared statically during application registration. Also, these API permissions must be granted by a tenant administrator.
24
24
25
-
# [.NET](#tab/dotnet)
25
+
# [.NET](#tab/idweb)
26
26
27
-
```csharp
28
-
ResourceId="someAppIDURI";
29
-
varscopes=new [] { ResourceId+"/.default"};
27
+
Here's an example of defining the scopes for the web API as part of the configuration in an [*appsettings.json*](https://github.com/Azure-Samples/active-directory-dotnetcore-daemon-v2/blob/master/2-Call-OwnApi/daemon-console/appsettings.json) file. This example is taken from the [.NET Core console daemon](https://github.com/Azure-Samples/active-directory-dotnetcore-daemon-v2) code sample on GitHub.
28
+
29
+
```json
30
+
{
31
+
"AzureAd": {
32
+
// Same AzureAd section as before.
33
+
},
34
+
35
+
"MyWebApi": {
36
+
"BaseUrl": "https://localhost:44372/",
37
+
"RelativePath": "api/TodoList",
38
+
"RequestAppToken": true,
39
+
"Scopes": [ "[Enter here the scopes for your web API]" ]
40
+
}
41
+
}
30
42
```
31
43
32
44
# [Java](#tab/java)
@@ -53,6 +65,13 @@ In MSAL Python, the configuration file looks like this code snippet:
53
65
}
54
66
```
55
67
68
+
# [.NET (low level)](#tab/dotnet)
69
+
70
+
```csharp
71
+
ResourceId="someAppIDURI";
72
+
varscopes=new [] { ResourceId+"/.default"};
73
+
```
74
+
56
75
---
57
76
58
77
### Azure AD (v1.0) resources
@@ -65,42 +84,25 @@ The scope used for client credentials should always be the resource ID followed
65
84
66
85
## AcquireTokenForClient API
67
86
68
-
To acquire a token for the app, you'll use `AcquireTokenForClient` or its equivalent, depending on the platform.
87
+
To acquire a token for the app, use `AcquireTokenForClient` or its equivalent, depending on the platform.
69
88
70
-
# [.NET](#tab/dotnet)
89
+
# [.NET](#tab/idweb)
90
+
91
+
With Microsoft.Identity.Web, you don't need to acquire a token. You can use higher level APIs, as you see in [Calling a web API from a daemon application](scenario-daemon-call-api.md). If however you're using an SDK that requires a token, the following code snippet shows how to get this token.
71
92
72
93
```csharp
73
-
usingMicrosoft.Identity.Client;
94
+
usingMicrosoft.Extensions.DependencyInjection;
95
+
usingMicrosoft.Identity.Abstractions;
96
+
usingMicrosoft.Identity.Web;
74
97
75
-
// With client credentials flows, the scope is always of the shape "resource/.default" because the
76
-
// application permissions need to be set statically (in the portal or by PowerShell), and then granted by
### AcquireTokenForClient uses the application token cache
100
-
101
-
In MSAL.NET, `AcquireTokenForClient` uses the application token cache. (All the other AcquireToken*XX* methods use the user token cache.)
102
-
Don't call `AcquireTokenSilent` before you call `AcquireTokenForClient`, because `AcquireTokenSilent` uses the *user* token cache. `AcquireTokenForClient` checks the *application* token cache itself and updates it.
Don't call `AcquireTokenSilent` before you call `AcquireTokenForClient`, because `AcquireTokenSilent` uses the *user* token cache. `AcquireTokenForClient` checks the *application* token cache itself and updates it.
225
+
190
226
---
191
227
192
228
### Protocol
@@ -253,10 +289,10 @@ If your daemon app calls your own web API and you weren't able to add an app per
253
289
254
290
## Next steps
255
291
256
-
# [.NET](#tab/dotnet)
292
+
# [.NET](#tab/idweb)
257
293
258
294
Moveontothenextarticleinthisscenario,
259
-
[Calling a web API](./scenario-daemon-call-api.md?tabs=dotnet).
0 commit comments