File tree Expand file tree Collapse file tree 2 files changed +16
-8
lines changed
src/Authentication/Authentication Expand file tree Collapse file tree 2 files changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -1003,11 +1003,8 @@ 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 ;
1007+ GraphSession . Instance . Environment = _originalEnvironment ;
10111008 }
10121009
10131010 #region CmdLet LifeCycle
@@ -1046,8 +1043,6 @@ private async Task ProcessRecordAsync()
10461043 if ( ShouldCheckHttpStatus && ! isSuccess )
10471044 {
10481045 var httpErrorRecord = await GenerateHttpErrorRecordAsync ( httpResponseMessageFormatter , httpRequestMessage ) ;
1049- // A reset of the GraphSession Environment is required to avoid side effects
1050- ResetGraphSessionEnvironment ( ) ;
10511046 ThrowTerminatingError ( httpErrorRecord ) ;
10521047 }
10531048 await ProcessResponseAsync ( httpResponseMessage ) ;
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments