Skip to content
This repository has been archived by the owner on Aug 23, 2020. It is now read-only.

Commit

Permalink
初回認証時だけブラウザから許可させる
Browse files Browse the repository at this point in the history
  • Loading branch information
mashiro committed Jun 18, 2013
1 parent fd859fa commit e2d1166
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
1 change: 1 addition & 0 deletions lib/facebook_irc_gateway/locale/en.yml
Expand Up @@ -20,6 +20,7 @@ en:
app_secret: "Input your Application Secret: "
email: "Input your mail address: "
password: "Input your password: "
access_to: "Please access this URL and allow this Application. Retry this after."
expires_in: "Access token expires in %{date}"
complete: "Complete Setup!!"
fail: "Setup failed."
Expand Down
1 change: 1 addition & 0 deletions lib/facebook_irc_gateway/locale/ja.yml
Expand Up @@ -20,6 +20,7 @@ ja:
app_secret: "アプリの秘訣を入力してください: "
email: "メールアドレスを入力してください: "
password: "パスワードを入力してください: "
access_to: "この URL にアクセスし、アプリケーションを許可してください。その後再度セットアップを実行してください。"
expires_in: "アクセストークンの有効期限は %{date} です。"
complete: "これでセットアップは完了です。"
fail: "セットアップに失敗しました。"
Expand Down
28 changes: 17 additions & 11 deletions setup.rb
Expand Up @@ -25,6 +25,7 @@ def noecho

DEFAULT_APP_ID = '221646024527845'
DEFAULT_APP_SECRET = '012749b22fcc3111ea88760c209cdb27'
CALLBACK_URL = 'https://www.facebook.com/connect/login_success.html'

PERMISSIONS = [
'user_about_me', 'friends_about_me', 'user_activities', 'friends_activities',
Expand Down Expand Up @@ -66,7 +67,7 @@ def noecho

client = FacebookOAuth::Client.new(:application_id => app_id,
:application_secret => app_secret,
:callback => 'https://www.facebook.com/connect/login_success.html')
:callback => CALLBACK_URL)

auth_url = client.authorize_url :response_type => 'token', :scope => PERMISSIONS.join(',')

Expand All @@ -81,19 +82,24 @@ def noecho
puts ''

success_page = form.submit
params = Hash[*success_page.uri.fragment.split('&').map { |s| s.split('=') }.flatten]
if success_page.uri.path == URI(CALLBACK_URL).path
params = Hash[*success_page.uri.fragment.split('&').map { |s| s.split('=') }.flatten]

access_token = params['access_token']
expires_in = params['expires_in'].to_i
access_token = params['access_token']
expires_in = params['expires_in'].to_i

Pit.set('facebook_irc_gateway', :data => {
'id' => app_id,
'secret' => app_secret,
'token' => access_token
})
Pit.set('facebook_irc_gateway', :data => {
'id' => app_id,
'secret' => app_secret,
'token' => access_token
})

puts I18n.t('setup.complete')
puts I18n.t('setup.expires_in', :date => expires_in.seconds.since)
puts I18n.t('setup.complete')
puts I18n.t('setup.expires_in', :date => expires_in.seconds.since)
else
puts I18n.t('setup.access_to')
puts FacebookIrcGateway::Utils.shorten_url auth_url
end
end
end
rescue => e
Expand Down

0 comments on commit e2d1166

Please sign in to comment.