C#C
C#2y ago
1 reply
Dani

get url after oauth2 redirect

hey guys so im working on a api intergration with the blizzard api and blazor server app right now its all going good but im at that point where im stuck when trying to use oauth im making a get request to the authorize server i login with my blizzard account and then i get redirected back to the page in the url with my code needed to make scoped request how can i get this code from the url when the redirected is done?
        public async Task<Oauth> GetOauthToken(string ClientId, string Scope, string State, string RedirectUri, string ResponseType)
        {
            var request = new RestRequest("/authorize", Method.Get);
            request.AddParameter("client_id",ClientId);
            request.AddParameter("scope",Scope);
            request.AddParameter("state",State);
            request.AddParameter("redirect_uri",RedirectUri);
            request.AddParameter("response_type",ResponseType);

            using (var client = new RestClient("https://oauth.battle.net"))
            {
                var url = client.BuildUri(request).ToString();
                await client.ExecuteAsync(request);
                return new Oauth
                {
                    AuthorizationCode = url
                };
                
            }
        }
and on the page it looks like this
    private async Task MakeRequest3()
    {
        try
        {
            var url = await api.GetOauthToken("clientid", "wow.profile", "/", "https://localhost:7280/", "code");
            nav.NavigateTo(url.AuthorizationCode);
        }
        catch (UnSuccesfullReponseException e)
        {
            Console.WriteLine(e.Message);
            apiOutput = e.Message;
        }  
    }


how can i detect when the redirect is succesfull and then get the current url so i can extract the code value from there?
Was this page helpful?