Open samstarling opened 6 years ago
Hey @samstarling ! Did you managed to solve that?
Hey @mknarciso – no, sadly I abandoned the project, and didn't get another chance to investigate this. However, if you find a solution, let me know – I'm still interested. Good luck!
Hi @samstarling !! Actually i've done a pretty ugly hack that made it work, but for sure is not the right solution...
I think that the CSRF problem is due to hard coding the link, i've got it when I tried here, maybe because we don't have the state variable. If I call it via the devise path it works.
I created both providers in an omniauth.rb file, as in the documentation.
My problem was that I was getting a false response due to authentication error for the sign_in path. The thing is that this error is on omniauth, and not Slack side, and the answer despite showing an error comes with a valid token. So instead of directly using request.env["omniauth.auth"]
I've done this:
def slack_sign_in
token = request.env["omniauth.auth"]["credentials"]["token"]
info = get_info(token)
Rails.logger.info info
team = Team.find_by(slack_id: info["team"]["id"])
...
end
where
def get_info(token)
require 'net/http'
require 'uri'
headers = {'Content-Type' => 'application/x-www-form-urlencoded'}
uri = URI.parse('https://slack.com/api/users.identity')
params = { :token => token}
uri.query = URI.encode_www_form( params )
res = Net::HTTP.post_form(uri, headers)
JSON.parse(res.body)
end
Pretty ugly I now, but after 3 days it worked....
Best!
PS: I tried to use @ginjo fork of omniauth-slack gem, but ran into some strange errors with the new method for Slack module.
Hey @kmrshntr: do you have any pointers on using multiple scopes with Devise? I'd like the users for a Slack team to be able to "Sign in using Slack" (
identity.basic
scope) and then add my bot (bot
scope). At the moment, I'm using a manual "Add to Slack" button (as per their documentation) which produces a link like this:However, when it redirects back to my application, I get:
Two questions:
config.omniauth :slack
definitions indevise.rb
, with different names? If so, how can I use those names when I'm generating links? Can I pass parameters touser_slack_omniauth_authorize_path
?