Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
[ProxyConnect) How to extend user details transferred?
judgej
✭
I wonder if you can provide any development advice on something that I am trying to do. It is nearly working, but the execution paths through this plugin is just too complicated for me to follow.
Basically, my CMS is providing additional information on the users in the authorise URL. The information is used to put the users into specific roles, set up a default signature and a few other things. Capturing this information is simple: I have added a line of code in _GetForeignCredentials() to save *all* the response details in the Gdn_ProxyAuthenticator object:
Now, that works, but the problem lies in where to put an event to be able to use that information.
What I need is one or more events that will catch the post-authentication of a user so that I can look at these details and update the user's account accordingly. The Autenticate() method provides one place that works *most* of the time, around line 64:
This works when an existing user comes to the forum. However, when a user comes to the forum for the first time, and is subsequently created, this event does not fire. I cannot find where in this plugin to place an event that would have access to both the saved ResponseResult details and the newly-created user.
(Edit: I will add, then when a user comes in for the first time and this event does not fire, pressing the browser back button to back out again to the calling CMS will fire this event four times! I have no idea what is going on there, and is one reason why I don't understand the code execution path.)
Do you have any pointer as to where this would be a good place? Once I have this working, would you also consider putting the events into the core plugin so other plugins can extend it?
Alternatively, maybe I am looking to hook the wrong thing? Perhaps there is an event in the core Vanilla that has access to the Authenticator object and fires after a user is logged in, whether they have just been created by your plugin or not?
Thanks in advance! And sorry this is such a long post, but I'm tearing my hair out trying to follow the execution path, and the cookies and redirects and handshakes...
-- Jason
Basically, my CMS is providing additional information on the users in the authorise URL. The information is used to put the users into specific roles, set up a default signature and a few other things. Capturing this information is simple: I have added a line of code in _GetForeignCredentials() to save *all* the response details in the Gdn_ProxyAuthenticator object:
$this->ProxyRequestResponseResult = $Result;
Now, that works, but the problem lies in where to put an event to be able to use that information.
What I need is one or more events that will catch the post-authentication of a user so that I can look at these details and update the user's account accordingly. The Autenticate() method provides one place that works *most* of the time, around line 64:
...
Gdn::Authenticator()->Trigger($AuthResponse);
if ($AuthResponse == Gdn_Authenticator::AUTH_SUCCESS) {
// Everything's cool, we don't have to do anything.
$this->EventArguments['ProxyRequestResponseResult'] = $this->ProxyRequestResponseResult;
$this->FireEvent('AfterUserAuthenticated');
} elseif ($AuthResponse == Gdn_Authenticator::AUTH_PARTIAL) {
...
This works when an existing user comes to the forum. However, when a user comes to the forum for the first time, and is subsequently created, this event does not fire. I cannot find where in this plugin to place an event that would have access to both the saved ResponseResult details and the newly-created user.
(Edit: I will add, then when a user comes in for the first time and this event does not fire, pressing the browser back button to back out again to the calling CMS will fire this event four times! I have no idea what is going on there, and is one reason why I don't understand the code execution path.)
Do you have any pointer as to where this would be a good place? Once I have this working, would you also consider putting the events into the core plugin so other plugins can extend it?
Alternatively, maybe I am looking to hook the wrong thing? Perhaps there is an event in the core Vanilla that has access to the Authenticator object and fires after a user is logged in, whether they have just been created by your plugin or not?
Thanks in advance! And sorry this is such a long post, but I'm tearing my hair out trying to follow the execution path, and the cookies and redirects and handshakes...
-- Jason
1
Comments
Just a tl;dr summary:
On logging in using ProxyConnect for the first time, I would like additional information from the CMS to apply to the vanilla account. I can capture the additional information sent by the CMS, and I can use that information to update the user's account. What I can't see, is where to hook into the ProxyConnect plugin so that the captured information can be used to update the current user's account (the user that has just been created and/or authenticated), in such a way that the update is guaranteed to happen.
I will now use a cron job to get my CMS to create users directly in the Vanilla database. It's not ideal, but it should work. It seems to be the only way to get details of users in the CMS into Vanilla.
Vanilla Forums COO [GitHub, Twitter, About.me]
Gdn_Auth_AuthSuccess_Handler($Sender)
Gdn_Auth_AuthCreated_Handler($Sender)
Vanilla Forums COO [GitHub, Twitter, About.me]
Vanilla Forums COO [GitHub, Twitter, About.me]
I wasn't trying to be critical or impatient when saying I was giving up on this approach - I was just giving in to the realities of deadlines and the time people have available. Now you open another door. Thanks.
Edit: got it. Pull "master" then merge in "unstable".
The method that does the fetching is Gdn_ProxyAuthenticator->_GetForeignCredentials() and it is that which only takes those four parameters. To be useful for extending user details that are passed in, that method needs to record all the additional name/value pairs that the handshake provides.
Edit: so far as I can see, the Gdn_Auth_AuthCreated_Handler is never fired. But then the result is not set to AUTH_CREATED anywhere in the code, so that's no surprise. Unless there is some core unstable code I haven't spotted and included?
if ($Result) { $ReturnArray = array( 'Email' => ArrayValue('Email', $Result), 'Name' => ArrayValue('Name', $Result), 'UniqueID' => ArrayValue('UniqueID', $Result), 'TransientKey' => ArrayValue('TransientKey', $Result, NULL) ); // JDJ: save the full handshake data. $this->ProxyRequestResponseResult = $Result; return $ReturnArray; }
Then passing that data into the event in WakeUp():
$UserEventData = array_merge(array( 'UserID' => Gdn::Session()->UserID, 'Payload' => GetValue('HandshakeResponse', $this, FALSE), 'Payload2' => GetValue('ProxyRequestResponseResult', $this, FALSE), // JDJ send saved data ),$UserInfo);
This just sticks the full authentication handshake data into "payload2" and leaves "payload" unchanged, since other plugins may still expect it to be there in its current form.
I'm trying to use the latest version of your module with the smallest hacks possible, and those two labelled lines do it for me. It doesn't deal with the non-used AUTH_CREATED, but that's the next step.
Vanilla Forums COO [GitHub, Twitter, About.me]