Search code examples
mysqldrupaldrupal-7slack

Implementing the "sign in with slack" button for a drupal site


Slack offers a simple oauth method (sign in with slack) for existing slack users to cross-authenticate to "my platform," whatever that may be. I've been able to do everything on the slack side, including getting a real name and email address from slack's identity scope and finding my user in the drupal mysql database users table.

But how can I actually log this user in and create/regenerate a session programmatically? Is there a way to do this from command line using drush or something, without having to edit the php, because that's not my preference. I thought I could just modify the timestamps in the database, but it looks like the session object requires more than that.

So given a drupal uid, and access to the drupal DB, what do I do?


Solution

  • Since both systems are on the same server, I wrote a python script to modify the drupal7 mysql database and "log them in" without using any drupal environment tricks. By updating the access timestamp for the user, the system treats as logged in. I also added code to run drush -user-create from the command line if the slack user's email doesn't match the drupal users table in the database.

    This was definitely not my preferred route, but it seems drupal's own tricks are more along the line of a bot impersonating a user anyway.

    I did not figure out how to create a session cookie and provide it to the user during login, so if you know how to do that, I'd love to know!