Created
December 27, 2017 15:36
-
-
Save vanakenm/3f59e88d00e0caaaf4b7cf2527574e64 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OauthController < ApplicationController | |
def authorize | |
options = { | |
site: 'https://slack.com/oauth/authorize' | |
} | |
client ||= OAuth2::Client.new( | |
ENV('SLACK_CLIENT_ID'), | |
ENV('SLACK_CLIENT_SECRET'), | |
options | |
) | |
params = { | |
scope: 'commands', | |
redirect_uri: 'https://www.effinbot.com/oauth/callback' | |
} | |
redirect_to client.auth_code.authorize_url(params) | |
end | |
def success; end | |
def error; end | |
def authorize_callback | |
code = params['code'] | |
response = HTTParty.get("https://slack.com/api/oauth.access?code=#{code}&client_id=#{ENV('SLACK_CLIENT_ID')}&client_secret=#{ENV['SLACK_CLIENT_SECRET']}") | |
if response['ok'] && response['ok'] == true | |
redirect_to '/success' | |
else | |
redirect_to '/error' | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment