@@ -65,15 +65,7 @@ public async Task<IActionResult> Index()
65
65
//
66
66
if ( response . StatusCode == System . Net . HttpStatusCode . Unauthorized )
67
67
{
68
- var todoTokens = authContext . TokenCache . ReadItems ( ) . Where ( a => a . Resource == AzureAdOptions . Settings . TodoListResourceId ) ;
69
- foreach ( TokenCacheItem tci in todoTokens )
70
- authContext . TokenCache . DeleteItem ( tci ) ;
71
-
72
- ViewBag . ErrorMessage = "UnexpectedError" ;
73
- TodoItem newItem = new TodoItem ( ) ;
74
- newItem . Title = "(No items in list)" ;
75
- itemList . Add ( newItem ) ;
76
- return View ( itemList ) ;
68
+ return ProcessUnauthorized ( itemList , authContext ) ;
77
69
}
78
70
}
79
71
catch ( Exception )
@@ -102,8 +94,6 @@ public async Task<IActionResult> Index()
102
94
return View ( "Error" ) ;
103
95
}
104
96
105
-
106
-
107
97
[ HttpPost ]
108
98
public async Task < ActionResult > Index ( string item )
109
99
{
@@ -148,15 +138,7 @@ public async Task<ActionResult> Index(string item)
148
138
//
149
139
if ( response . StatusCode == System . Net . HttpStatusCode . Unauthorized )
150
140
{
151
- var todoTokens = authContext . TokenCache . ReadItems ( ) . Where ( a => a . Resource == AzureAdOptions . Settings . TodoListResourceId ) ;
152
- foreach ( TokenCacheItem tci in todoTokens )
153
- authContext . TokenCache . DeleteItem ( tci ) ;
154
-
155
- ViewBag . ErrorMessage = "UnexpectedError" ;
156
- TodoItem newItem = new TodoItem ( ) ;
157
- newItem . Title = "(No items in list)" ;
158
- itemList . Add ( newItem ) ;
159
- return View ( newItem ) ;
141
+ return ProcessUnauthorized ( itemList , authContext ) ;
160
142
}
161
143
}
162
144
catch ( Exception )
@@ -177,5 +159,18 @@ public async Task<ActionResult> Index(string item)
177
159
}
178
160
return View ( "Error" ) ;
179
161
}
162
+
163
+ private ActionResult ProcessUnauthorized ( List < TodoItem > itemList , AuthenticationContext authContext )
164
+ {
165
+ var todoTokens = authContext . TokenCache . ReadItems ( ) . Where ( a => a . Resource == AzureAdOptions . Settings . TodoListResourceId ) ;
166
+ foreach ( TokenCacheItem tci in todoTokens )
167
+ authContext . TokenCache . DeleteItem ( tci ) ;
168
+
169
+ ViewBag . ErrorMessage = "UnexpectedError" ;
170
+ TodoItem newItem = new TodoItem ( ) ;
171
+ newItem . Title = "(No items in list)" ;
172
+ itemList . Add ( newItem ) ;
173
+ return View ( itemList ) ;
174
+ }
180
175
}
181
176
}
0 commit comments