Last active
December 25, 2015 13:19
-
-
Save swistak/6982393 to your computer and use it in GitHub Desktop.
Test script for ePaństwo Paszport.
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
require 'sinatra' | |
require 'oauth2' | |
require 'json' | |
require 'logger' | |
require 'pp' | |
set :port, 3000 | |
site = ARGV[0] || 'http://paszport.epf.org.pl/' | |
callback_host = ARGV[1] || 'http://localhost:3000' | |
client_id = ARGV[2] || "NTI1ODJkNjQ0MjM5MTQ1" | |
client_secret = ARGV[3] || 'b916286cf330c5940a9e3d8e64cbc628ce15d1bc' | |
cb_path = '/auth/epanstwo/callback' | |
client = OAuth2::Client.new(client_id, client_secret, :site => site, :token_method => :get) | |
request_logger = Logger.new($stdout) | |
request_logger.formatter = proc do |severity, datetime, progname, msg| | |
"%6s: %s\n" % [severity, msg.split("\n").join("\n" + " "*6 + "| ")] | |
end | |
client.connection.response :logger, request_logger | |
auth_url = client.auth_code.authorize_url(:redirect_uri => callback_host + cb_path) | |
puts "Opening authorization url." | |
system("xdg-open", auth_url) | |
get cb_path do | |
code = params[:code] | |
puts "Got response from provider. code: #{code}" | |
puts "Getting token.\n" | |
token = client.auth_code.get_token(code) | |
puts "Got token. Getting user info." | |
puts "User info hash:" | |
pp token.get('/oauth/userinfo').parsed | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment