good day. I’m new to C# and OAuth. I'm trying to implement OAuth2 in Blazor using RestSharp. I have the following code:
@page "/infusionsoft" @using System.Globalization
Request authentication
@code {
@using RestSharp;
@using RestSharp.Authenticators;
@using Newtonsoft.Json;
public void Foo1()
{
string url = "https://signin.infusionsoft.com/app/oauth/authorize";
string client_id = "myid";
string client_secret = "mysecret";
//request token
var restclient = new RestClient(url);
RestRequest request = new RestRequest("request/oauth") { Method = Method.POST };
request.AddHeader("Accept", "application/json");
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddParameter("client_id", client_id);
request.AddParameter("client_secret", client_secret);
request.AddParameter("grant_type", "authorization_code");//+
IRestResponse tResponse = restclient.Execute(request);
Console.WriteLine(tResponse.Content);
}
}
It’s supposed to redirect my app to a sign in page but right now it doesn’t do anything. I have tried google but I still don’t get it :(. Also, how do I start calling the apis once I get the authorization. Any sample code is greatly appreciated. Thanks.
You should redirect the user to authentication server by sending HTTP status code 302 and then specifying the auth server URL and query parameters in Redirect URL.