// Remove credentials from the store.
        // Also deletes the credentials' auth token from the keychain.
        public void RemoveCredentials(ENCredentials credentials)
        {
            // Delete auth token from registry.
            credentials.DeleteFromRegistry();

            // Update user defaults.
            Store.Remove(credentials.Host);
        }
        // Add credentials to the store.
        // Also saves the authentication token to the keychain.
        public void AddCredentials(ENCredentials credentials)
        {
            // Save auth token to registry.
            credentials.SaveToRegistry();

            // Add it to our host => credentials dictionary.
            Store[credentials.Host] = credentials;
        }
		// Remove credentials from the store.
		// Also deletes the credentials' auth token from the keychain.
		public void RemoveCredentials(ENCredentials credentials)
		{
			// Delete auth token from registry.
			credentials.DeleteFromRegistry();

			// Update user defaults.
			Store.Remove(credentials.Host);
		}
		// Add credentials to the store.
		// Also saves the authentication token to the keychain.
		public void AddCredentials(ENCredentials credentials)
		{
			// Save auth token to registry.
			credentials.SaveToRegistry();

			// Add it to our host => credentials dictionary.
			Store[credentials.Host] = credentials;
		}
        // Look up the credentials for the given host.
        public ENCredentials CredentialsForHost(string host)
        {
            ENCredentials credentials = null;

            if (Store == null)
            {
                return(null);
            }
            Store.TryGetValue(host, out credentials);
            if (credentials != null && !credentials.AreValid())
            {
                RemoveCredentials(credentials);
                return(null);
            }

            return(credentials);
        }
Exemplo n.º 6
0
		public void AuthenticateToEvernote()
		{
			// Authenticate is idempotent; check if we're already authenticated.
			if (IsAuthenticated)
			{
				return;
			}

			EdamUser = null;

			// If the developer token is set, then we can short circuit the entire auth flow and just call ourselves authenticated.
			if (DeveloperToken != null)
			{
				_IsAuthenticated = true;
				PrimaryAuthenticationToken = DeveloperToken;
				PerformPostAuthentication();
				return;
			}

			// Start bootstrapping
			string locale = CultureInfo.CurrentCulture.ToString();
			ENUserStoreClient bootstrapUserStore = new ENUserStoreClient(UserStoreUrl(), null);
			try
			{
				BootstrapInfo info = bootstrapUserStore.GetBootstrapInfo(locale);
				// Use first profile as the preferred profile.
				BootstrapProfile profile = info.Profiles[0];
				string host = profile.Settings.ServiceHost;
				EvernoteOAuth.HostService service = 0;
				if (host == ENSessionBootstrapServerBaseURLStringUS)
				{
					service = EvernoteOAuth.HostService.Production;
				}
				else if (host == ENSessionBootstrapServerBaseURLStringCN)
				{
					service = EvernoteOAuth.HostService.Yinxiang;
				}
				else
				{
					service = EvernoteOAuth.HostService.Sandbox;
				}

				// Perform the authentication.
				var oauth = new EvernoteOAuth(service, ConsumerKey, ConsumerSecret, SupportsLinkedAppNotebook);

				string errResponse = oauth.Authorize();
				if (errResponse.Length == 0)
				{
					ENCredentials credentials = new ENCredentials(SessionHost, oauth.UserId, oauth.NoteStoreUrl, oauth.WebApiUrlPrefix, oauth.Token, oauth.Expires.ToDateTime());
					_IsAuthenticated = true;
					AddCredentials(credentials);
					SetCurrentProfileNameFromHost(credentials.Host);
					SessionHost = credentials.Host;
					PrimaryAuthenticationToken = credentials.AuthenticationToken;
					if (oauth.LinkedAppNotebookSelected)
					{
						Preferences.SetObject(oauth.LinkedAppNotebookSelected, ENSessionPreferencesAppNotebookIsLinked);
					}
					AuthenticationCompleted = true;
					PerformPostAuthentication();
				}
				else
				{
					Unauthenticate();
				}
			}
			catch (Exception)
			{
				Unauthenticate();
			}
		}
Exemplo n.º 7
0
		private void AddCredentials(ENCredentials credentials)
		{
			ENCredentialStore store = CredentialStore();
			store.AddCredentials(credentials);
			SaveCredentialStore(store);
		}