I've installed this on a pretty clean install of D7 and getting this error after I authorize with linkedin when creating a new account:

PHP Fatal error: Call to undefined function linkedin_access_token() in /var/www/sites/all/modules/linkedin/linkedin_auth/linkedin_auth.module on line 161,

The account is created, but from what I can see, is not linked to the linkedin authoring.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jarchowk’s picture

No clue guys?

jarchowk’s picture

More info.. when I "log in with linkedin", it pushes me out to the linkedin auth page. Once I authorize, it puts me back to the site to the login create screen. I fill in a user name and email address, then I yet again go to linkedin for authorization (a different one apparently). Then it goes back to the user page and I get the error:

LinkedIn debug : Access denied to /linkedin/token/10. Requesting user has uid 0, which is different from the requested account.

nielx’s picture

FileSize
965 bytes

I attached a patch that fixed the issue.

nielx’s picture

Status: Active » Needs review
krishnaku’s picture

FileSize
1.48 KB

I dont this this patch really addresses the issue. We still need to call the code in linkedin_access_token after registering and logging in the user so that the newly created account can be linked with the linkedin account. Short circuiting this with a call to linkedin_access_token avoids the error reported, but does not complete the workflow correctly.

I suspect that the issue is somehow related to the way the various include files are distributed between the linkedin module and linked_auth modules, and somehow the flow from /user/register is causing to get to this callback without linkedin.inc being included - but I did not have the time to figure out the correct solution, so I opted for the following hack before the call to linkedin_access_token:

    if (!function_exists('linkedin_access_token')) {
        module_load_include('inc', 'linkedin', 'linkedin');
  }

This let me proceed to the call to linkedin_access_token which then failed with the error #2 reported by jarchowk.

I also think that replacing the access callback with the linkedin_auth_token_access callback to fix this error is also incorrect. Within the context of where it is invoked, the user has just been registered and logged in and so we now have an active session with the uid of the newly registered user. The check being applied in
linkedin_token_access is correct imho for this scenario. The trouble is that when the callback arrives, the session has lost this uid.

I traced this problem down to one problem in core and one in linkedin_auth_register_form_submit code. The first issue is that the user_external_login_register
call causes the session to be regenerated and written to the DB and when it does so, the code in drupal_session_regenerate does not write the uid to the DB, so the session remains associated with uid 0. The second problem is that when linkedin_auth_register_form saves the user, it does so with status = 0 rather than status =1 (enabled by default). Thus when the session is reinitialized on the next call, this uid is not considered valid for authentication, so _drupal_session_read in session.inc replaces it with an anonymous user. Together these two cause the uid established in the login to get lost in the subsequent call.

I have attached the diffs to this post for your review. I need to pull these down from github and make a proper patch, but am busy catching up from all the time I lost tracking this issue down. So I'll get to it when I can..for now I am moving on with my changes made in place..

With these changes, I was able to get workflow linking the two accounts to work correctly end to end. Hopefully this is helpful to you. BTW. I suspect that the better approach is to just avoid this separate linking workflow and log in the user in automatically as a related thread here has discussed.

acbramley’s picture

Issue summary: View changes
Priority: Normal » Critical
Status: Needs review » Needs work

Bumping priority, currently this module doesn't quite work properly.

After enabling the linkedin and linkedin_auth modules I added my dev environment as an app at https://www.linkedin.com/secure/developer and filled in the relevant settings (note: I left the Bypass email verification unchecked).

* When I go to /user and hit Login using LinkedIn I get taken to the Authorize page on the Linkedin site.
* After filling in my linkedin account credentials I'm taken back to the Drupal site and shown "No user associated with this LinkedIn account. Please register." so I add the email address and hit create new account
* After clicking the one time login link in the email, I am successfully logged in, but the crucial part of actually pairing my account with my linked in account is not done. I have to manually go to the Linkedin tab on the user edit screen again and authorize the account for a second time
* I then tried enabling the Bypass email verification stuff to see if that was causing it which lead me to this call to undefined function error after authorizing with linkedin and filling in my email address.