コード例 #1
0
ファイル: OAuthHelper.cs プロジェクト: neooleg/greenshot
 /// <summary>
 /// Authenticate via an embedded browser
 /// If this works, return the code
 /// </summary>
 /// <param name="settings">OAuth2Settings with the Auth / Token url etc</param>
 /// <returns>true if completed, false if canceled</returns>
 private static bool AuthenticateViaEmbeddedBrowser(OAuth2Settings settings)
 {
     if (string.IsNullOrEmpty(settings.CloudServiceName)) {
         throw new ArgumentNullException("CloudServiceName");
     }
     if (settings.BrowserSize == Size.Empty) {
         throw new ArgumentNullException("BrowserSize");
     }
     OAuthLoginForm loginForm = new OAuthLoginForm(string.Format("Authorize {0}", settings.CloudServiceName), settings.BrowserSize, settings.FormattedAuthUrl, settings.RedirectUrl);
     loginForm.ShowDialog();
     if (loginForm.IsOk) {
         string code;
         if (loginForm.CallbackParameters.TryGetValue(CODE, out code) && !string.IsNullOrEmpty(code)) {
             settings.Code = code;
             GenerateRefreshToken(settings);
             return true;
         }
     }
     return false;
 }
コード例 #2
0
ファイル: OAuthHelper.cs プロジェクト: neooleg/greenshot
 /// <summary>
 /// Authorize the token by showing the dialog
 /// </summary>
 /// <returns>The request token.</returns>
 private String GetAuthorizeToken()
 {
     if (string.IsNullOrEmpty(Token)) {
         Exception e = new Exception("The request token is not set");
         throw e;
     }
     LOG.DebugFormat("Opening AuthorizationLink: {0}", AuthorizationLink);
     OAuthLoginForm oAuthLoginForm = new OAuthLoginForm(LoginTitle, BrowserSize, AuthorizationLink, CallbackUrl);
     oAuthLoginForm.ShowDialog();
     if (oAuthLoginForm.IsOk) {
         if (oAuthLoginForm.CallbackParameters != null) {
             string tokenValue;
             if (oAuthLoginForm.CallbackParameters.TryGetValue(OAUTH_TOKEN_KEY, out tokenValue)) {
                 Token = tokenValue;
             }
             string verifierValue;
             if (oAuthLoginForm.CallbackParameters.TryGetValue(OAUTH_VERIFIER_KEY, out verifierValue)) {
                 Verifier = verifierValue;
             }
         }
     }
     if (CheckVerifier) {
         if (!string.IsNullOrEmpty(Verifier)) {
             return Token;
         }
         return null;
     }
     return Token;
 }