def get(self, uuid): try: uuid = str(uuid) api = utils.get_linkedin_api(uuid) # Get Request Token result = api.request_token() if result == False: raise api.get_error() # Generate Authorisation URL authorisation_url = api.get_authorize_url(request_token=api._request_token) # Store the request token and request token secret against the Employee datastore.set_employee(uuid, dict(oauth_request_token=api._request_token, oauth_request_token_secret=api._request_token_secret)) # Issue the Email to the Employee mailservice.send_linkedin_connection_request(uuid, authorisation_url) # If all is well, redirect back to the Employee view self.redirect('/employees/'+uuid) except (Exception), e: logging.error('LinkedInOAuthRequestController : get() : caught exception') logging.error(e) self.error(500)
def get(self, uuid): try: is_admin = users.is_current_user_admin() # NOTE: The URL will have a query string appended : "/oauth-response/EMPLOYEE_UUID?oauth_token=21903a3c-b69e-4c55-a7a7-425474a84bfd&oauth_verifier=17604" uuid = str(uuid) employee_profile = None # Get the Employee employee = model_employee.Employee.get_by_key_name(uuid) if employee is None: logging.error('LinkedInOAuthResponseController : get() : No Employee with UUID '+uuid+' found.') self.error(500) return # Recreate the API instance, then set the API request token/secret to be the stored Employee request token/secret api = utils.get_linkedin_api(uuid) api._request_token = employee.oauth_request_token api._request_token_secret = employee.oauth_request_token_secret # The OAuth Token should match the one we sent oauth_token = str(self.request.get('oauth_token')) # The Verifier is needed for future API calls for this Employee oauth_verifier = str(self.request.get('oauth_verifier')) # Get Access Token result = api.access_token(verifier=oauth_verifier) if result == False: logging.error('LinkedInOAuthResponseController : get() : '+api.get_error()) self.error(500) return # Get current User profile employee_profile = api.get_profile(fields=['id,first-name,last-name,skills:(id,skill:(name),proficiency:(level,name),years:(id,name)),picture-url']) logging.debug(employee_profile) # Save the LinkedIn Skills list skill_keys = list() if employee_profile.skills is not None and len(employee_profile.skills) > 0: skill_keys = datastore.set_employee_skills(uuid, employee_profile.skills) # Save the OAuth Verifier and the Skills against the Employee datastore.set_employee(uuid, dict(oauth_verifier=oauth_verifier, access_token=api._access_token, access_token_secret=api._access_token_secret, skills=skill_keys, picture_url=employee_profile.picture_url)) # Send the Employee to the OAuth Response view args = dict(env=os.environ, employee=employee, is_admin=is_admin) path = os.path.join(os.path.dirname(__file__),'../views/employees/oauth-response.html') self.response.out.write(template.render(path, args)) except (Exception), e: logging.error('LinkedInOAuthResponseController : get() : caught exception') logging.error(e) self.error(500)