Sha256: 76d82f2095139c3a634088046ce350921fbe56477a7db55b259bed95eacabaf9
Contents?: true
Size: 1.03 KB
Versions: 15
Compression:
Stored size: 1.03 KB
Contents
# A simple Sinatra example demonstrating OAuth2 implementation with Geoloqi require 'rubygems' require 'sinatra' require 'geoloqi' GEOLOQI_REDIRECT_URI = 'http://yourwebsite.net' enable :sessions set :session_secret, 'PUT A SECRET WORD HERE' # Encrypts the cookie session.. recommended. def geoloqi @geoloqi ||= Geoloqi::Session.new :auth => session[:geoloqi_auth], :config => {:client_id => 'YOUR OAUTH CLIENT ID', :client_secret => 'YOUR CLIENT SECRET'} end # If the access token expires, Geoloqi::Session will refresh inline! # This after block makes sure the session gets the updated config. after do session[:geoloqi_auth] = @geoloqi.auth end get '/?' do geoloqi.get_auth(params[:code], GEOLOQI_REDIRECT_URI) if params[:code] && !geoloqi.access_token? redirect geoloqi.authorize_url(GEOLOQI_REDIRECT_URI) unless geoloqi.access_token? username = geoloqi.get('account/username')['username'] "You have successfully logged in as #{username}!" end
Version data entries
15 entries across 15 versions & 1 rubygems