File tree Expand file tree Collapse file tree 2 files changed +15
-8
lines changed
src/Authentication/Authentication Expand file tree Collapse file tree 2 files changed +15
-8
lines changed Original file line number Diff line number Diff line change @@ -1003,11 +1003,7 @@ private string QualifyFilePath(string path)
1003
1003
/// </summary>
1004
1004
private void ResetGraphSessionEnvironment ( )
1005
1005
{
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 ;
1011
1007
}
1012
1008
1013
1009
#region CmdLet LifeCycle
@@ -1046,8 +1042,6 @@ private async Task ProcessRecordAsync()
1046
1042
if ( ShouldCheckHttpStatus && ! isSuccess )
1047
1043
{
1048
1044
var httpErrorRecord = await GenerateHttpErrorRecordAsync ( httpResponseMessageFormatter , httpRequestMessage ) ;
1049
- // A reset of the GraphSession Environment is required to avoid side effects
1050
- ResetGraphSessionEnvironment ( ) ;
1051
1045
ThrowTerminatingError ( httpErrorRecord ) ;
1052
1046
}
1053
1047
await ProcessResponseAsync ( httpResponseMessage ) ;
Original file line number Diff line number Diff line change @@ -34,7 +34,20 @@ function Permissions_GetPermissionsData([bool] $online) {
34
34
# Make a REST request to MS Graph to get the permissions data from the Microsoft Graph service principal
35
35
if ( $online -or ! $_permissions.msGraphServicePrincipal -or ! $_permissions.isFromInvokeMgGraphRequest ) {
36
36
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
38
51
39
52
if ( $restResult ) {
40
53
$_permissions.msGraphServicePrincipal = $restResult | Select-Object - ExpandProperty value
You can’t perform that action at this time.
0 commit comments