static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); SocketsExtentions.SocketsLogicInstance = new SocketsExtentions(); using (var authorizeForm = new AuthorizeForm()) { authorizeForm.ShowDialog(); if (authorizeForm.DialogResult == DialogResult.OK) { Application.Run(new MainForm()); } } }
public Boolean Login_UI() { try { //Check prekeyring.xml to see if the Dropbox credential exists. AccessToken at = this.AccessToken; //If not,pop up a login window asking the user to enter his/her account && password if (at == null) { this.Client = new DropNet.DropNetClient(ServerControler.apiKey, ServerControler.appSecret); this.Client.GetToken(); //Ask user to enter DropBox account and password //SecuruStikMessageQueue.SendMessage_Splash_Hiden(); AuthorizeForm af = new AuthorizeForm(this.AuthorizeUrl); af.ShowDialog(); if (af.DialogResult == DialogResult.OK) { //return this.GetAccessToken(); try { UserLogin userLogin = this.Client.GetAccessToken(); this.AccessToken = new AccessToken { UserToken = userLogin.Token, UserSecret = userLogin.Secret }; return(true); } catch (DropNet.Exceptions.DropboxException ex) { //SecuruStikException.ThrowSecuruStik( SecuruStikExceptionType.DropBoxControl_AccessToken , // ex.Message + "\r\n" + ex.Message , ex ); return(false); } } else if (af.DialogResult == DialogResult.Cancel) { return(false); } else { MessageBoxEx.Show("Login Dropbox failed."); return(false); } } else { this.Client = new DropNet.DropNetClient( ServerControler.apiKey, ServerControler.appSecret, at.UserToken, at.UserSecret, null); } } catch (System.Exception ex) { //SecuruStikException.ThrowSecuruStik( // SecuruStikExceptionType.Initialization_DropBoxController , // ex.Message ); } return(true); }
/// <summary> /// Using the provided usage scopes and parameters, shows a window asking user to grant the application access /// to their account. Returns the authorization code if the user grants access to this app. /// </summary> /// <param name="scopes">The scopes that the app has requested.</param> /// <param name="extraParams">Any extra parameters that are needed for authorization.</param> /// <returns>The authorization code for getting the initial access token, or null on cancel or error.</returns> protected string RequestAuthorization(List <string> scopes, NameValueCollection extraParams) { //Represents the collection that will contain all parameters of the request url. Start by adding the //required stuff to it. NameValueCollection parameters = new NameValueCollection() { { "response_type", "code" }, { "client_id", ClientId }, { "redirect_uri", RedirectUri } }; //Add scopes if any are provided. if (scopes != null && scopes.Count > 0) { string scopesStr = ""; //Add the scope parameter and then the list of scopes, separated by spaces. for (int i = 0; i < scopes.Count; i++) { if (i != scopes.Count - 1) { scopesStr += scopes[i] + " "; } else { scopesStr += scopes[i]; } } parameters["scope"] = scopesStr; } //Add any extra parameters. if (extraParams != null && extraParams.Count > 0) { parameters.Add(extraParams); } //Create the authorization request url. var requestUrl = ConstructUri(AuthorizationEndpoint, parameters).ToString(); //Create the authorization window that will prompt the user to login to their account. The user will then //grant or deny access to this app. var loginWindow = new AuthorizeForm(); loginWindow.Text = "Login To " + ProviderName; loginWindow.RequestAuthorization(requestUrl, AuthorizationFormCloseParams); //Show the window as a dialog to block application use until the user gives access to this app, denies //access to this app, or chooses to just close the window (also denying access to this app). loginWindow.ShowDialog(); //Check if authorization was cancelled by closing the window early. if (loginWindow.WasAuthorizationCancelled) { LastError = OAuthClientResult.UserCancelled; LastErrorMessage = "Authorization process cancelled by closing login window."; return(null); } //The redirect url should not be empty. if (string.IsNullOrEmpty(loginWindow.AuthorizationRedirectUrl)) { LastError = OAuthClientResult.UnexpectedError; LastErrorMessage = "Authorization url is null or empty."; return(null); } //Success. LastError = OAuthClientResult.Success; LastErrorMessage = "Operation completed successfully."; //Return the authorization code. Subclasses will handle this value, including if it is null or empty. return(loginWindow.AuthorizationRedirectUrl); }