def test_warn(self): """ 関数が問題なく通るかのみ確認 """ msg = 'Simplejson Error4.' obj = 'hoge' Log.info(msg, obj)
def set_cache(cls, cache_key, cache_value, timeout=None): """ キャッシュにセットする アプリ側のsettingsのtimeoutがあれば使う なければgsocialのsettingのtimeoutを使う """ if timeout == None: # ここは普通のif文に変更した方がよいかも try: timeout = settings.GSOCIAL_CACHE_TIMEOUT except AttributeError: Log.info('GSOCIAL_CACHE_TIMEOUT isn\'t in settings.', timeout) timeout = DEFALT_CACHE_TIMEOUT Log.debug('Check timeout.', timeout) cache.set(cache_key, cache_value, timeout)
def _verify_sign_header(request): """ OAuth checking of header output authorization ok :None else: raise ヘッダーのOAUTH認証 output 認証ok: None それ以外: raise """ Log.debug("[Method] _verify_sign_header") request.opensocial_container = containerdata #下記つかってないのでコメントアウト #header_params = {} #oauth_signature = request.REQUEST.get("oauth_signature", None) auth_string = request.META.get('HTTP_AUTHORIZATION',"") auth_string = auth_string.replace('OAuth ',"") Log.debug('HTTP_AUTHORIZATION', auth_string) params = {} remote_hash = False for param in auth_string.split(','): Log.debug('param', param) (key, value) = param.strip().split('=', 1) value = value.strip('"').encode('utf-8') if key == 'oauth_signature': remote_hash = base64.decodestring(urllib.unquote(value)) elif key and key != 'OAuth realm' and key != 'realm': params[key] = value Log.debug('params', params) if not remote_hash: raise oauth_token_secret = params.get('oauth_token_secret', '') # Some container only need query parameter to create base_string # while some need postdata as well,so you create both hash pattern. # As one of them matches,checking will be passed. # コンテナによって、base_stringを作成するのにクエリパラメータのみを使うもの、 # postdataも含めるものがあるので、両方のパターンのハッシュを作り # どちらかがマッチすれば認証OKとする。 encoding = request.encoding if not encoding: encoding = 'utf-8' for key, value in request.GET.items(): if key and key != 'oauth_signature': params[key] = value.encode(encoding) Log.debug('params', params) # local_hash1 = local_hash2 = u'' #create hash by only using query parameter. # クエリパラメータのみを使ってハッシュを作成 local_hash1 = create_hmac_hash(request, params, oauth_token_secret) # create hash with using parameter contain POSTDATA # POSTDATAも含めたパラメータを使ってハッシュを作成 post_param = generate_post_hash(request, encoding) params.update(post_param) local_hash2 = create_hmac_hash(request, params, oauth_token_secret) host = request.get_host() host = host.split(',')[0] base_url = request.is_secure() and 'https://' or 'http://' + host + request.path Log.info('base_url', base_url) for k, v in params.iteritems(): if isinstance(v, basestring): Log.info('Check k and v.decode(encoding) of params.iteritems()', [k, v.decode(encoding)]) else: Log.info('Check k and v of params.iteritems()', [k, v]) Log.info('raw', request.raw_post_data) Log.info('remote_hash', binascii.b2a_base64(remote_hash)[:-1]) Log.info('local_hash1', binascii.b2a_base64(local_hash1)[:-1]) Log.info('local_hash2', binascii.b2a_base64(local_hash2)[:-1]) Log.info('local_hash1 == remote_hash ?', (local_hash1 == remote_hash)) Log.info('local_hash2 == remote_hash ?', (local_hash2 == remote_hash)) if local_hash1 != remote_hash and local_hash2 != remote_hash: raise opensocial_owner_id = request.REQUEST.get('opensocial_owner_id', None) if opensocial_owner_id is not None: request.opensocial_userid = str(opensocial_owner_id) request.opensocial_viewer_id = str(opensocial_owner_id) return None
def _verify_sign_header(request): """ OAuth checking of header output authorization ok :None else: raise ヘッダーのOAUTH認証 output 認証ok: None それ以外: raise """ Log.debug("[Method] _verify_sign_header") request.opensocial_container = containerdata #下記つかってないのでコメントアウト #header_params = {} #oauth_signature = request.REQUEST.get("oauth_signature", None) auth_string = request.META.get('HTTP_AUTHORIZATION', "") auth_string = auth_string.replace('OAuth ', "") Log.debug('HTTP_AUTHORIZATION', auth_string) params = {} remote_hash = False for param in auth_string.split(','): Log.debug('param', param) (key, value) = param.strip().split('=', 1) value = value.strip('"').encode('utf-8') if key == 'oauth_signature': remote_hash = base64.decodestring(urllib.unquote(value)) elif key and key != 'OAuth realm' and key != 'realm': params[key] = value Log.debug('params', params) if not remote_hash: raise oauth_token_secret = params.get('oauth_token_secret', '') # Some container only need query parameter to create base_string # while some need postdata as well,so you create both hash pattern. # As one of them matches,checking will be passed. # コンテナによって、base_stringを作成するのにクエリパラメータのみを使うもの、 # postdataも含めるものがあるので、両方のパターンのハッシュを作り # どちらかがマッチすれば認証OKとする。 encoding = request.encoding if not encoding: encoding = 'utf-8' for key, value in request.GET.items(): if key and key != 'oauth_signature': params[key] = value.encode(encoding) Log.debug('params', params) # local_hash1 = local_hash2 = u'' #create hash by only using query parameter. # クエリパラメータのみを使ってハッシュを作成 local_hash1 = create_hmac_hash(request, params, oauth_token_secret) # create hash with using parameter contain POSTDATA # POSTDATAも含めたパラメータを使ってハッシュを作成 post_param = generate_post_hash(request, encoding) params.update(post_param) local_hash2 = create_hmac_hash(request, params, oauth_token_secret) host = request.get_host() host = host.split(',')[0] base_url = request.is_secure( ) and 'https://' or 'http://' + host + request.path Log.info('base_url', base_url) for k, v in params.iteritems(): if isinstance(v, basestring): Log.info('Check k and v.decode(encoding) of params.iteritems()', [k, v.decode(encoding)]) else: Log.info('Check k and v of params.iteritems()', [k, v]) Log.info('raw', request.raw_post_data) Log.info('remote_hash', binascii.b2a_base64(remote_hash)[:-1]) Log.info('local_hash1', binascii.b2a_base64(local_hash1)[:-1]) Log.info('local_hash2', binascii.b2a_base64(local_hash2)[:-1]) Log.info('local_hash1 == remote_hash ?', (local_hash1 == remote_hash)) Log.info('local_hash2 == remote_hash ?', (local_hash2 == remote_hash)) if local_hash1 != remote_hash and local_hash2 != remote_hash: raise opensocial_owner_id = request.REQUEST.get('opensocial_owner_id', None) if opensocial_owner_id is not None: request.opensocial_userid = str(opensocial_owner_id) request.opensocial_viewer_id = str(opensocial_owner_id) return None