'Signs request and returns signature and OAuth parameters.
`custom_paramters` is dict of parsed `custom_parameter` field
`client_key` and `client_secret` are LTI tool credentials.
Also *anonymous student id* is passed to template and therefore to LTI provider.'

def oauth_params(self, custom_parameters, client_key, client_secret):

    client = oauthlib.oauth1.Client(client_key=unicode(client_key), client_secret=unicode(client_secret))
    body = {u'user_id': self.get_user_id(), u'oauth_callback': u'about:blank', u'launch_presentation_return_url': '', u'lti_message_type': u'basic-lti-launch-request', u'lti_version': 'LTI-1p0', u'roles': self.role, u'resource_link_id': self.get_resource_link_id(), u'lis_result_sourcedid': self.get_lis_result_sourcedid(), u'context_id': self.context_id}
    if self.has_score:
        body.update({u'lis_outcome_service_url': self.get_outcome_service_url()})
    self.user_email = ''
    self.user_username = ''
    if callable(self.runtime.get_real_user):
        real_user_object = self.runtime.get_real_user(self.runtime.anonymous_student_id)
        try:
            self.user_email = real_user_object.email
        except AttributeError:
            self.user_email = ''
        try:
            self.user_username = real_user_object.username
        except AttributeError:
            self.user_username = ''
    if (self.ask_to_send_username and self.user_username):
        body['lis_person_sourcedid'] = self.user_username
    if (self.ask_to_send_email and self.user_email):
        body['lis_person_contact_email_primary'] = self.user_email
    body.update(custom_parameters)
    headers = {'Content-Type': 'application/x-www-form-urlencoded'}
    try:
        (__, headers, __) = client.sign(unicode(self.launch_url.strip()), http_method=u'POST', body=body, headers=headers)
    except ValueError:
        log.info(u'LTI    module    %s    in    course    %s    does    not    have    oauth    parameters    correctly    configured.', self.location, self.location.course_key)
        headers = {u'Content-Type': u'application/x-www-form-urlencoded', u'Authorization': u'OAuth    oauth_nonce="80966668944732164491378916897",    oauth_timestamp="1378916897",    oauth_version="1.0",    oauth_signature_method="HMAC-SHA1",    oauth_consumer_key="",    oauth_signature="frVp4JuvT1mVXlxktiAUjQ7%2F1cw%3D"'}
    params = headers['Authorization']
    params = dict([param.strip().replace('"', '').split('=') for param in params.split(',')])
    params[u'oauth_nonce'] = params[u'OAuth    oauth_nonce']
    del params[u'OAuth    oauth_nonce']
    params[u'oauth_signature'] = urllib.unquote(params[u'oauth_signature']).decode('utf8')
    params.update(body)
    return params
