Skip to content

Commit 60b9c23

Browse files
authored
Merge branch 'dev' into WeeklyApiRefresh/202409250809
2 parents bbe81c8 + d493619 commit 60b9c23

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/Authentication/Authentication/Cmdlets/InvokeMgGraphRequest.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,11 +1003,7 @@ private string QualifyFilePath(string path)
10031003
/// </summary>
10041004
private void ResetGraphSessionEnvironment()
10051005
{
1006-
var currentEnvironment = GraphSession.Instance.Environment;
1007-
if(currentEnvironment != null && !currentEnvironment.Equals(_originalEnvironment))
1008-
{
1009-
GraphSession.Instance.Environment = _originalEnvironment;
1010-
}
1006+
_originalEnvironment = GraphSession.Instance.Environment;
10111007
}
10121008

10131009
#region CmdLet LifeCycle
@@ -1046,8 +1042,6 @@ private async Task ProcessRecordAsync()
10461042
if (ShouldCheckHttpStatus && !isSuccess)
10471043
{
10481044
var httpErrorRecord = await GenerateHttpErrorRecordAsync(httpResponseMessageFormatter, httpRequestMessage);
1049-
// A reset of the GraphSession Environment is required to avoid side effects
1050-
ResetGraphSessionEnvironment();
10511045
ThrowTerminatingError(httpErrorRecord);
10521046
}
10531047
await ProcessResponseAsync(httpResponseMessage);

src/Authentication/Authentication/custom/common/Permissions.ps1

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,20 @@ function Permissions_GetPermissionsData([bool] $online) {
3434
# Make a REST request to MS Graph to get the permissions data from the Microsoft Graph service principal
3535
if ( $online -or ! $_permissions.msGraphServicePrincipal -or ! $_permissions.isFromInvokeMgGraphRequest ) {
3636
try {
37-
$restResult = Invoke-MgGraphRequest -method GET -OutputType PSObject $_permissions.msGraphPermissionsRequestUri
37+
38+
# Get-MgContext is used to get the current context for the request to MS Graph
39+
# From the context, we can get the current environment and use it to get the permissions request URI
40+
# If the context is not available, then we will use the default permissions request URI
41+
42+
$context = Get-MgContext
43+
$uri = $_permissions.msGraphPermissionsRequestUri
44+
if($context){
45+
$currentEnv = $context.Environment
46+
$allEnv = Get-MgEnvironment
47+
$env = $allEnv | Where-Object { $_.Name -eq $currentEnv }
48+
$uri = $env.GraphEndpoint + "/v1.0/servicePrincipals?`$filter=appId eq '$Permissions_msGraphApplicationId'"
49+
}
50+
$restResult = Invoke-MgGraphRequest -method GET -OutputType PSObject $uri
3851

3952
if ( $restResult ) {
4053
$_permissions.msGraphServicePrincipal = $restResult | Select-Object -ExpandProperty value

0 commit comments

Comments
 (0)