Skip to content

Commit a30633c

Browse files
Merge branch 'main' into ModuleCommandMetadataRefresh/202604010009
2 parents 18743b9 + 3367405 commit a30633c

File tree

186 files changed

+4119
-749
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

186 files changed

+4119
-749
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
### Example
2+
3+
```powershell
4+
5+
Import-Module Microsoft.Graph.Beta.Applications
6+
7+
Get-MgBetaServicePrincipalSynchronizationTemplate -ServicePrincipalId $servicePrincipalId
8+
9+
```
10+
This example shows how to use the Get-MgBetaServicePrincipalSynchronizationTemplate Cmdlet.
11+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
### Example
2+
3+
```powershell
4+
5+
Import-Module Microsoft.Graph.Applications
6+
7+
Get-MgServicePrincipalSynchronizationTemplate -ServicePrincipalId $servicePrincipalId
8+
9+
```
10+
This example shows how to use the Get-MgServicePrincipalSynchronizationTemplate Cmdlet.
11+

src/Authentication/Authentication.Core/Utilities/AuthenticationHelpers.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,19 @@ private static async Task<DeviceCodeCredential> GetDeviceCodeCredentialAsync(IAu
160160
TokenCachePersistenceOptions = GetTokenCachePersistenceOptions(authContext),
161161
DeviceCodeCallback = (code, cancellation) =>
162162
{
163-
GraphSession.Instance.OutputWriter.WriteObject(code.Message);
163+
if (GraphSession.Exists)
164+
{
165+
try
166+
{
167+
GraphSession.Instance.OutputWriter.WriteObject(code.Message);
168+
return Task.CompletedTask;
169+
}
170+
catch (InvalidOperationException)
171+
{
172+
// Fall through to console output if OutputWriter is unavailable.
173+
}
174+
}
175+
Console.WriteLine(code.Message);
164176
return Task.CompletedTask;
165177
}
166178
};
@@ -272,12 +284,14 @@ public static async Task<IAuthContext> AuthenticateAsync(IAuthContext authContex
272284
return signInAuthContext;
273285
}
274286

275-
private static async Task<IAuthContext> SignInAsync(IAuthContext authContext, CancellationToken cancellationToken = default)
287+
internal static async Task<IAuthContext> SignInAsync(IAuthContext authContext, CancellationToken cancellationToken = default, TokenCredential tokenCredential = null)
276288
{
277289
if (authContext is null)
278290
throw new AuthenticationException(ErrorConstants.Message.MissingAuthContext);
279-
var tokenCredential = await GetTokenCredentialAsync(authContext, cancellationToken).ConfigureAwait(false);
280-
var token = await tokenCredential.GetTokenAsync(new TokenRequestContext(GetScopes(authContext)), cancellationToken).ConfigureAwait(false);
291+
tokenCredential ??= await GetTokenCredentialAsync(authContext, cancellationToken).ConfigureAwait(false);
292+
// Use isCaeEnabled: true to match the TokenRequestContext that AzureIdentityAccessTokenProvider will use
293+
// during API calls, ensuring MSAL caches a CAE-capable token that can be found silently later.
294+
var token = await tokenCredential.GetTokenAsync(new TokenRequestContext(GetScopes(authContext), isCaeEnabled: true), cancellationToken).ConfigureAwait(false);
281295
JwtHelpers.DecodeJWT(token.Token, account: null, ref authContext);
282296
return authContext;
283297
}

0 commit comments

Comments
 (0)