Basically, I have a button that executes the following code
$(document).ready(function (){
$("#login-button").click(function () {
var parameters = "@Model.parameters";
parameters = parameters.replace(/&/g, "&");
window.location.href = "https://accounts.spotify.com/authorize/".concat(parameters);
})
})
and it successfully gives an access token in https://localhost:44382/Callback#access_token=TOKEN&token_type=Bearer&expires_in=3600&state=586917 .
But I can't figure out how to pull out the access token from the URL so I can use it as a variable. I tried
public IActionResult OnGet()
{
@TempData["access_token"] = (string)HttpContext.Request.Query["access_token"];
return Page();
}
on the Callback.cshtml.cs file, but it seems to return null(the whole Query contains no elements), because as I suspect, it executes prior to the URL actually containing the token. And also, I tried putting in the following code to Callback.cshtml, but it runs into the same issue. In addition to the $window.location.href not actually redirecting.
$(document).load(function () {
@TempData["access_token"] = @HttpContext.Request.Query["access_token"];
$window.location.href = "/Overview";
})