Change homepage_url to application_base_url
This commit is contained in:
parent
17917528f6
commit
240eb78b08
9 changed files with 51 additions and 52 deletions
|
|
@ -32,14 +32,14 @@ class AuthorizationsController < ApplicationController
|
||||||
render :text => "bad request: #{params.inspect}", :status => 403
|
render :text => "bad request: #{params.inspect}", :status => 403
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
packaged_manifest = JSON.parse(RestClient.get("#{app_url}/manifest.json").body)
|
packaged_manifest = JSON.parse(RestClient.get("#{app_url}manifest.json").body)
|
||||||
public_key = OpenSSL::PKey::RSA.new(packaged_manifest['public_key'])
|
public_key = OpenSSL::PKey::RSA.new(packaged_manifest['public_key'])
|
||||||
manifest = JWT.decode(packaged_manifest['jwt'], public_key)
|
manifest = JWT.decode(packaged_manifest['jwt'], public_key)
|
||||||
|
|
||||||
message = verify(signed_string, Base64.decode64(params[:signature]), public_key, manifest)
|
message = verify(signed_string, Base64.decode64(params[:signature]), public_key, manifest)
|
||||||
if not (message =='ok')
|
if not (message =='ok')
|
||||||
render :text => message, :status => 403
|
render :text => message, :status => 403
|
||||||
elsif manifest["homepage_url"].match(/^http:\/\/(localhost:\d+|chubbi\.es|cubbi\.es)$/).nil?
|
elsif manifest["application_base_url"].match(/^http:\/\/(localhost:\d+|chubbi\.es|cubbi\.es)\/$/).nil?
|
||||||
# This will only be temporary (less than a month) while we iron out the kinks in Diaspora Connect. Essentially,
|
# This will only be temporary (less than a month) while we iron out the kinks in Diaspora Connect. Essentially,
|
||||||
# whatever we release people will try to work off of and it sucks to build things on top of non-stable things.
|
# whatever we release people will try to work off of and it sucks to build things on top of non-stable things.
|
||||||
# We also started writing a gem that we'll release (around the same time) that makes becoming a Diaspora enabled
|
# We also started writing a gem that we'll release (around the same time) that makes becoming a Diaspora enabled
|
||||||
|
|
@ -79,7 +79,7 @@ class AuthorizationsController < ApplicationController
|
||||||
nonce = split[3]
|
nonce = split[3]
|
||||||
|
|
||||||
return 'blank public key' if public_key.n.nil?
|
return 'blank public key' if public_key.n.nil?
|
||||||
return 'the app url in the manifest does not match the url passed in the parameters' if manifest["homepage_url"] != app_url
|
return 'the app url in the manifest does not match the url passed in the parameters' if manifest["application_base_url"] != app_url
|
||||||
return 'key too small, use at least 2048 bits' if public_key.n.num_bits < 2048
|
return 'key too small, use at least 2048 bits' if public_key.n.num_bits < 2048
|
||||||
return "invalid time" unless valid_time?(time)
|
return "invalid time" unless valid_time?(time)
|
||||||
return 'invalid nonce' unless valid_nonce?(nonce)
|
return 'invalid nonce' unless valid_nonce?(nonce)
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ class OAuth2::Provider::Models::ActiveRecord::Client
|
||||||
:name => manifest["name"],
|
:name => manifest["name"],
|
||||||
:permissions_overview => manifest["permissions_overview"],
|
:permissions_overview => manifest["permissions_overview"],
|
||||||
:description => manifest["description"],
|
:description => manifest["description"],
|
||||||
:homepage_url => manifest["homepage_url"],
|
:application_base_url => manifest["application_base_url"],
|
||||||
:icon_url => manifest["icon_url"],
|
:icon_url => manifest["icon_url"],
|
||||||
:public_key => pub_key.export
|
:public_key => pub_key.export
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,11 @@
|
||||||
= link_to t('.revoke_access'), authorization_path(:id => app.id), :method => :delete, :confirm => 'are you sure?', :class => "button"
|
= link_to t('.revoke_access'), authorization_path(:id => app.id), :method => :delete, :confirm => 'are you sure?', :class => "button"
|
||||||
|
|
||||||
- if app.icon_url
|
- if app.icon_url
|
||||||
= image_tag(app.homepage_url + app.icon_url, :class => "avatar")
|
= image_tag(app.application_base_url + app.icon_url, :class => "avatar")
|
||||||
|
|
||||||
.content
|
.content
|
||||||
%div.from
|
%div.from
|
||||||
= link_to app.name, app.homepage_url
|
= link_to app.name, app.application_base_url
|
||||||
= app.description
|
= app.description
|
||||||
|
|
||||||
- else
|
- else
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#authorize
|
#authorize
|
||||||
#application-description
|
#application-description
|
||||||
= image_tag(@client.homepage_url + @client.icon_url, :id => 'client-application-image')
|
= image_tag(@client.application_base_url + @client.icon_url, :id => 'client-application-image')
|
||||||
%br
|
%br
|
||||||
%strong
|
%strong
|
||||||
= @client.name
|
= @client.name
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ class AddOAuth2Support < ActiveRecord::Migration
|
||||||
create_table 'oauth_clients', :force => true do |t|
|
create_table 'oauth_clients', :force => true do |t|
|
||||||
t.string 'name', :limit => 127, :null => false
|
t.string 'name', :limit => 127, :null => false
|
||||||
t.text 'description', :null => false
|
t.text 'description', :null => false
|
||||||
t.string 'homepage_url', :limit => 127, :null => false
|
t.string 'application_base_url', :limit => 127, :null => false
|
||||||
t.string 'icon_url', :limit => 127, :null => false
|
t.string 'icon_url', :limit => 127, :null => false
|
||||||
|
|
||||||
t.string 'oauth_identifier', :limit => 32, :null => false
|
t.string 'oauth_identifier', :limit => 32, :null => false
|
||||||
|
|
@ -14,7 +14,7 @@ class AddOAuth2Support < ActiveRecord::Migration
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index :oauth_clients, :name, :unique => true
|
add_index :oauth_clients, :name, :unique => true
|
||||||
add_index :oauth_clients, :homepage_url, :unique => true
|
add_index :oauth_clients, :application_base_url, :unique => true
|
||||||
add_index :oauth_clients, :nonce, :unique => true
|
add_index :oauth_clients, :nonce, :unique => true
|
||||||
|
|
||||||
create_table 'oauth_authorization_codes', :force => true do |t|
|
create_table 'oauth_authorization_codes', :force => true do |t|
|
||||||
|
|
@ -56,7 +56,7 @@ class AddOAuth2Support < ActiveRecord::Migration
|
||||||
drop_table 'oauth_authorization_codes'
|
drop_table 'oauth_authorization_codes'
|
||||||
|
|
||||||
remove_index :oauth_clients, :column => :nonce
|
remove_index :oauth_clients, :column => :nonce
|
||||||
remove_index :oauth_clients, :column => :homepage_url
|
remove_index :oauth_clients, :column => :application_base_url
|
||||||
remove_index :oauth_clients, :column => :name
|
remove_index :oauth_clients, :column => :name
|
||||||
|
|
||||||
drop_table 'oauth_clients'
|
drop_table 'oauth_clients'
|
||||||
|
|
|
||||||
|
|
@ -226,7 +226,7 @@ ActiveRecord::Schema.define(:version => 20110623210918) do
|
||||||
create_table "oauth_clients", :force => true do |t|
|
create_table "oauth_clients", :force => true do |t|
|
||||||
t.string "name", :limit => 127, :null => false
|
t.string "name", :limit => 127, :null => false
|
||||||
t.text "description", :null => false
|
t.text "description", :null => false
|
||||||
t.string "homepage_url", :limit => 127, :null => false
|
t.string "application_base_url", :limit => 127, :null => false
|
||||||
t.string "icon_url", :limit => 127, :null => false
|
t.string "icon_url", :limit => 127, :null => false
|
||||||
t.string "oauth_identifier", :limit => 32, :null => false
|
t.string "oauth_identifier", :limit => 32, :null => false
|
||||||
t.string "oauth_secret", :limit => 32, :null => false
|
t.string "oauth_secret", :limit => 32, :null => false
|
||||||
|
|
@ -235,7 +235,7 @@ ActiveRecord::Schema.define(:version => 20110623210918) do
|
||||||
t.text "permissions_overview", :null => false
|
t.text "permissions_overview", :null => false
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "oauth_clients", ["homepage_url"], :name => "index_oauth_clients_on_homepage_url", :unique => true
|
add_index "oauth_clients", ["application_base_url"], :name => "index_oauth_clients_on_application_base_url", :unique => true
|
||||||
add_index "oauth_clients", ["name"], :name => "index_oauth_clients_on_name", :unique => true
|
add_index "oauth_clients", ["name"], :name => "index_oauth_clients_on_name", :unique => true
|
||||||
add_index "oauth_clients", ["nonce"], :name => "index_oauth_clients_on_nonce", :unique => true
|
add_index "oauth_clients", ["nonce"], :name => "index_oauth_clients_on_nonce", :unique => true
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,11 +44,10 @@ module Chubbies
|
||||||
d.private_key_path = File.dirname(__FILE__) + "/chubbies.private.pem"
|
d.private_key_path = File.dirname(__FILE__) + "/chubbies.private.pem"
|
||||||
d.public_key_path = File.dirname(__FILE__) + "/chubbies.public.pem"
|
d.public_key_path = File.dirname(__FILE__) + "/chubbies.public.pem"
|
||||||
d.test_mode = true
|
d.test_mode = true
|
||||||
d.application_url = "http://localhost:9292"
|
d.application_base_url = "localhost:9292/"
|
||||||
|
|
||||||
d.manifest_field(:name, "Chubbies")
|
d.manifest_field(:name, "Chubbies")
|
||||||
d.manifest_field(:description, "The best way to chub.")
|
d.manifest_field(:description, "The best way to chub.")
|
||||||
d.manifest_field(:homepage_url, "http://localhost:9292")
|
|
||||||
d.manifest_field(:icon_url, "#")
|
d.manifest_field(:icon_url, "#")
|
||||||
|
|
||||||
d.manifest_field(:permissions_overview, "Chubbi.es wants to post photos to your stream.")
|
d.manifest_field(:permissions_overview, "Chubbi.es wants to post photos to your stream.")
|
||||||
|
|
|
||||||
|
|
@ -19,13 +19,13 @@ describe AuthorizationsController do
|
||||||
@time = Time.now
|
@time = Time.now
|
||||||
Time.stub(:now).and_return(@time)
|
Time.stub(:now).and_return(@time)
|
||||||
@nonce = 'asdfsfasf'
|
@nonce = 'asdfsfasf'
|
||||||
@signed_string = ["http://chubbi.es",'http://pod.pod',"#{Time.now.to_i}", @nonce].join(';')
|
@signed_string = ["http://chubbi.es/",'http://pod.pod',"#{Time.now.to_i}", @nonce].join(';')
|
||||||
@signature = @private_key.sign(OpenSSL::Digest::SHA256.new, @signed_string)
|
@signature = @private_key.sign(OpenSSL::Digest::SHA256.new, @signed_string)
|
||||||
|
|
||||||
@manifest = {
|
@manifest = {
|
||||||
"name" => "Chubbies",
|
"name" => "Chubbies",
|
||||||
"description" => "The best way to chub.",
|
"description" => "The best way to chub.",
|
||||||
"homepage_url" => "http://chubbi.es",
|
"application_base_url" => "http://chubbi.es/",
|
||||||
"icon_url" => "#",
|
"icon_url" => "#",
|
||||||
"permissions_overview" => "I will use the permissions this way!",
|
"permissions_overview" => "I will use the permissions this way!",
|
||||||
}
|
}
|
||||||
|
|
@ -46,14 +46,14 @@ describe AuthorizationsController do
|
||||||
manifest = {
|
manifest = {
|
||||||
"name" => "Chubbies",
|
"name" => "Chubbies",
|
||||||
"description" => "The best way to chub.",
|
"description" => "The best way to chub.",
|
||||||
"homepage_url" => url,
|
"application_base_url" => url,
|
||||||
"icon_url" => "#",
|
"icon_url" => "#",
|
||||||
"permissions_overview" => "I will use the permissions this way!",
|
"permissions_overview" => "I will use the permissions this way!",
|
||||||
}
|
}
|
||||||
|
|
||||||
packaged_manifest = {:public_key => @public_key.export, :jwt => JWT.encode(manifest, @private_key, "RS256")}.to_json
|
packaged_manifest = {:public_key => @public_key.export, :jwt => JWT.encode(manifest, @private_key, "RS256")}.to_json
|
||||||
|
|
||||||
stub_request(:get, "#{url}/manifest.json").
|
stub_request(:get, "#{url}manifest.json").
|
||||||
to_return(:status => 200, :body => packaged_manifest, :headers => {})
|
to_return(:status => 200, :body => packaged_manifest, :headers => {})
|
||||||
|
|
||||||
@signed_string = [url,'http://pod.pod',"#{Time.now.to_i}", @nonce].join(';')
|
@signed_string = [url,'http://pod.pod',"#{Time.now.to_i}", @nonce].join(';')
|
||||||
|
|
@ -62,21 +62,21 @@ describe AuthorizationsController do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'renders something for chubbies ' do
|
it 'renders something for chubbies ' do
|
||||||
prepare_manifest("http://chubbi.es")
|
prepare_manifest("http://chubbi.es/")
|
||||||
@controller.stub!(:verify).and_return('ok')
|
@controller.stub!(:verify).and_return('ok')
|
||||||
post :token, @params_hash
|
post :token, @params_hash
|
||||||
response.body.blank?.should be_false
|
response.body.blank?.should be_false
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'renders something for cubbies ' do
|
it 'renders something for cubbies ' do
|
||||||
prepare_manifest("http://cubbi.es")
|
prepare_manifest("http://cubbi.es/")
|
||||||
@controller.stub!(:verify).and_return('ok')
|
@controller.stub!(:verify).and_return('ok')
|
||||||
post :token, @params_hash
|
post :token, @params_hash
|
||||||
response.body.blank?.should be_false
|
response.body.blank?.should be_false
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'renders something for localhost' do
|
it 'renders something for localhost' do
|
||||||
prepare_manifest("http://localhost:3423")
|
prepare_manifest("http://localhost:3423/")
|
||||||
@controller.stub!(:verify).and_return('ok')
|
@controller.stub!(:verify).and_return('ok')
|
||||||
post :token, @params_hash
|
post :token, @params_hash
|
||||||
response.body.blank?.should be_false
|
response.body.blank?.should be_false
|
||||||
|
|
@ -178,7 +178,7 @@ describe AuthorizationsController do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'checks consistency of app_url' do
|
it 'checks consistency of app_url' do
|
||||||
@controller.verify(@signed_string, @sig, @public_key, @manifest.merge({"homepage_url" => "http://badsite.com"})).should == "the app url in the manifest does not match the url passed in the parameters"
|
@controller.verify(@signed_string, @sig, @public_key, @manifest.merge({"application_base_url" => "http://badsite.com/"})).should == "the app url in the manifest does not match the url passed in the parameters"
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'checks key size' do
|
it 'checks key size' do
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,7 @@ end
|
||||||
|
|
||||||
Factory.define(:app, :class => OAuth2::Provider.client_class) do |a|
|
Factory.define(:app, :class => OAuth2::Provider.client_class) do |a|
|
||||||
a.sequence(:name) { |token| "Chubbies#{token}" }
|
a.sequence(:name) { |token| "Chubbies#{token}" }
|
||||||
a.sequence(:homepage_url) { |token| "http://chubbi#{token}.es/" }
|
a.sequence(:application_base_url) { |token| "http://chubbi#{token}.es/" }
|
||||||
|
|
||||||
a.description "The best way to chub on the net."
|
a.description "The best way to chub on the net."
|
||||||
a.icon_url "/images/chubbies48.png"
|
a.icon_url "/images/chubbies48.png"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue