On load, my login page determines if the query param is null. If it is, it redirects to another page than then redirects back to login, but provides the query param. That looks like this:
protected void Page_Load(object sender, EventArgs e) {
if (Request.Params["code"] == null) {
var authCodeUrl = ConfigurationManager.AppSettings["MyId.AuthCodeUrl"];
Response.Redirect(authCodeUrl);
}
else {
var code = Request.Params["code"];
GetAuthResult(code);
}
}
GetAuthResult
fires after the return redirect. In it, it sends a POST to a separate API and expects to get a return result:
using (var client = new HttpClient()) {
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));
var response = client.PostAsync(accessTokenUrl, new FormUrlEncodedContent(bodyData)).Result;
if (!response.IsSuccessStatusCode) {
throw new Exception("MyID auth failed", new Exception(response.ReasonPhrase));
}
var token = response.Content.ReadAsStringAsync().Result;
return JsonConvert.DeserializeObject<MyIdAuthResult>(token);
}
You can see it happen in the GIF below. When I step over line 43, I expect to check the result on line 44. Except Page_Load
fires again. Any ideas what I'm doing wrong?