Esempio n. 1
0
        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 authorization RequestResult 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.
        }
        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
            {
            }
        }
Esempio n. 3
0
        public string SignInCallback(string code, int expires_in, string state)
        {
            OAuthFlow oauth = new OAuthFlowBuilder()
                              .SetTokenURL("https://api.smartsheet.com/2.0/token")
                              .SetAuthorizationURL("https://www.smartsheet.com/b/authorize")
                              .SetClientId(ClientId)
                              .SetClientSecret(ClientSecret)
                              .SetRedirectURL("http://localhost:55989/oauth/signin")
                              .Build();

            AuthorizationResult authResult = oauth.ExtractAuthorizationResult("http://localhost:55989/oauth/signin" + Request.QueryString.ToString());
            Token token = oauth.ObtainNewToken(authResult);

            return(token.AccessToken);
        }
Esempio n. 4
0
        public RedirectResult SignIn()
        {
            OAuthFlow oauth = new OAuthFlowBuilder()
                              .SetTokenURL("https://api.smartsheet.com/2.0/token")
                              .SetAuthorizationURL("https://www.smartsheet.com/b/authorize")
                              .SetClientId(ClientId)
                              .SetClientSecret(ClientSecret)
                              .SetRedirectURL("http://localhost:55989/oauth/signin")
                              .Build();

            String url = oauth.NewAuthorizationURL(new List <AccessScope> {
                AccessScope.READ_SHEETS
            }, "/");

            return(RedirectPermanent(url));
        }