Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 6 commits
  • 6 files changed
  • 0 commit comments
  • 1 contributor
View
1  Gemfile
@@ -15,6 +15,7 @@ gem 'sqlite3'
gem 'sinatra'
gem 'thin'
gem 'haml'
+gem 'sinatra-content-for'
#for clients
gem "oauth2"
View
1  clients/web-client/.gitignore
@@ -0,0 +1 @@
+connect.yaml
View
2  clients/web-client/Gemfile
@@ -1,3 +1,5 @@
+source 'https://rubygems.org'
+
group :server do
gem "sinatra", "~> 1.3.2"
gem "sinatra-contrib", "~> 1.3.1"
View
45 clients/web-client/application.rb
@@ -1,16 +1,35 @@
+require 'singleton'
+DEFAULT_OPTS = {:mode=>:header, :header_format=>"OAuth %s", :param_name=>"oauth_token"}
-class WebClient < Sinatra::Base
+class Connect
+ include Singleton
+ include Openplacos::Connection
- CLIENT_ID = '7olsiabevyxnp7c33crmrkbqb'
- CLIENT_SECRET = 'c04d6719rqwkuy0o7juicudr5'
- REDIRECT_URI = 'http://localhost:9292/oauth2/callback'
- DEFAULT_OPTS = {:mode=>:header, :header_format=>"OAuth %s", :param_name=>"oauth_token"}
- SITE_URL = 'http://localhost:4567'
+ attr_reader :client, :redirect_uri
+ attr_accessor :token
- Client = OAuth2::Client.new(CLIENT_ID,CLIENT_SECRET, {:site => SITE_URL, :token_url => '/oauth/authorize'})
+ def init
+ @file_config = File.dirname(__FILE__) + "/connect.yaml"
+ @url = 'http://localhost:4567'
+ @name = 'web-client'
+ @redirect_uri = 'http://localhost:9292/oauth2/callback'
+ @token = {}
+ load_config
+
+ if @token_params[@url].nil? #get token -- first time
+
+ register()
+ save_config
+ end
+ create_client()
+ end
+
+end
- Token = Hash.new
+
+class WebClient < Sinatra::Base
+
helpers Sinatra::ContentFor
# sinatra configuration
@@ -24,7 +43,7 @@ class WebClient < Sinatra::Base
get '/' do
-
+
content_for :menu_left do
"salut"
end
@@ -37,15 +56,15 @@ class WebClient < Sinatra::Base
end
get '/oauth2/callback' do
- token = Client.auth_code.get_token(params[:code], {:redirect_uri => REDIRECT_URI}, DEFAULT_OPTS)
+ token = ::Connect.instance.client.auth_code.get_token(params[:code], {:redirect_uri => ::Connect.instance.redirect_uri}, DEFAULT_OPTS)
session[:token] = token.token
- Token[token.token] = token
+ ::Connect.instance.token[token.token] = token
redirect "/"
end
get '/login' do
if session[:token].nil?
- redirect Client.auth_code.authorize_url({:redirect_uri => REDIRECT_URI, :scope => "user read write"})
+ redirect ::Connect.instance.client.auth_code.authorize_url({:redirect_uri => ::Connect.instance.redirect_uri, :scope => "user read write"})
end
redirect "/"
end
@@ -56,7 +75,7 @@ class WebClient < Sinatra::Base
end
def oposRequest(url)
- token = Token[session[:token]]
+ token = ::Connect.instance.token[session[:token]]
if !token.nil?
resp = token.get(url)
return JSON.parse(resp.body)
View
2  clients/web-client/config.ru
@@ -2,6 +2,8 @@ require 'sinatra'
require 'sinatra/content_for'
require 'oauth2'
require 'json'
+require File.join(File.dirname(__FILE__),'/../../gem/lib/openplacos/libclient.rb')
require File.join(File.dirname(__FILE__),'application.rb')
+Connect.instance.init
run WebClient.new
View
4 gem/lib/openplacos/libclient.rb
@@ -85,7 +85,7 @@ def create_client
{:site => "#{@url}",
:token_url => '/oauth/authorize'
}
- )
+ )
end
def get_grant_url(type_)
@@ -95,7 +95,7 @@ def get_grant_url(type_)
# save config with token, client_id and secret into a userspace directory
# needed to not regrant client every connection
def save_config
- @token_params[@url] = @token.to_hash
+ @token_params[@url] = @token ? @token.to_hash : {}
@token_params[@url][:client_id] = @client_id
@token_params[@url][:client_secret] = @client_secret

No commit comments for this range

Something went wrong with that request. Please try again.