Beispiel #1
0
def testcallback():
    values = services.request_value_dict(['client_id','shared_secret','code','state','error','scope'])
    request_token = oauth2.service.request_token_call()
    if request_token != None:
    	values.update(request_token)
    	services.session.store(request_token)
    values['name'] = 'oauth 2 callback'
    return values
Beispiel #2
0
def testcallback():
    values = services.request_value_dict(
        ['client_id', 'shared_secret', 'code', 'state', 'error', 'scope'])
    request_token = oauth2.service.request_token_call()
    if request_token != None:
        values.update(request_token)
        services.session.store(request_token)
    values['name'] = 'oauth 2 callback'
    return values
Beispiel #3
0
 def request_token_call(self,
                        secret=None,
                        grant_type='authorization_code',
                        assertion_type=None):
     ## process flow for oauth
     params = services.request_value_dict(['client_id', 'redirect_uri'])
     if grant_type is 'authorization_code':
         params['code'] = services.get_param('code')
         params['client_secret'] = services.get_param('shared_secret')
     elif grant_type is 'refresh_token':
         # todo implement
         pass
     else:
         ## assume its a bearer token flow
         params['assertion'] = secret
     params['grant_type'] = grant_type
     params['format'] = 'json'
     base_url = services.get_param('base_url')
     suffix_override = services.get_param('suffix_override')
     if suffix_override != None:
         suffix_override = base_url + '/' + suffix_override
     client = oauthclient(params['client_id'],
                          services.get_param('shared_secret'), base_url)
     sending = client.toqueryparams(params)
     try:
         request_token = client.requestToken(suffix_override, params)
         request_token.update(params)
         if ('error' in request_token):
             request_token['error_description'] = setup.get_message(
                 request_token['error'])
     except Exception as e:
         request_token = {}
         request_token.update(params)
         request_token[
             'error'] = "Error occured in oAuth Call ({0})".format(e)
         print(e)
     except ValueError as ve:
         request_token = {}
         request_token.update(params)
         request_token[
             'error'] = "Input Error occured in oAuth Call ({0})".format(ve)
     except:
         request_token = {}
         request_token.update(params)
         request_token['error'] = 'Unknown error'
     if suffix_override != None:
         request_token['url_used'] = suffix_override + '?' + sending
     else:
         request_token[
             'url_used'] = base_url + '/oauth/request_token?' + sending
     return request_token
Beispiel #4
0
def testauthorize():
    ## process flow for oauth
    tostore = services.request_value_dict(['client_id','shared_secret','redirect_uri','base_url','state','suffix_override','token_type','scope'])
    params = services.dict_subset(tostore,['client_id','redirect_uri','state','scope'])
    params['response_type'] = 'code'
     
    services.session.store(tostore, False)
    if services.session.get_attr('state') is None:
	services.session.put('state',services.session.get_session().id)
        params['state'] = services.session.get_attr('state')
    
    consumer_key = services.get_param('client_id')
    shared_secret = services.get_param('shared_secret')
    base_url =  services.get_param('base_url')
    
    oauthclient = oauth2.oauthclient(consumer_key, shared_secret, base_url)
    redirect_url = oauthclient.authorizeRedirect(params=params)
    return dict(link=redirect_url )
Beispiel #5
0
    def request_token_call(self,secret=None,grant_type='authorization_code',assertion_type=None):
	## process flow for oauth
	params = services.request_value_dict(['client_id','redirect_uri'])
	if grant_type is 'authorization_code':
	    params['code'] = services.get_param('code')
	    params['client_secret'] = services.get_param('shared_secret')
	elif grant_type is 'refresh_token':
	    # todo implement
	    pass
	else:
	    ## assume its a bearer token flow
	    params['assertion'] = secret
	params['grant_type'] = grant_type
	params['format'] = 'json'
	base_url =  services.get_param('base_url')
	suffix_override =  services.get_param('suffix_override')
	if suffix_override != None:
	    suffix_override = base_url + '/' + suffix_override
	client = oauthclient(params['client_id'], services.get_param('shared_secret'), base_url)
	sending = client.toqueryparams(params)
	try:
	    request_token = client.requestToken(suffix_override, params)
	    request_token.update(params);
	    if ('error' in request_token):
		request_token['error_description'] = setup.get_message(request_token['error'])
	except Exception as e:
	    request_token = {}
	    request_token.update(params)
	    request_token['error'] = "Error occured in oAuth Call ({0})".format(e)
	    print (e)
	except ValueError as ve:
	    request_token = {}
	    request_token.update(params)
	    request_token['error'] = "Input Error occured in oAuth Call ({0})".format(ve)
	except:
	    request_token = {}
	    request_token.update(params)
	    request_token['error'] = 'Unknown error'
	if suffix_override != None:	
	    request_token['url_used'] = suffix_override + '?' + sending
	else:
	    request_token['url_used'] = base_url + '/oauth/request_token?' + sending
	return request_token
Beispiel #6
0
def testauthorize():
    ## process flow for oauth
    tostore = services.request_value_dict([
        'client_id', 'shared_secret', 'redirect_uri', 'base_url', 'state',
        'suffix_override', 'token_type', 'scope'
    ])
    params = services.dict_subset(
        tostore, ['client_id', 'redirect_uri', 'state', 'scope'])
    params['response_type'] = 'code'

    services.session.store(tostore, False)
    if services.session.get_attr('state') is None:
        services.session.put('state', services.session.get_session().id)
        params['state'] = services.session.get_attr('state')

    consumer_key = services.get_param('client_id')
    shared_secret = services.get_param('shared_secret')
    base_url = services.get_param('base_url')

    oauthclient = oauth2.oauthclient(consumer_key, shared_secret, base_url)
    redirect_url = oauthclient.authorizeRedirect(params=params)
    return dict(link=redirect_url)