コード例 #1
0
        private bool ClientCertValidationCallback(object sender, X509Certificate cert,
                                                  X509Chain chain, SslPolicyErrors policyErrors)
        {
            if (cert != null)
            {
                ClientAuthenticated?.Invoke(this, new X509Certificate2(cert));
            }

            return(true);
        }
コード例 #2
0
        public async Task <IOAuth2Token> RefreshUserAuthenticationToken()
        {
            await this.ApplicationShutdownLock.EnterReadLock();

            try{
                //??? API response parameter expires_in seems to be in tenths of a second instead of seconds; possible API bug
                IOAuth2Token NewToken;
                try{
                    NewToken = await APIOAuth.GetTokenByRefreshTokenAsync(ClientAuthenticated.OAuth2Token.RefreshToken);
                }catch (ImgurException) {
                    throw;
                }catch (HttpRequestException Error) {
                    throw ToImgurException(Error);
                }catch (TaskCanceledException Error) {
                    throw ToImgurException(Error);
                }
                Log.Imgur_.LogCritical(
                    "A new Imgur OAuth Token has been acquired, which expires at {0:u}. It is highly recommended that this Token be backed up from the settings file, in case it is lost. This token must be kept secret; anyone with access to it has access to the Imgur user account with which it is associated.",
                    NewToken.ExpiresAt
                    );
                ClientAuthenticated.SetOAuth2Token(NewToken);
                try{
                    await RepositorySettings.SaveNewImgurUserAuthorizationToken(NewToken);

                    Log.Imgur_.LogInfo("New Imgur OAuth Token saved successfully to settings");
                }catch (DataAccessException Error) {
                    Log.Imgur_.LogCritical(
                        "An error occured whilst saving the new Imgur OAuth Token; update the application settings manually with the new Token, otherwise subsequent runs of the application will use the old Token and fail to connect to Imgur.\nDetails: {0}",
                        Error.Message
                        );
                }
                return(NewToken);
            }finally{
                this.ApplicationShutdownLock.ExitReadLock();
            }
        }
コード例 #3
0
 private void OnClientAuthentication()
 {
     ClientAuthenticated?.Invoke(new ActiveClientEventArgs(this));
 }