Requests an Access token for WNS communication.

	:return: dict: {'access_token': <str>, 'expires_in': <int>, 'token_type': 'bearer'}

def _wns_authenticate(scope="notify.windows.com", application_id=None):
	"""
	Requests an Access token for WNS communication.

	:return: dict: {'access_token': <str>, 'expires_in': <int>, 'token_type': 'bearer'}
	"""
	client_id = get_manager().get_wns_package_security_id(application_id)
	client_secret = get_manager().get_wns_secret_key(application_id)
	if not client_id:
		raise ImproperlyConfigured(
			'You need to set PUSH_NOTIFICATIONS_SETTINGS["WNS_PACKAGE_SECURITY_ID"] to use WNS.'
		)

	if not client_secret:
		raise ImproperlyConfigured(
			'You need to set PUSH_NOTIFICATIONS_SETTINGS["WNS_SECRET_KEY"] to use WNS.'
		)

	headers = {
		"Content-Type": "application/x-www-form-urlencoded",
	}
	params = {
		"grant_type": "client_credentials",
		"client_id": client_id,
		"client_secret": client_secret,
		"scope": scope,
	}
	data = urlencode(params).encode("utf-8")

	request = Request(SETTINGS["WNS_ACCESS_URL"], data=data, headers=headers)
	try:
		response = urlopen(request)
	except HTTPError as err:
		if err.code == 400:
			# One of your settings is probably jacked up.
			# https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh868245
			raise WNSAuthenticationError("Authentication failed, check your WNS settings.")
		raise err

	oauth_data = response.read().decode("utf-8")
	try:
		oauth_data = json.loads(oauth_data)
	except Exception:
		# Upstream WNS issue
		raise WNSAuthenticationError("Received invalid JSON data from WNS.")

	access_token = oauth_data.get("access_token")
	if not access_token:
		# Upstream WNS issue
		raise WNSAuthenticationError("Access token missing from WNS response.")

	return access_token