From b84b848bec016986f9d4ab3eff3b9a302c8efb55 Mon Sep 17 00:00:00 2001 From: Mikhail Klassen Date: Mon, 25 Feb 2019 22:02:55 -0700 Subject: [PATCH] Fixed issues around doing the OAUTH dance for LinkedIn --- notebooks/_Appendix B - OAuth Primer.ipynb | 25 ++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/notebooks/_Appendix B - OAuth Primer.ipynb b/notebooks/_Appendix B - OAuth Primer.ipynb index db362c2..b780a38 100644 --- a/notebooks/_Appendix B - OAuth Primer.ipynb +++ b/notebooks/_Appendix B - OAuth Primer.ipynb @@ -292,7 +292,7 @@ "import os\n", "from threading import Timer\n", "from flask import Flask, request\n", - "from linkedin import linkedin\n", + "from linkedin import linkedin # pip install python3-linkedin\n", "from IPython.display import display\n", "from IPython.display import Javascript as JS\n", "\n", @@ -302,13 +302,19 @@ "CONSUMER_SECRET = ''\n", "\n", "# This value is where LinkedIn will redirect. We'll configure an embedded\n", - "# web server to be serving requests here\n", - "\n", - "RETURN_URL = 'http://localhost:5000/oauth_helper'\n", + "# web server to be serving requests here. Make sure to add this to your\n", + "# app settings\n", + "REDIRECT_URL = 'http://localhost:5000/oauth_helper'\n", "\n", "# A temporary file to store a code from the web server\n", "OAUTH_FILE = 'resources/ch04-linkedin/linkedin.authorization_code'\n", "\n", + "# These should match those in your app settings\n", + "permissions = {'BASIC_PROFILE': 'r_basicprofile',\n", + " 'EMAIL_ADDRESS': 'r_emailaddress',\n", + " 'SHARE': 'w_share',\n", + " 'COMPANY_ADMIN': 'rw_company_admin'}\n", + "\n", "# Configure an emedded web server that accepts one request, stores a file\n", "# that will need to be accessed outside of the request context, and \n", "# immediately shuts itself down\n", @@ -328,8 +334,8 @@ "# Send an OAuth request to LinkedIn, handle the redirect, and display the access\n", "# token that's included in the redirect for the user to copy and paste\n", "\n", - "auth = linkedin.LinkedInAuthentication(CONSUMER_KEY, CONSUMER_SECRET, RETURN_URL, \n", - " linkedin.PERMISSIONS.enums.values())\n", + "auth = linkedin.LinkedInAuthentication(CONSUMER_KEY, CONSUMER_SECRET, REDIRECT_URL, \n", + " permissions.values())\n", "\n", "# Display popup after a brief delay to ensure that the web server is running and \n", "# can handle the redirect back from LinkedIn\n", @@ -357,6 +363,13 @@ "app = linkedin.LinkedInApplication(auth)\n", "print(app.get_profile())" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": {