Using django-oauth2 for django rest framework with LinkedIn











up vote
0
down vote

favorite












I am using the django rest framework OAuth2 Toolkit. I have set everything up, and everything seems to be fine, except that LinkedIn returns a 401 unauthorized response when I try to get an access token. The trace is:



2018-11-21 14:28:22,904 [middlewares 70] INFO: {"method": "POST", "user_id": 234630, "request_post_body": {"authorization_grant_type": "authorization-code", "client_id": "foo", "csrfmiddlewaretoken": "foobar", "initial-client_id": "foo", "initial-client_secret": "bar", "redirect_uris": "http://xeniadev.com:3000/linkedin-login-redirect", "user": "234630", "_save": "Save", "name": "LinkedIn", "client_secret": "bar", "client_type": "public"}, "path": "/admin/oauth2_provider/application/1/change/", "device_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36", "user": ""}
[21/Nov/2018 14:28:22] "POST /admin/oauth2_provider/application/1/change/ HTTP/1.1" 302 0
2018-11-21 14:28:23,830 [middlewares 70] INFO: {"method": "GET", "user_id": 234630, "user": "", "path": "/admin/oauth2_provider/application/", "device_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36"}
[21/Nov/2018 14:28:23] "GET /admin/oauth2_provider/application/ HTTP/1.1" 200 2874
2018-11-21 14:28:23,920 [middlewares 70] INFO: {"method": "GET", "user_id": 234630, "user": "", "path": "/admin/jsi18n/", "device_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36"}
[21/Nov/2018 14:28:23] "GET /admin/jsi18n/ HTTP/1.1" 200 909
2018-11-21 14:28:32,895 [resource 74] DEBUG: Dispatching token_type Bearer request to <oauthlib.oauth2.rfc6749.tokens.BearerToken object at 0x12001b4c0>.
2018-11-21 14:28:32,895 [oauth2_endpoints 58] DEBUG: Dispatching grant_type convert_token request to <rest_framework_social_oauth2.oauth2_grants.SocialTokenGrant object at 0x11d9f86d8>.
2018-11-21 14:28:32,895 [refresh_token 58] DEBUG: Validating refresh token request, <oauthlib.Request url="/auth/convert-token", http_method="POST", headers="", body="<SANITIZED>&backend=linkedin-oauth2&client_id=foo&grant_type=convert_token">.
2018-11-21 14:28:32,963 [oauth2_validators 243] DEBUG: Application '77ha5jwgczyohk' has type 'public'
2018-11-21 14:28:32,964 [base 147] DEBUG: Validating access to scopes ['read', 'write'] for client 'foo' (<Application: LinkedIn>).
2018-11-21 14:28:32,978 [connectionpool 813] DEBUG: Starting new HTTPS connection (1): api.linkedin.com:443
2018-11-21 14:28:33,320 [connectionpool 393] DEBUG: https://api.linkedin.com:443 "GET /v1/people/~:(email-address,first-name,headline,id,industry,last-name)?format=json HTTP/1.1" 401 None
2018-11-21 14:28:33,324 [middlewares 70] INFO: {"method": "POST", "user": "AnonymousUser", "path": "/auth/convert-token", "device_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0.1 Safari/605.1.15", "request_post_body": {"grant_type": "convert_token", "backend": "linkedin-oauth2", "client_id": "foo", "token": "footokenbar"}}
2018-11-21 14:28:33,325 [log 228] WARNING: Unauthorized: /auth/convert-token
[21/Nov/2018 14:28:33] "POST /auth/convert-token HTTP/1.1" 401 79


Unfortunately, neither this trace nor the linkedin developer console tells me anything about why this is happening. The client_id and client_secret are definitely correct










share|improve this question


























    up vote
    0
    down vote

    favorite












    I am using the django rest framework OAuth2 Toolkit. I have set everything up, and everything seems to be fine, except that LinkedIn returns a 401 unauthorized response when I try to get an access token. The trace is:



    2018-11-21 14:28:22,904 [middlewares 70] INFO: {"method": "POST", "user_id": 234630, "request_post_body": {"authorization_grant_type": "authorization-code", "client_id": "foo", "csrfmiddlewaretoken": "foobar", "initial-client_id": "foo", "initial-client_secret": "bar", "redirect_uris": "http://xeniadev.com:3000/linkedin-login-redirect", "user": "234630", "_save": "Save", "name": "LinkedIn", "client_secret": "bar", "client_type": "public"}, "path": "/admin/oauth2_provider/application/1/change/", "device_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36", "user": ""}
    [21/Nov/2018 14:28:22] "POST /admin/oauth2_provider/application/1/change/ HTTP/1.1" 302 0
    2018-11-21 14:28:23,830 [middlewares 70] INFO: {"method": "GET", "user_id": 234630, "user": "", "path": "/admin/oauth2_provider/application/", "device_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36"}
    [21/Nov/2018 14:28:23] "GET /admin/oauth2_provider/application/ HTTP/1.1" 200 2874
    2018-11-21 14:28:23,920 [middlewares 70] INFO: {"method": "GET", "user_id": 234630, "user": "", "path": "/admin/jsi18n/", "device_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36"}
    [21/Nov/2018 14:28:23] "GET /admin/jsi18n/ HTTP/1.1" 200 909
    2018-11-21 14:28:32,895 [resource 74] DEBUG: Dispatching token_type Bearer request to <oauthlib.oauth2.rfc6749.tokens.BearerToken object at 0x12001b4c0>.
    2018-11-21 14:28:32,895 [oauth2_endpoints 58] DEBUG: Dispatching grant_type convert_token request to <rest_framework_social_oauth2.oauth2_grants.SocialTokenGrant object at 0x11d9f86d8>.
    2018-11-21 14:28:32,895 [refresh_token 58] DEBUG: Validating refresh token request, <oauthlib.Request url="/auth/convert-token", http_method="POST", headers="", body="<SANITIZED>&backend=linkedin-oauth2&client_id=foo&grant_type=convert_token">.
    2018-11-21 14:28:32,963 [oauth2_validators 243] DEBUG: Application '77ha5jwgczyohk' has type 'public'
    2018-11-21 14:28:32,964 [base 147] DEBUG: Validating access to scopes ['read', 'write'] for client 'foo' (<Application: LinkedIn>).
    2018-11-21 14:28:32,978 [connectionpool 813] DEBUG: Starting new HTTPS connection (1): api.linkedin.com:443
    2018-11-21 14:28:33,320 [connectionpool 393] DEBUG: https://api.linkedin.com:443 "GET /v1/people/~:(email-address,first-name,headline,id,industry,last-name)?format=json HTTP/1.1" 401 None
    2018-11-21 14:28:33,324 [middlewares 70] INFO: {"method": "POST", "user": "AnonymousUser", "path": "/auth/convert-token", "device_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0.1 Safari/605.1.15", "request_post_body": {"grant_type": "convert_token", "backend": "linkedin-oauth2", "client_id": "foo", "token": "footokenbar"}}
    2018-11-21 14:28:33,325 [log 228] WARNING: Unauthorized: /auth/convert-token
    [21/Nov/2018 14:28:33] "POST /auth/convert-token HTTP/1.1" 401 79


    Unfortunately, neither this trace nor the linkedin developer console tells me anything about why this is happening. The client_id and client_secret are definitely correct










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am using the django rest framework OAuth2 Toolkit. I have set everything up, and everything seems to be fine, except that LinkedIn returns a 401 unauthorized response when I try to get an access token. The trace is:



      2018-11-21 14:28:22,904 [middlewares 70] INFO: {"method": "POST", "user_id": 234630, "request_post_body": {"authorization_grant_type": "authorization-code", "client_id": "foo", "csrfmiddlewaretoken": "foobar", "initial-client_id": "foo", "initial-client_secret": "bar", "redirect_uris": "http://xeniadev.com:3000/linkedin-login-redirect", "user": "234630", "_save": "Save", "name": "LinkedIn", "client_secret": "bar", "client_type": "public"}, "path": "/admin/oauth2_provider/application/1/change/", "device_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36", "user": ""}
      [21/Nov/2018 14:28:22] "POST /admin/oauth2_provider/application/1/change/ HTTP/1.1" 302 0
      2018-11-21 14:28:23,830 [middlewares 70] INFO: {"method": "GET", "user_id": 234630, "user": "", "path": "/admin/oauth2_provider/application/", "device_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36"}
      [21/Nov/2018 14:28:23] "GET /admin/oauth2_provider/application/ HTTP/1.1" 200 2874
      2018-11-21 14:28:23,920 [middlewares 70] INFO: {"method": "GET", "user_id": 234630, "user": "", "path": "/admin/jsi18n/", "device_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36"}
      [21/Nov/2018 14:28:23] "GET /admin/jsi18n/ HTTP/1.1" 200 909
      2018-11-21 14:28:32,895 [resource 74] DEBUG: Dispatching token_type Bearer request to <oauthlib.oauth2.rfc6749.tokens.BearerToken object at 0x12001b4c0>.
      2018-11-21 14:28:32,895 [oauth2_endpoints 58] DEBUG: Dispatching grant_type convert_token request to <rest_framework_social_oauth2.oauth2_grants.SocialTokenGrant object at 0x11d9f86d8>.
      2018-11-21 14:28:32,895 [refresh_token 58] DEBUG: Validating refresh token request, <oauthlib.Request url="/auth/convert-token", http_method="POST", headers="", body="<SANITIZED>&backend=linkedin-oauth2&client_id=foo&grant_type=convert_token">.
      2018-11-21 14:28:32,963 [oauth2_validators 243] DEBUG: Application '77ha5jwgczyohk' has type 'public'
      2018-11-21 14:28:32,964 [base 147] DEBUG: Validating access to scopes ['read', 'write'] for client 'foo' (<Application: LinkedIn>).
      2018-11-21 14:28:32,978 [connectionpool 813] DEBUG: Starting new HTTPS connection (1): api.linkedin.com:443
      2018-11-21 14:28:33,320 [connectionpool 393] DEBUG: https://api.linkedin.com:443 "GET /v1/people/~:(email-address,first-name,headline,id,industry,last-name)?format=json HTTP/1.1" 401 None
      2018-11-21 14:28:33,324 [middlewares 70] INFO: {"method": "POST", "user": "AnonymousUser", "path": "/auth/convert-token", "device_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0.1 Safari/605.1.15", "request_post_body": {"grant_type": "convert_token", "backend": "linkedin-oauth2", "client_id": "foo", "token": "footokenbar"}}
      2018-11-21 14:28:33,325 [log 228] WARNING: Unauthorized: /auth/convert-token
      [21/Nov/2018 14:28:33] "POST /auth/convert-token HTTP/1.1" 401 79


      Unfortunately, neither this trace nor the linkedin developer console tells me anything about why this is happening. The client_id and client_secret are definitely correct










      share|improve this question













      I am using the django rest framework OAuth2 Toolkit. I have set everything up, and everything seems to be fine, except that LinkedIn returns a 401 unauthorized response when I try to get an access token. The trace is:



      2018-11-21 14:28:22,904 [middlewares 70] INFO: {"method": "POST", "user_id": 234630, "request_post_body": {"authorization_grant_type": "authorization-code", "client_id": "foo", "csrfmiddlewaretoken": "foobar", "initial-client_id": "foo", "initial-client_secret": "bar", "redirect_uris": "http://xeniadev.com:3000/linkedin-login-redirect", "user": "234630", "_save": "Save", "name": "LinkedIn", "client_secret": "bar", "client_type": "public"}, "path": "/admin/oauth2_provider/application/1/change/", "device_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36", "user": ""}
      [21/Nov/2018 14:28:22] "POST /admin/oauth2_provider/application/1/change/ HTTP/1.1" 302 0
      2018-11-21 14:28:23,830 [middlewares 70] INFO: {"method": "GET", "user_id": 234630, "user": "", "path": "/admin/oauth2_provider/application/", "device_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36"}
      [21/Nov/2018 14:28:23] "GET /admin/oauth2_provider/application/ HTTP/1.1" 200 2874
      2018-11-21 14:28:23,920 [middlewares 70] INFO: {"method": "GET", "user_id": 234630, "user": "", "path": "/admin/jsi18n/", "device_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36"}
      [21/Nov/2018 14:28:23] "GET /admin/jsi18n/ HTTP/1.1" 200 909
      2018-11-21 14:28:32,895 [resource 74] DEBUG: Dispatching token_type Bearer request to <oauthlib.oauth2.rfc6749.tokens.BearerToken object at 0x12001b4c0>.
      2018-11-21 14:28:32,895 [oauth2_endpoints 58] DEBUG: Dispatching grant_type convert_token request to <rest_framework_social_oauth2.oauth2_grants.SocialTokenGrant object at 0x11d9f86d8>.
      2018-11-21 14:28:32,895 [refresh_token 58] DEBUG: Validating refresh token request, <oauthlib.Request url="/auth/convert-token", http_method="POST", headers="", body="<SANITIZED>&backend=linkedin-oauth2&client_id=foo&grant_type=convert_token">.
      2018-11-21 14:28:32,963 [oauth2_validators 243] DEBUG: Application '77ha5jwgczyohk' has type 'public'
      2018-11-21 14:28:32,964 [base 147] DEBUG: Validating access to scopes ['read', 'write'] for client 'foo' (<Application: LinkedIn>).
      2018-11-21 14:28:32,978 [connectionpool 813] DEBUG: Starting new HTTPS connection (1): api.linkedin.com:443
      2018-11-21 14:28:33,320 [connectionpool 393] DEBUG: https://api.linkedin.com:443 "GET /v1/people/~:(email-address,first-name,headline,id,industry,last-name)?format=json HTTP/1.1" 401 None
      2018-11-21 14:28:33,324 [middlewares 70] INFO: {"method": "POST", "user": "AnonymousUser", "path": "/auth/convert-token", "device_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0.1 Safari/605.1.15", "request_post_body": {"grant_type": "convert_token", "backend": "linkedin-oauth2", "client_id": "foo", "token": "footokenbar"}}
      2018-11-21 14:28:33,325 [log 228] WARNING: Unauthorized: /auth/convert-token
      [21/Nov/2018 14:28:33] "POST /auth/convert-token HTTP/1.1" 401 79


      Unfortunately, neither this trace nor the linkedin developer console tells me anything about why this is happening. The client_id and client_secret are definitely correct







      linkedin-api python-social-auth django-socialauth






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 21 at 15:21









      Alex

      400213




      400213





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53415234%2fusing-django-oauth2-for-django-rest-framework-with-linkedin%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53415234%2fusing-django-oauth2-for-django-rest-framework-with-linkedin%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Contact image not getting when fetch all contact list from iPhone by CNContact

          count number of partitions of a set with n elements into k subsets

          A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks