Search code examples
oauth-2.0callbackwebformsblazor

Blazor Server: Read Response information in Callback


I am working on a Hobby application in Blazor Server. The first stage in this application involves directing the user to an external site to have them authorize my app (OAuth2) to access their information from the external site. Part of this process involves a return authorization code. I have a Webforms version of this application where the Start page redirects the user to a URL and then a callback page completes the task of capturing a token. I cannot figure out how to capture the "Code" from the response in the Callback from the external server. Any help?

Start Page:

        public void Btn_UM_CreateNew_click(object sender, EventArgs e)
        {
            RegisterAsyncTask(new PageAsyncTask(TestNew));
        }
        private async Task TestNew()
        {
            using (var eveAuth = new EveAuth())
            {
                var url = await eveAuth.EveAuthGet();

                Response.Redirect(url);

            }
        }

Callback page (where I extract the "Code" value:

        protected async void Page_Load(object sender, EventArgs e)
        {
            var resp = Request["code"];
            using (EveAuth eveCallback = new EveAuth())
            {
                await eveCallback.EveTokenGet(resp);
            }


Solution

  • Is the "Code" passed to the Callback page via a query string?

    If so you can refer to the below article

    https://chrissainty.com/working-with-query-strings-in-blazor/