@@ -39,6 +39,7 @@ public class EntraMockResponsePlugin(IPluginEvents pluginEvents, IProxyContext c
39
39
40
40
public override string Name => nameof ( EntraMockResponsePlugin ) ;
41
41
42
+ // Running on POST requests with a body
42
43
protected override void ProcessMockResponse ( ref byte [ ] body , IList < MockResponseHeader > headers , ProxyRequestArgs e , MockResponse ? matchingResponse )
43
44
{
44
45
base . ProcessMockResponse ( ref body , headers , e , matchingResponse ) ;
@@ -47,7 +48,7 @@ protected override void ProcessMockResponse(ref byte[] body, IList<MockResponseH
47
48
var changed = false ;
48
49
49
50
StoreLastNonce ( e ) ;
50
- UpdateMsalState ( ref bodyString , e , ref changed ) ;
51
+ UpdateMsalStateInBody ( ref bodyString , e , ref changed ) ;
51
52
UpdateIdToken ( ref bodyString , e , ref changed ) ;
52
53
UpdateDevProxyKeyId ( ref bodyString , ref changed ) ;
53
54
UpdateDevProxyCertificateChain ( ref bodyString , ref changed ) ;
@@ -58,6 +59,15 @@ protected override void ProcessMockResponse(ref byte[] body, IList<MockResponseH
58
59
}
59
60
}
60
61
62
+ // Running on GET requests without a body
63
+ protected override void ProcessMockResponse ( ref string ? body , IList < MockResponseHeader > headers , ProxyRequestArgs e , MockResponse ? matchingResponse )
64
+ {
65
+ base . ProcessMockResponse ( ref body , headers , e , matchingResponse ) ;
66
+
67
+ StoreLastNonce ( e ) ;
68
+ UpdateMsalStateInHeaders ( headers , e ) ;
69
+ }
70
+
61
71
private void UpdateDevProxyCertificateChain ( ref string bodyString , ref bool changed )
62
72
{
63
73
if ( ! bodyString . Contains ( "@dynamic.devProxyCertificateChain" ) )
@@ -127,7 +137,22 @@ private static string PadBase64(string base64)
127
137
return base64 + padding ;
128
138
}
129
139
130
- private void UpdateMsalState ( ref string body , ProxyRequestArgs e , ref bool changed )
140
+ private static void UpdateMsalStateInHeaders ( IList < MockResponseHeader > headers , ProxyRequestArgs e )
141
+ {
142
+ var locationHeader = headers . FirstOrDefault ( h => h . Name . Equals ( "Location" , StringComparison . OrdinalIgnoreCase ) ) ;
143
+
144
+ if ( locationHeader is null ||
145
+ ! e . Session . HttpClient . Request . RequestUri . Query . Contains ( "state=" ) )
146
+ {
147
+ return ;
148
+ }
149
+
150
+ var queryString = HttpUtility . ParseQueryString ( e . Session . HttpClient . Request . RequestUri . Query ) ;
151
+ var msalState = queryString [ "state" ] ;
152
+ locationHeader . Value = locationHeader . Value . Replace ( "state=@dynamic" , $ "state={ msalState } ") ;
153
+ }
154
+
155
+ private static void UpdateMsalStateInBody ( ref string body , ProxyRequestArgs e , ref bool changed )
131
156
{
132
157
if ( ! body . Contains ( "state=@dynamic" ) ||
133
158
! e . Session . HttpClient . Request . RequestUri . Query . Contains ( "state=" ) )
0 commit comments