Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<LangVersion>9.0</LangVersion>
<TargetFrameworks>netstandard2.0;net6.0;net472</TargetFrameworks>
<RootNamespace>Microsoft.Graph.PowerShell.Authentication.Core</RootNamespace>
<Version>2.32.0</Version>
<Version>2.35.1</Version>
<!-- Suppress .NET Target Framework Moniker (TFM) Support Build Warnings -->
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ public void ShouldLoadSettingsFromConfiguredDataStore()

// Assert
Assert.NotNull(loadedEnvironment);
// 5 built-in + 2 user-defined
Assert.Equal(7, settings.Environments.Count());
// 7 built-in + 2 user-defined
Assert.Equal(9, settings.Environments.Count());
Assert.Equal("https://login.MyNewCloud.com", loadedEnvironment.AzureADEndpoint);
Assert.Equal("https://graph.MyNewCloud.com", loadedEnvironment.GraphEndpoint);
Assert.Equal(GraphEnvironmentConstants.EnvironmentType.UserDefined, loadedEnvironment.Type);
Expand Down Expand Up @@ -155,8 +155,8 @@ public void ShouldRemoveSettingsFromConfiguredDataStore()

// Assert
Assert.NotEmpty(settingsContent);
// 5 built-in + 1 user-defined
Assert.Equal(6, settings.Environments.Count());
// 7 built-in + 1 user-defined
Assert.Equal(8, settings.Environments.Count());

GraphSession.Reset();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ public async Task ShouldUseGlobalCloudWhenEnvironmentIsNotSet()
}

[Fact]
public async Task ShouldUseGermanyCloudWhenEnvironmentIsSetToGermany()
public async Task ShouldUseDelosCloudWhenEnvironmentIsSetToDelos()
{
GraphSession.Initialize(() => new GraphSession());

// Arrange
GraphEnvironment germanyEnvironment = GraphEnvironment.BuiltInEnvironments[GraphEnvironmentConstants.EnvironmentName.Germany];
GraphSession.Instance.Environment = germanyEnvironment;
GraphEnvironment delosEnvironment = GraphEnvironment.BuiltInEnvironments[GraphEnvironmentConstants.EnvironmentName.DelosCloud];
GraphSession.Instance.Environment = delosEnvironment;
Uri requestUrl = new Uri($"https://graph.microsoft.com/beta/users?{topParam}&{selectParam}");
var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUrl);

Expand All @@ -80,7 +80,7 @@ public async Task ShouldUseGermanyCloudWhenEnvironmentIsSetToGermany()

// Assert
Assert.Equal(requestUrl.Scheme, response.RequestMessage.RequestUri.Scheme);
Assert.Equal("graph.microsoft.de", response.RequestMessage.RequestUri.Host);
Assert.Equal("graph.svc.sovcloud.de", response.RequestMessage.RequestUri.Host);
Assert.Contains(topParam, sentRequestQuery);
Assert.Contains(selectParam, sentRequestQuery);
Assert.Equal(2, sentRequestQuery.Split('&').Length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFrameworks>net8.0;net472</TargetFrameworks>
<IsPackable>false</IsPackable>
<Version>2.32.0</Version>
<Version>2.35.1</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.2" />
Expand Down
58 changes: 44 additions & 14 deletions src/Authentication/Authentication/GraphEnvironmentConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,24 @@ public static class EnvironmentName
public const string USGovDoD = "USGovDoD";

/// <summary>
/// The graph national cloud for Germany.
/// The graph national cloud for China.
/// </summary>
public const string Germany = "Germany";
public const string China = "China";

/// <summary>
/// The graph national cloud for China.
/// The French sovereign cloud operated by Bleu.
/// </summary>
public const string China = "China";
public const string BleuCloud = "BleuCloud";

/// <summary>
/// The German sovereign cloud operated by Delos.
/// </summary>
public const string DelosCloud = "DelosCloud";

/// <summary>
/// The Singapore government sovereign cloud.
/// </summary>
public const string GovSGCloud = "GovSGCloud";
}

/// <summary>
Expand Down Expand Up @@ -84,16 +94,6 @@ public static class EnvironmentType
GraphEndpoint = "https://dod-graph.microsoft.us"
}
},
// Germany national cloud endpoints.
{
EnvironmentName.Germany, new GraphEnvironment
{
Name = EnvironmentName.Germany,
Type = EnvironmentType.BuiltIn,
AzureADEndpoint = "https://login.microsoftonline.de",
GraphEndpoint = "https://graph.microsoft.de"
}
},
// China national cloud endpoints.
{
EnvironmentName.China, new GraphEnvironment
Expand All @@ -103,6 +103,36 @@ public static class EnvironmentType
AzureADEndpoint = "https://login.chinacloudapi.cn",
GraphEndpoint = "https://microsoftgraph.chinacloudapi.cn"
}
},
// French sovereign cloud endpoints.
{
EnvironmentName.BleuCloud, new GraphEnvironment
{
Name = EnvironmentName.BleuCloud,
Type = EnvironmentType.BuiltIn,
AzureADEndpoint = "https://login.sovcloud-identity.fr",
GraphEndpoint = "https://graph.svc.sovcloud.fr"
}
},
// German sovereign cloud endpoints.
{
EnvironmentName.DelosCloud, new GraphEnvironment
{
Name = EnvironmentName.DelosCloud,
Type = EnvironmentType.BuiltIn,
AzureADEndpoint = "https://login.sovcloud-identity.de",
GraphEndpoint = "https://graph.svc.sovcloud.de"
}
},
// Singapore government sovereign cloud endpoints.
{
EnvironmentName.GovSGCloud, new GraphEnvironment
{
Name = EnvironmentName.GovSGCloud,
Type = EnvironmentType.BuiltIn,
AzureADEndpoint = "https://login.sovcloud-identity.sg",
GraphEndpoint = "https://graph.svc.sovcloud.sg"
}
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<WarningsAsErrors />
<NuspecFile>Microsoft.Graph.Authentication.nuspec</NuspecFile>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<Version>2.32.0</Version>
<Version>2.35.1</Version>
</PropertyGroup>
<PropertyGroup>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<package>
<metadata>
<version>2.32.0</version>
<version>2.35.1</version>
<id>Microsoft.Graph.Authentication</id>
<description>Microsoft Graph PowerShell authentication module</description>
<authors>Microsoft</authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: Microsoft
#
# Generated on: 21/09/2023
# Generated on: 02/12/2026
#

@{
Expand All @@ -12,13 +12,13 @@
RootModule = './Microsoft.Graph.Authentication.psm1'

# Version number of this module.
ModuleVersion = '2.6.1'
ModuleVersion = '2.35.1'

# Supported PSEditions
CompatiblePSEditions = 'Core', 'Desktop'

# ID used to uniquely identify this module
GUID = '883916f2-9184-46ee-b1f8-b6a2fb784cee'
GUID = '44776453-fc06-4f89-94c9-f0bd6578afa1'

# Author of this module
Author = 'Microsoft'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ Describe 'Get-MgContext' {


It 'Should return the correct environment when specified via Connect-MgGraph -Environment' {
Connect-MgGraph -AccessToken (ConvertTo-SecureString -AsPlainText -String $DummyToken) -Environment Germany
Connect-MgGraph -AccessToken (ConvertTo-SecureString -AsPlainText -String $DummyToken) -Environment DelosCloud
$Context = Get-MgContext
$Context | Should -Not -Be $null
$Context.Environment | Should -Be "Germany"
$Context.Environment | Should -Be "DelosCloud"
$Context.AuthType | Should -Be "UserProvidedAccessToken"
}
}
Expand Down
21 changes: 8 additions & 13 deletions src/Authentication/docs/Add-MgEnvironment.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
---
external help file: Microsoft.Graph.Authentication.dll-Help.xml
Module Name: Microsoft.Graph.Authentication
online version: https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.authentication/add-mgenvironment
Expand All @@ -7,31 +7,27 @@ schema: 2.0.0

# Add-MgEnvironment

## SYNOPSIS
Adds Microsoft Graph environment to the settings file.

## SYNOPSIS
Adds Microsoft Graph environment to the settings file.
## SYNTAX

```
Add-MgEnvironment [-Name] <String> [-AzureADEndpoint] <String> [-GraphEndpoint] <String> [-WhatIf] [-Confirm]
[<CommonParameters>]
```

## DESCRIPTION
Adds Microsoft Graph environment to the settings file.

## EXAMPLES

## DESCRIPTION
Adds Microsoft Graph environment to the settings file.
## EXAMPLES
### Example 1: Add user defined environment
```powershell
PS C:\> Add-MgEnvironment -Name "Canary" -GraphEndpoint "https://canary.graph.microsoft.com" -AzureADEndpoint "https://login.microsoftonline.com"
Name AzureADEndpoint GraphEndpoint Type
---- --------------- ------------- ----
Canary https://login.microsoftonline.com https://microsoftgraph.com User-defined
```

Adds user defined environment.

## PARAMETERS

### -AzureADEndpoint
Expand Down Expand Up @@ -125,5 +121,4 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable

## RELATED LINKS

[https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.authentication/add-mgenvironment](https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.authentication/add-mgenvironment)

[https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.authentication/add-mgenvironment](https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.authentication/add-mgenvironment
33 changes: 9 additions & 24 deletions src/Authentication/docs/Connect-MgGraph.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
---
external help file: Microsoft.Graph.Authentication.dll-Help.xml
Module Name: Microsoft.Graph.Authentication
online version: https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.authentication/connect-mggraph
Expand All @@ -7,9 +7,8 @@ schema: 2.0.0

# Connect-MgGraph

## SYNOPSIS
Microsoft Graph PowerShell supports two types of authentication: delegated and app-only access. There are a number of cmdlets that can be used to manage the different parameters required during authentication, for example, environment, application ID, and certificate.

## SYNOPSIS
Microsoft Graph PowerShell supports two types of authentication: delegated and app-only access. There are a number of cmdlets that can be used to manage the different parameters required during authentication, for example, environment, application ID, and certificate.
## SYNTAX

### UserParameterSet (Default)
Expand Down Expand Up @@ -50,82 +49,71 @@ Connect-MgGraph [-ContextScope <ContextScope>] [-Environment <String>] [-ClientT
[-EnvironmentVariable] [-NoWelcome] [<CommonParameters>]
```

## DESCRIPTION
You must invoke Connect-MgGraph before any commands that access Microsoft Graph. This cmdlet gets the access token using the Microsoft Authentication Library

## EXAMPLES

## DESCRIPTION
You must invoke Connect-MgGraph before any commands that access Microsoft Graph. This cmdlet gets the access token using the Microsoft Authentication Library
## EXAMPLES
### Example 1: Delegated access: Using interactive authentication, where you provide the scopes that you require during your session
```powershell
PS C:\> Connect-MgGraph -Scopes "User.Read.All", "Group.ReadWrite.All"
```

This example shows how to authenticate to graph with scopes.

### Example 2: Delegated access: Using device code flow
```powershell
PS C:\> Connect-MgGraph -Scopes "User.Read.All", "Group.ReadWrite.All" -UseDeviceAuthentication
```

This example shows how to authenticate to graph with scopes and device.

### Example 3: Delegated access: Using your own access token
```powershell
PS C:\> Connect-MgGraph -AccessToken $AccessToken
```

This example shows how to authenticate to graph using an access token.

### Example 4: Delegated access: custom application for Microsoft Graph PowerShell
```powershell
PS C:\> Connect-MgGraph -ClientId <YOUR_NEW_APP_ID> -TenantId <YOUR_TENANT_ID>
```

Follow this [link](https://learn.microsoft.com/en-us/powershell/microsoftgraph/authentication-commands?view=graph-powershell-1.0#using-connect-mggraph) for more information on the steps for creating custom applications.

### Example 5: App-only access: Using client credential with a certificate - Certificate Thumbprint
```powershell
PS C:\> Connect-MgGraph -ClientId "YOUR_APP_ID" -TenantId "YOUR_TENANT_ID" -CertificateThumbprint "YOUR_CERT_THUMBPRINT"
```

Follow this [link](https://learn.microsoft.com/en-us/powershell/microsoftgraph/authentication-commands?view=graph-powershell-1.0#using-connect-mggraph) for more information on how to load the certificate.

### Example 6: App-only access: Using client credential with a certificate - Certificate name
```powershell
PS C:\> Connect-MgGraph -ClientId "YOUR_APP_ID" -TenantId "YOUR_TENANT_ID" -CertificateName "YOUR_CERT_SUBJECT"
```

Follow this [link](https://learn.microsoft.com/en-us/powershell/microsoftgraph/authentication-commands?view=graph-powershell-1.0#using-connect-mggraph) for more information on how to load the certificate.

### Example 7: App-only access: Using client credential with a certificate - Certificate
```powershell
PS C:\> $Cert = Get-ChildItem Cert:\LocalMachine\My\$CertThumbprint
PS C:\> Connect-MgGraph -ClientId "YOUR_APP_ID" -TenantId "YOUR_TENANT_ID" -Certificate $Cert
```

Follow this [link](https://learn.microsoft.com/en-us/powershell/microsoftgraph/authentication-commands?view=graph-powershell-1.0#using-connect-mggraph) for more information on how to load the certificate.


### Example 8: Using client secret credentials
```powershell
PS C:\> $ClientSecretCredential = Get-Credential -Credential "Client_Id"
# Enter client_secret in the password prompt.
PS C:\> Connect-MgGraph -TenantId "Tenant_Id" -ClientSecretCredential $ClientSecretCredential
```

This authentication method is ideal for background interactions. It does not require a user to physically sign in.

### Example 9: Using managed identity: System-assigned managed identity
```powershell
PS C:\> Connect-MgGraph -Identity
```

Uses an automatically managed identity on a service instance. The identity is tied to the lifecycle of a service instance.

### Example 10: Using managed identity: User-assigned managed identity
```powershell
PS C:\> Connect-MgGraph -Identity -ClientId "User_Assigned_Managed_identity_Client_Id"
```

Uses a user created managed identity as a standalone Azure resource.

### Example 11: Connecting to an environment or cloud
Expand All @@ -139,16 +127,14 @@ USGov https://login.microsoftonline.us https://graph.microsoft.us
USGovDoD https://login.microsoftonline.us https://dod-graph.microsoft.us Built-in
PS C:\> Connect-MgGraph -Environment USGov
```

When you use Connect-MgGraph, you can choose to target other environments. By default, Connect-MgGraph targets the global public cloud.

### Example 12: Connecting to an environment as a different identity
```powershell
PS C:\> Connect-MgGraph -ContextScope Process
```

To connect as a different identity other than CurrentUser, specify the -ContextScope parameter with the value Process.

## PARAMETERS

### -AccessToken
Expand Down Expand Up @@ -412,5 +398,4 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable

## RELATED LINKS

[https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.authentication/connect-mggraph](https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.authentication/connect-mggraph)

[https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.authentication/connect-mggraph](https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.authentication/connect-mggraph
Loading
Loading