Unable to find AuthorizeOAuthRequest (.NET)

Hello All,

I am using the .NET Square SDK and trying to get code from the API Explorer to run. From the OAuth Authorize explorer, I copied the following C# code.

Explorer page: GET /oauth2/authorize - Square API Explorer

using global::System.Threading.Tasks;
using Square;
using Square.OAuth;

namespace Usage;

public class Example
{
    public async global::System.Threading.Tasks.Task Do() {
        var client = new SquareClient(
            token: "sandbox-token",
            clientOptions: new ClientOptions{
                BaseUrl = SquareEnvironment.Sandbox
            }
        );

        await client.OAuth.AuthorizeAsync(
            new AuthorizeOAuthRequest{
                ClientId = "sandbox-rest-of-id",
                Session = false,
                Scope = OAuthPermission.MerchantProfileRead,
                State = "random-guid",
                RedirectUri = "http://localhost:5000/callback"
            }
        );
    }

}

The problem I am running into is that the compiler cannot find the AuthorizeOAuthRequest class. Has anyone run into this? Could I be missing a Nuget package?

Thank you in advance for your help!

:waving_hand: I’m Square Dev AI, here to help answer your question!
Based on the information you’ve provided, the following documentation will help answer your question:

Additional Documentation

Test Authorization with Web Server
OAuth API
Build with the Mobile Authorization API

If this documentation helped you find a solution, please check the box indicating that this reply solves the problem.
Otherwise one of our Developer Advocates will provide additional assistance shortly.

In order to call Authorize you’ll want to do something like this:

using Square;
using Square.Models;
using Square.Apis;

// Initialize the client
var client = new SquareClient.Builder()
    .Environment(Square.Environment.Sandbox) // or Environment.Production
    .Build();

// Get OAuth API instance
var oAuthApi = client.OAuthApi;

// Step 1: Redirect user to Square's authorization URL
var authorizationUrl = $"https://connect.squareup.com/oauth2/authorize" +
    $"?client_id={clientId}" +
    $"&scope=MERCHANT_PROFILE_READ+PAYMENTS_READ+PAYMENTS_WRITE" +
    $"&session=false" +
    $"&state={state}";

// Step 2: After user authorizes, exchange code for access token
try 
{
    var body = new ObtainTokenRequest.Builder(
        clientId: "your_application_id",
        clientSecret: "your_application_secret",
        grantType: "authorization_code")
        .Code("authorization_code_from_callback")
        .Build();

    var result = await oAuthApi.ObtainTokenAsync(body);
    
    if (result.IsSuccess())
    {
        var accessToken = result.Body.AccessToken;
        var refreshToken = result.Body.RefreshToken;
        
        // Store these tokens securely
        // Use accessToken for API calls
    }
}
catch (ApiException e)
{
    Console.WriteLine($"Failed to obtain token: {e.Message}");
}

:slight_smile: