This is the builder that is used To build OAuthFlow instances.
Thread Safety: This class is not thread safe since it's mutable, one builder instance is NOT expected To be used in multiple threads.
private static void UseOAuthFlow() { OAuthFlow oauth = new OAuthFlowBuilder() .SetClientId("1tziajulcsbqsswgy37") .SetClientSecret("sxouqll7zluvzmact3") .SetRedirectURL("https://www.google.com") .Build(); string url = oauth.NewAuthorizationURL ( new Smartsheet.Api.OAuth.AccessScope[] { Smartsheet.Api.OAuth.AccessScope.READ_SHEETS, Smartsheet.Api.OAuth.AccessScope.WRITE_SHEETS, Smartsheet.Api.OAuth.AccessScope.SHARE_SHEETS, Smartsheet.Api.OAuth.AccessScope.DELETE_SHEETS, Smartsheet.Api.OAuth.AccessScope.CREATE_SHEETS, Smartsheet.Api.OAuth.AccessScope.READ_USERS, Smartsheet.Api.OAuth.AccessScope.ADMIN_USERS, Smartsheet.Api.OAuth.AccessScope.ADMIN_SHEETS, Smartsheet.Api.OAuth.AccessScope.ADMIN_WORKSPACES, }, "key=Test" ); // Take the user to the following URL Debug.WriteLine(url); // After the user accepts or declines the authorization they are taken to the redirect URL. The URL of the page // the user is taken to can be used to generate an authorization RequestResult object. string authorizationResponseURL = "https://www.google.com/?code=yn8kl1kvruh31uj&expires_in=599957&state=key%3DTest"; // On this page pass in the full URL of the page to create an authorizationResult object AuthorizationResult authResult = oauth.ExtractAuthorizationResult(authorizationResponseURL); // Get the token from the authorization result Token token = oauth.ObtainNewToken(authResult); Assert.IsTrue(token.AccessToken == "ACCESS_TOKEN"); Token tokenRefreshed = oauth.RefreshToken(token); Assert.IsTrue(token.AccessToken != "ACCESS_TOKEN"); oauth.RevokeToken(token); SmartsheetClient smartsheet = new SmartsheetBuilder().SetAccessToken(token.AccessToken).Build(); try { smartsheet.SheetResources.ListSheets(null, null); Assert.Fail(); } catch { } }
public static void OAuthExample() { // Setup the information that is necessary to request an authorization code OAuthFlow oauth = new OAuthFlowBuilder().SetClientId("cxggphqv52axrylaux").SetClientSecret("1lllvnekmjafoad0si"). SetRedirectURL("https://batie.com/").Build(); // Create the URL that the user will go to grant authorization to the application string url = oauth.NewAuthorizationURL(new Smartsheet.Api.OAuth.AccessScope[] { Smartsheet.Api.OAuth.AccessScope.CREATE_SHEETS, Smartsheet.Api.OAuth.AccessScope.WRITE_SHEETS }, "key=YOUR_VALUE"); // Take the user to the following URL Console.WriteLine(url); // After the user accepts or declines the authorization they are taken to the redirect URL. The URL of the page // the user is taken to can be used to generate an AuthorizationResult object. string authorizationResponseURL = "https://batie.com/?code=dxe7eykuh912rhs&expires_in=239824&state=key%3DYOUR_VALUE"; // On this page pass in the full URL of the page to create an authorizationResult object AuthorizationResult authResult = oauth.ExtractAuthorizationResult(authorizationResponseURL); // Get the token from the authorization result Token token = oauth.ObtainNewToken(authResult); // Save the token or use it. }