def _wns_authenticate(scope='notify.windows.com'):
 client_id = SETTINGS['WNS_PACKAGE_SECURITY_ID']
 if (not client_id):
  raise ImproperlyConfigured('You need to set PUSH_NOTIFICATIONS_SETTINGS["WNS_PACKAGE_SECURITY_ID"] to use WNS.')
 client_secret = SETTINGS['WNS_SECRET_KEY']
 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):
   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:
  raise WNSAuthenticationError('Received invalid JSON data from WNS.')
 access_token = oauth_data.get('access_token')
 if (not access_token):
  raise WNSAuthenticationError('Access token missing from WNS response.')
 return access_token

def _wns_authenticate ( scope = 'notify.windows.com' ) : client_id = SETTINGS [ 'WNS_PACKAGE_SECURITY_ID' ] if ( not client_id ) : raise ImproperlyConfigured ( 'You need to set PUSH_NOTIFICATIONS_SETTINGS["WNS_PACKAGE_SECURITY_ID"] to use WNS.' ) client_secret = SETTINGS [ 'WNS_SECRET_KEY' ] 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 ) : 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 : raise WNSAuthenticationError ( 'Received invalid JSON data from WNS.' ) access_token = oauth_data . get ( 'access_token' ) if ( not access_token ) : raise WNSAuthenticationError ( 'Access token missing from WNS response.' ) return access_token
requests an access token for wns communication .