How to get code for accesstoken

public string Authorize()
{
string status = “”;
try
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls| SecurityProtocolType.Tls11| SecurityProtocolType.Tls12| SecurityProtocolType.Ssl3;
RestClient client = new RestClient(REQUESTTOKENURL);
RestRequest request = new RestRequest();
request.AddHeader(“Content-Type”, “application/json”);
request.AddParameter(“client_id”, “g9yrw3uey8wjasasaasamknzhrqzad8w”);
request.AddParameter(“redirect_uri”, “https://localhost:44111/”);
request.AddParameter(“response_type”, “code”);
request.AddParameter(“scope”, “full”);
request.Method = Method.GET;

            IRestResponse response = client.Execute(request);
            string content = response.Content;
            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                var inf = content.Split(new string[] { "code=" }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault().Split('&').FirstOrDefault();
                status = inf;
            }
            

        }
        catch (Exception ex) {
            var error=ex.Message;
        }

        return status;
    }

please help,

@pradip_Kondalkar, I’m not sure what you’re asking, exactly? The process for generating an access token is laid out in the Authentication guide. Is there a particular part of the flow that is causing you problems?

Hey thanks for reply

yes when i try to make request for access code it redirect to sign in page but doesn’t go further
please help me with getting access code of access-token

Is the redirect_uri the same one that the Application was registered with when you setup your Key/Secret?

Hello, just wanted to add up. I can’t find were to apply the redirect_uri section when creating new app. Thank you.

Hello guys,

This is actually a very common place to get “stuck”. You’re thinking that you’re going to get the api access token on the front end but OAuth doesn’t work that way. You first have to get an authorization token which gives you permission to request an access token…this is why the login screen is there, so that anyone giving authorization to an app can be proven as authorized to do so by logging in…you then are given the auth token which you must then use to request your access/refresh token pair…it is with the access token that you can make api requests with, not the auth token. I’ll provide a video I created to help people with understanding how OAuth works with Infusionsoft to help you along the way :wink:

I really cant see where to add the redirect uri. Its always giving me this error.

https://www.testsite.com/?error=server_error&error_uri=https%3A%2F%2Fdeveloper.infusionsoft.com%2Fdocs%2Fread%2FGetting_Started_With_OAuth2&error_description=An+error+occurred

Can you also provide a procedure on how to request a code and tokens using Postman?

Please see attached image.

We don’t require you to whitelist the redrect_uri, so it is not an option in the portal right now to provide it. You can send in whatever redirect_uri as a query param in the initial authorization request that you like.

You don’t provide it in the api account, you provided it as part of the request.