<commit_before>package org.openhab.binding.withings.internal.api;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.Dictionary;
import java.util.Hashtable;

import oauth.signpost.OAuthConsumer;
import oauth.signpost.OAuthProvider;
import oauth.signpost.basic.DefaultOAuthConsumer;
import oauth.signpost.basic.DefaultOAuthProvider;
import oauth.signpost.exception.OAuthException;
import oauth.signpost.http.HttpParameters;
import oauth.signpost.signature.AuthorizationHeaderSigningStrategy;
import oauth.signpost.signature.HmacSha1MessageSigner;

import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.cm.ConfigurationException;
import org.osgi.service.cm.ManagedService;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * {@link WithingsAuthenticator} is responsible for authenticating openHAB
 * against the Withings API. It uses the OSGi console to instruct the user how
 * to execute the OAuth flow in the web browser. First the user needs to execute
 * <code>withings:startAuthentication</code>. A URL for an OAuth login site is
 * printed to the OSGi console. After login the user is redirected to a callback
 * page where he finds the necessary parameters. Then he needs to execute
 * <code>withings:finishAuthentication "&lt;oauth-verifier&gt;" "&lt;user-id&gt;"</code>
 * to finish the authentication process. The {@link WithingsAuthenticator} will
 * store the oauth tokens and the user id to the file system in the
 * {@link WithingsAuthenticator#contentDir} folder.
 * 
 * @see http://www.withings.com/de/api/oauthguide
 * @author <NAME>
 * @since 1.5.0
 */
public class WithingsAuthenticator implements ManagedService {

	public static final class OAuthTokens implements Serializable {

		private static final long serialVersionUID = 6071735616022465845L;

		public String token;

		public String tokenSecret;

		public OAuthTokens() {
		}

		public OAuthTokens(String token, String tokenSecret) {
			this.token = token;
			this.tokenSecret = tokenSecret;
		}
	}

	/**
	 * Default OAuth consumer key
	 */
	private static final String DEFAULT_CONSUMER_KEY = "<KEY>";
	/**
	 * Default OAuth consumer secret
	 */
	private static final String DEFAULT_CONSUMER_SECRET = "1d0117ec8f6f4cb4cf123484f2b39d8f3524264ebefc7edbd435e0e28e60";

	/**
	 * Default content dir for data storage
	 */
	private static final String DEFAULT_CONTENT_DIR = "data/withings";

	/**
	 * Default Redirect URL to which the user is redirected after the login
	 */
	private static final String DEFAULT_REDIRECT_URL = "http://www.openhab.org/oauth/withings";

	private static final String FILE_NAME_OAUTH_TOKEN = "oauth_tokens";

	private static final String FILE_NAME_USER_ID = "user";

	private static final String LINE = "#########################################################################################";

	private static final Logger logger = LoggerFactory
			.getLogger(WithingsAuthenticator.class);

	private static final String OAUTH_ACCESS_TOKEN_ENDPOINT_URL = "https://oauth.withings.com/account/access_token";

	private static final String OAUTH_AUTHORIZE_ENDPOINT_URL = "https://oauth.withings.com/account/authorize";

	private static final String OAUTH_REQUEST_TOKEN_ENDPOINT = "https://oauth.withings.com/account/request_token";

	private BundleContext bundleContext;

	private ServiceRegistration<?> clientServiceRegistration;
<commit_msg>changed API key and secret to the official openHAB defaults<commit_after>package org.openhab.binding.withings.internal.api;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.Dictionary;
import java.util.Hashtable;

import oauth.signpost.OAuthConsumer;
import oauth.signpost.OAuthProvider;
import oauth.signpost.basic.DefaultOAuthConsumer;
import oauth.signpost.basic.DefaultOAuthProvider;
import oauth.signpost.exception.OAuthException;
import oauth.signpost.http.HttpParameters;
import oauth.signpost.signature.AuthorizationHeaderSigningStrategy;
import oauth.signpost.signature.HmacSha1MessageSigner;

import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.cm.ConfigurationException;
import org.osgi.service.cm.ManagedService;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * {@link WithingsAuthenticator} is responsible for authenticating openHAB
 * against the Withings API. It uses the OSGi console to instruct the user how
 * to execute the OAuth flow in the web browser. First the user needs to execute
 * <code>withings:startAuthentication</code>. A URL for an OAuth login site is
 * printed to the OSGi console. After login the user is redirected to a callback
 * page where he finds the necessary parameters. Then he needs to execute
 * <code>withings:finishAuthentication "&lt;oauth-verifier&gt;" "&lt;user-id&gt;"</code>
 * to finish the authentication process. The {@link WithingsAuthenticator} will
 * store the oauth tokens and the user id to the file system in the
 * {@link WithingsAuthenticator#contentDir} folder.
 * 
 * @see http://www.withings.com/de/api/oauthguide
 * @author <NAME>
 * @since 1.5.0
 */
public class WithingsAuthenticator implements ManagedService {

	public static final class OAuthTokens implements Serializable {

		private static final long serialVersionUID = 6071735616022465845L;

		public String token;

		public String tokenSecret;

		public OAuthTokens() {
		}

		public OAuthTokens(String token, String tokenSecret) {
			this.token = token;
			this.tokenSecret = tokenSecret;
		}
	}

	/**
	 * Default OAuth consumer key
	 */
	private static final String DEFAULT_CONSUMER_KEY = "<KEY>";
	/**
	 * Default OAuth consumer secret
	 */
	private static final String DEFAULT_CONSUMER_SECRET = "25f1098263e511711b3287288f90740ff45532cef91658c5043db0b0e0c851c";

	/**
	 * Default content dir for data storage
	 */
	private static final String DEFAULT_CONTENT_DIR = "data/withings";

	/**
	 * Default Redirect URL to which the user is redirected after the login
	 */
	private static final String DEFAULT_REDIRECT_URL = "http://www.openhab.org/oauth/withings";

	private static final String FILE_NAME_OAUTH_TOKEN = "oauth_tokens";

	private static final String FILE_NAME_USER_ID = "user";

	private static final String LINE = "#########################################################################################";

	private static final Logger logger = LoggerFactory
			.getLogger(WithingsAuthenticator.class);

	private static final String OAUTH_ACCESS_TOKEN_ENDPOINT_URL = "https://oauth.withings.com/account/access_token";

	private static final String OAUTH_AUTHORIZE_ENDPOINT_URL = "https://oauth.withings.com/account/authorize";

	private static final String OAUTH_REQUEST_TOKEN_ENDPOINT = "https://oauth.withings.com/account/request_token";

	private BundleContext bundleContext;

	private ServiceRegistration<?> clientServiceRegistration;

{'fraction_non_alphanumeric': 0.10556348074179743, 'fraction_numerical': 0.017118402282453638, 'mean_word_length': 5.535593220338983, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 6, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2685167', 'n_tokens_mistral': 2355, 'n_tokens_neox': 2207, 'n_words': 611}