summaryrefslogtreecommitdiff
path: root/script/invalidate_bearer_token
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2016-09-14 11:11:48 +0200
committerAzul <azul@riseup.net>2016-09-14 11:11:48 +0200
commitf575f57915d5369269849352a70b0e4704c3fd19 (patch)
tree7b13646448e64e560101493eeac1a03c3a25dbd8 /script/invalidate_bearer_token
parent92481029074f34342cc35937f3aab94aca7887c7 (diff)
parent22478d315af3590d2a344eb1aa8cf2aec0730506 (diff)
Merge remote-tracking branch 'pr/237' into develop
Twitter Feature on Main-View from @loadtocode Twitter feature within home/index of LEAP web app as feed of tweets of one user's twitter account How to use it: set up an Application-only authentication by twitter (https://dev.twitter.com/oauth/application-only) and then create a config/secrets.yml including: ``` development: twitter: enabled: false # set to true for usage twitter_handle: XXXXX #put your twitter handle here bearer_token: XXXXX #put your bearer token here test: twitter: enabled: false # set to true for usage twitter_handle: XXXXX #put your twitter handle here bearer_token: XXXXX #put your bearer token here ``` things in the PR: - [x] gemfile:twitter - [x] twitter helper (caching (to avoid reaching twitter rate limits) - [x] index twitter view - [x] twitter css (twitter design as discussed in call: Profil-Header: Picture, Link to twitter + twitter_handle; removed picture and twitter_handle from individual tweet, heading aligns at the top, only the last 3 tweets are shown) - [x] script to generate bearer token - [x] script to invalidate generated bearer token - [x] documentation (Readme + Doc)
Diffstat (limited to 'script/invalidate_bearer_token')
-rwxr-xr-xscript/invalidate_bearer_token47
1 files changed, 47 insertions, 0 deletions
diff --git a/script/invalidate_bearer_token b/script/invalidate_bearer_token
new file mode 100755
index 0000000..eda1c7d
--- /dev/null
+++ b/script/invalidate_bearer_token
@@ -0,0 +1,47 @@
+#!/usr/bin/env ruby
+
+require "net/http"
+require "uri"
+require "json"
+require "base64"
+require "optparse"
+
+options = {}
+
+option_parser = OptionParser.new do |opts|
+ opts.banner = "Invalidate your bearer_token for twitter by including the following [options]. The bearer token can't be used afterwards anymore. Please create a new bearer-token if you want to activate the twitter feature again."
+
+ opts.on("--key KEY", "consumer_key of your twitter application") do |key|
+ options[:conkey] = key
+ end
+
+ opts.on("--secret SECRET", "consumer_secret of your twitter application") do |secret|
+ options[:consec] = secret
+ end
+
+ opts.on("--token TOKEN", "bearer token for twitter") do |token|
+ options[:token] = token
+ end
+
+end
+
+option_parser.parse!
+
+if options[:conkey].nil? || options[:consec].nil? || options[:token].nil? then
+ puts option_parser
+ exit
+else
+ consumer_key = options[:conkey]
+ consumer_secret = options[:consec]
+ bearer_token = options[:token]
+end
+
+uri = URI("https://api.twitter.com/oauth2/invalidate_token")
+data = "access_token=#{bearer_token}"
+cre = Base64.strict_encode64("#{consumer_key}:#{consumer_secret}")
+authorization_headers = { "Authorization" => "Basic #{cre}"}
+
+Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
+ response = http.request_post(uri, data, authorization_headers)
+ puts JSON.parse(response.body)
+end