diff --git a/app/controllers/doorkeeper/applications_controller.rb b/app/controllers/doorkeeper/applications_controller.rb index 2ddeefa97..19d3334b4 100644 --- a/app/controllers/doorkeeper/applications_controller.rb +++ b/app/controllers/doorkeeper/applications_controller.rb @@ -51,9 +51,9 @@ def set_application def application_params if params.respond_to?(:permit) - params.require(:application).permit(:name, :redirect_uris) + params.require(:application).permit(:name, :redirect_uri) else - params[:application].slice(:name, :redirect_uris) rescue nil + params[:application].slice(:name, :redirect_uri) rescue nil end end end diff --git a/app/views/doorkeeper/applications/_form.html.erb b/app/views/doorkeeper/applications/_form.html.erb index cc930afbe..9fe23e2cc 100644 --- a/app/views/doorkeeper/applications/_form.html.erb +++ b/app/views/doorkeeper/applications/_form.html.erb @@ -13,10 +13,10 @@
- <%= f.label :redirect_uris %> + <%= f.label :redirect_uri %>
- <%= f.text_area :redirect_uris %> - <%= errors_for application, :redirect_uris %> + <%= f.text_area :redirect_uri %> + <%= errors_for application, :redirect_uri %> Please use one line per URI. <% if Doorkeeper.configuration.test_redirect_uri %> Use <%= Doorkeeper.configuration.test_redirect_uri %> for local tests diff --git a/app/views/doorkeeper/applications/index.html.erb b/app/views/doorkeeper/applications/index.html.erb index c1b183980..53226c013 100644 --- a/app/views/doorkeeper/applications/index.html.erb +++ b/app/views/doorkeeper/applications/index.html.erb @@ -23,7 +23,7 @@ input[type=submit] { <% @applications.each do |application| %> <%= link_to application.name, [:oauth, application] %> - <%= application.redirect_uris %> + <%= application.redirect_uri %> <%= link_to 'Edit', edit_oauth_application_path(application) %> <%= render 'delete_form', application: application %> diff --git a/app/views/doorkeeper/applications/show.html.erb b/app/views/doorkeeper/applications/show.html.erb index 7f4913bdb..9869424e4 100644 --- a/app/views/doorkeeper/applications/show.html.erb +++ b/app/views/doorkeeper/applications/show.html.erb @@ -7,7 +7,7 @@

Callback urls:

- <% @application.redirect_uris.split.each do |uri| %><%= uri %> <% end %> + <% @application.redirect_uri.split.each do |uri| %><%= uri %> <% end %>

Application Id:

@@ -17,7 +17,7 @@

<%= @application.secret %>

Link to authorization code:

-

<%= link_to 'Authorize', oauth_authorization_path(:client_id => @application.uid, :redirect_uri => @application.redirect_uris.split.first, :response_type => 'code' ) %>

+

<%= link_to 'Authorize', oauth_authorization_path(:client_id => @application.uid, :redirect_uri => @application.redirect_uri, :response_type => 'code' ) %>

diff --git a/config/locales/en.yml b/config/locales/en.yml index d7b64e8e0..c44bdb414 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -4,7 +4,7 @@ en: models: application: attributes: - redirect_uris: + redirect_uri: fragment_present: 'cannot contain a fragment.' has_query_parameter: 'cannot contain a query parameter.' invalid_uri: 'must be a valid URI.' @@ -14,7 +14,7 @@ en: models: application: attributes: - redirect_uris: + redirect_uri: fragment_present: 'cannot contain a fragment.' has_query_parameter: 'cannot contain a query parameter.' invalid_uri: 'must be a valid URI.' @@ -24,7 +24,7 @@ en: models: application: attributes: - redirect_uris: + redirect_uri: fragment_present: 'cannot contain a fragment.' has_query_parameter: 'cannot contain a query parameter.' invalid_uri: 'must be a valid URI.' diff --git a/lib/doorkeeper/models/application.rb b/lib/doorkeeper/models/application.rb index e9f7ee5a5..a95cd44c2 100644 --- a/lib/doorkeeper/models/application.rb +++ b/lib/doorkeeper/models/application.rb @@ -5,14 +5,14 @@ class Application has_many :access_grants, :dependent => :destroy, :class_name => "Doorkeeper::AccessGrant" has_many :access_tokens, :dependent => :destroy, :class_name => "Doorkeeper::AccessToken" - validates :name, :secret, :uid, :redirect_uris, :presence => true + validates :name, :secret, :uid, :redirect_uri, :presence => true validates :uid, :uniqueness => true - validates :redirect_uris, :redirect_uri => true + validates :redirect_uri, :redirect_uri => true before_validation :generate_uid, :generate_secret, :on => :create if ::Rails.version.to_i < 4 || defined?(ProtectedAttributes) - attr_accessible :name, :redirect_uris + attr_accessible :name, :redirect_uri end def self.model_name diff --git a/lib/doorkeeper/models/mongo_mapper/application.rb b/lib/doorkeeper/models/mongo_mapper/application.rb index 278bf90c6..05cca714a 100644 --- a/lib/doorkeeper/models/mongo_mapper/application.rb +++ b/lib/doorkeeper/models/mongo_mapper/application.rb @@ -8,11 +8,11 @@ class Application many :authorized_tokens, :class_name => "Doorkeeper::AccessToken" - key :name, String - key :uid, String - key :secret, String - key :redirect_uris, String - key :scopes, String + key :name, String + key :uid, String + key :secret, String + key :redirect_uri, String + key :scopes, String def scopes=(value) write_attribute :scopes, value if value.present? diff --git a/lib/doorkeeper/models/mongoid2/application.rb b/lib/doorkeeper/models/mongoid2/application.rb index 8d7a6323f..9843c7158 100644 --- a/lib/doorkeeper/models/mongoid2/application.rb +++ b/lib/doorkeeper/models/mongoid2/application.rb @@ -8,7 +8,7 @@ class Application field :name, :type => String field :uid, :type => String field :secret, :type => String - field :redirect_uris, :type => String + field :redirect_uri, :type => String index :uid, :unique => true diff --git a/lib/doorkeeper/models/mongoid3/application.rb b/lib/doorkeeper/models/mongoid3/application.rb index 993b6dcba..7a0b3f527 100644 --- a/lib/doorkeeper/models/mongoid3/application.rb +++ b/lib/doorkeeper/models/mongoid3/application.rb @@ -8,7 +8,7 @@ class Application field :name, :type => String field :uid, :type => String field :secret, :type => String - field :redirect_uris, :type => String + field :redirect_uri, :type => String index({ uid: 1 }, { unique: true }) diff --git a/lib/doorkeeper/oauth/client.rb b/lib/doorkeeper/oauth/client.rb index a38f78159..2f8289f06 100644 --- a/lib/doorkeeper/oauth/client.rb +++ b/lib/doorkeeper/oauth/client.rb @@ -17,7 +17,7 @@ def self.authenticate(credentials, method = Doorkeeper::Application.method(:auth end end - delegate :id, :name, :uid, :redirect_uris, :to => :@application + delegate :id, :name, :uid, :redirect_uri, :to => :@application def initialize(application) @application = application diff --git a/lib/doorkeeper/oauth/pre_authorization.rb b/lib/doorkeeper/oauth/pre_authorization.rb index 6a281d547..3b03227a6 100644 --- a/lib/doorkeeper/oauth/pre_authorization.rb +++ b/lib/doorkeeper/oauth/pre_authorization.rb @@ -55,7 +55,7 @@ def validate_scopes def validate_redirect_uri return false unless redirect_uri.present? Helpers::URIChecker.test_uri?(redirect_uri) || - Helpers::URIChecker.valid_for_authorization?(redirect_uri, client.redirect_uris) + Helpers::URIChecker.valid_for_authorization?(redirect_uri, client.redirect_uri) end end end diff --git a/lib/generators/doorkeeper/templates/migration.rb b/lib/generators/doorkeeper/templates/migration.rb index 72ba2e927..60edd8640 100644 --- a/lib/generators/doorkeeper/templates/migration.rb +++ b/lib/generators/doorkeeper/templates/migration.rb @@ -1,10 +1,10 @@ class CreateDoorkeeperTables < ActiveRecord::Migration def change create_table :oauth_applications do |t| - t.string :name, :null => false - t.string :uid, :null => false - t.string :secret, :null => false - t.text :redirect_uris, :null => false + t.string :name, :null => false + t.string :uid, :null => false + t.string :secret, :null => false + t.text :redirect_uri, :null => false t.timestamps end @@ -15,7 +15,7 @@ def change t.integer :application_id, :null => false t.string :token, :null => false t.integer :expires_in, :null => false - t.string :redirect_uri, :null => false, :limit => 2048 + t.text :redirect_uri, :null => false t.datetime :created_at, :null => false t.datetime :revoked_at t.string :scopes diff --git a/spec/controllers/applications_controller_spec.rb b/spec/controllers/applications_controller_spec.rb index 3d5fa6d69..8fb30c536 100644 --- a/spec/controllers/applications_controller_spec.rb +++ b/spec/controllers/applications_controller_spec.rb @@ -18,7 +18,7 @@ module Doorkeeper expect do post :create, application: { name: 'Example', - redirect_uris: 'http://example.com' } + redirect_uri: 'http://example.com' } end.to_not change { Doorkeeper::Application.count } end end @@ -32,7 +32,7 @@ module Doorkeeper expect do post :create, application: { name: 'Example', - redirect_uris: 'http://example.com' } + redirect_uri: 'http://example.com' } end.to change { Doorkeeper::Application.count }.by(1) expect(response).to be_redirect end @@ -50,7 +50,7 @@ module Doorkeeper application = FactoryGirl.create(:application) put :update, id: application.id, application: { name: 'Example', - redirect_uris: 'http://example.com' } + redirect_uri: 'http://example.com' } application.reload.name.should eq 'Example' end end diff --git a/spec/controllers/authorizations_controller_spec.rb b/spec/controllers/authorizations_controller_spec.rb index 62520cc71..61155c49c 100644 --- a/spec/controllers/authorizations_controller_spec.rb +++ b/spec/controllers/authorizations_controller_spec.rb @@ -21,7 +21,7 @@ def translated_error_message(key) describe "POST #create" do before do - post :create, :client_id => client.uid, :response_type => "token", :redirect_uri => client.redirect_uris + post :create, :client_id => client.uid, :response_type => "token", :redirect_uri => client.redirect_uri end it "redirects after authorization" do @@ -29,7 +29,7 @@ def translated_error_message(key) end it "redirects to client redirect uri" do - expect(response.location).to match(%r[^#{client.redirect_uris}]) + expect(response.location).to match(%r[^#{client.redirect_uri}]) end it "includes access token in fragment" do @@ -56,7 +56,7 @@ def translated_error_message(key) describe "POST #create with errors" do before do default_scopes_exist :public - post :create, :client_id => client.uid, :response_type => "token", :scope => "invalid", :redirect_uri => client.redirect_uris + post :create, :client_id => client.uid, :response_type => "token", :scope => "invalid", :redirect_uri => client.redirect_uri end it "redirects after authorization" do @@ -64,7 +64,7 @@ def translated_error_message(key) end it "redirects to client redirect uri" do - expect(response.location).to match(%r[^#{client.redirect_uris}]) + expect(response.location).to match(%r[^#{client.redirect_uri}]) end it "does not include access token in fragment" do @@ -90,7 +90,7 @@ def translated_error_message(key) describe "GET #new" do before do - get :new, :client_id => client.uid, :response_type => "token", :redirect_uri => client.redirect_uris + get :new, :client_id => client.uid, :response_type => "token", :redirect_uri => client.redirect_uri end it 'renders new template' do @@ -103,12 +103,12 @@ def translated_error_message(key) Doorkeeper.configuration.stub(:skip_authorization => proc do true end) - get :new, :client_id => client.uid, :response_type => "token", :redirect_uri => client.redirect_uris + get :new, :client_id => client.uid, :response_type => "token", :redirect_uri => client.redirect_uri end it "should redirect immediately" do response.should be_redirect - response.location.should =~ %r[^#{client.redirect_uris}] + response.location.should =~ %r[^#{client.redirect_uri}] end it "should issue a token" do diff --git a/spec/dummy/db/migrate/20131022151523_pluralize_redirect_uri_in_application.rb b/spec/dummy/db/migrate/20131022151523_pluralize_redirect_uri_in_application.rb deleted file mode 100644 index 80d75c63c..000000000 --- a/spec/dummy/db/migrate/20131022151523_pluralize_redirect_uri_in_application.rb +++ /dev/null @@ -1,6 +0,0 @@ -class PluralizeRedirectUriInApplication < ActiveRecord::Migration - def change - rename_column :oauth_applications, :redirect_uri, :redirect_uris - change_column :oauth_applications, :redirect_uris, :text, :null => false, :limit => nil - end -end \ No newline at end of file diff --git a/spec/dummy/db/schema.rb b/spec/dummy/db/schema.rb index 1c7a6f42a..be077297e 100644 --- a/spec/dummy/db/schema.rb +++ b/spec/dummy/db/schema.rb @@ -11,14 +11,14 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20131022151523) do +ActiveRecord::Schema.define(:version => 20130902175349) do create_table "oauth_access_grants", :force => true do |t| t.integer "resource_owner_id", :null => false t.integer "application_id", :null => false t.string "token", :null => false t.integer "expires_in", :null => false - t.string "redirect_uri", :limit => 2048, :null => false + t.text "redirect_uri", :null => false t.datetime "created_at", :null => false t.datetime "revoked_at" t.string "scopes" @@ -42,12 +42,12 @@ add_index "oauth_access_tokens", ["token"], :name => "index_oauth_access_tokens_on_token", :unique => true create_table "oauth_applications", :force => true do |t| - t.string "name", :null => false - t.string "uid", :null => false - t.string "secret", :null => false - t.text "redirect_uris", :null => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.string "name", :null => false + t.string "uid", :null => false + t.string "secret", :null => false + t.text "redirect_uri", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.integer "owner_id" t.string "owner_type" end diff --git a/spec/factories/application.rb b/spec/factories/application.rb index fca53ab07..b5dc407d8 100644 --- a/spec/factories/application.rb +++ b/spec/factories/application.rb @@ -1,6 +1,6 @@ FactoryGirl.define do factory :application, :class => Doorkeeper::Application do sequence(:name){ |n| "Application #{n}" } - redirect_uris "https://app.com/callback" + redirect_uri "https://app.com/callback" end end diff --git a/spec/lib/oauth/authorization_code_request_spec.rb b/spec/lib/oauth/authorization_code_request_spec.rb index e15dba3e3..d94f6519c 100644 --- a/spec/lib/oauth/authorization_code_request_spec.rb +++ b/spec/lib/oauth/authorization_code_request_spec.rb @@ -7,7 +7,7 @@ module Doorkeeper::OAuth let(:client) { grant.application } subject do - AuthorizationCodeRequest.new server, grant, client, :redirect_uri => client.redirect_uris + AuthorizationCodeRequest.new server, grant, client, :redirect_uri => client.redirect_uri end it 'issues a new token for the client' do diff --git a/spec/lib/oauth/pre_authorization_spec.rb b/spec/lib/oauth/pre_authorization_spec.rb index dc117862a..ba78b1329 100644 --- a/spec/lib/oauth/pre_authorization_spec.rb +++ b/spec/lib/oauth/pre_authorization_spec.rb @@ -3,7 +3,7 @@ module Doorkeeper::OAuth describe PreAuthorization do let(:server) { double :server, :default_scopes => Scopes.new, :scopes => Scopes.from_string('public') } - let(:client) { double :client, :redirect_uris => 'http://tst.com/auth' } + let(:client) { double :client, :redirect_uri => 'http://tst.com/auth' } let :attributes do { diff --git a/spec/models/doorkeeper/application_spec.rb b/spec/models/doorkeeper/application_spec.rb index 62b35b5f6..b14435837 100644 --- a/spec/models/doorkeeper/application_spec.rb +++ b/spec/models/doorkeeper/application_spec.rb @@ -69,9 +69,9 @@ module Doorkeeper new_application.should_not be_valid end - it 'is invalid without redirect_uris' do + it 'is invalid without redirect_uri' do new_application.save - new_application.redirect_uris = nil + new_application.redirect_uri = nil new_application.should_not be_valid end @@ -159,7 +159,7 @@ module Doorkeeper it "should fail to mass assign a new application", if: ::Rails::VERSION::MAJOR < 4 do mass_assign = { :name => 'Something', - :redirect_uris => 'http://somewhere.com/something', + :redirect_uri => 'http://somewhere.com/something', :uid => 123, :secret => 'something' } Application.create(mass_assign).uid.should_not == 123 diff --git a/spec/requests/endpoints/token_spec.rb b/spec/requests/endpoints/token_spec.rb index 36fcc66b8..f6744dc1f 100644 --- a/spec/requests/endpoints/token_spec.rb +++ b/spec/requests/endpoints/token_spec.rb @@ -14,7 +14,7 @@ end scenario 'accepts client credentials with basic auth header' do - post token_endpoint_url(:code => @authorization.token, :redirect_uri => @client.redirect_uris), + post token_endpoint_url(:code => @authorization.token, :redirect_uri => @client.redirect_uri), {} , { 'HTTP_AUTHORIZATION' => basic_auth_header_for_client(@client) } diff --git a/spec/requests/flows/authorization_code_spec.rb b/spec/requests/flows/authorization_code_spec.rb index b6da45439..cbb2c29db 100644 --- a/spec/requests/flows/authorization_code_spec.rb +++ b/spec/requests/flows/authorization_code_spec.rb @@ -22,7 +22,7 @@ end scenario 'resource owner authorizes using test url' do - @client.redirect_uris = Doorkeeper.configuration.test_redirect_uri + @client.redirect_uri = Doorkeeper.configuration.test_redirect_uri @client.save! visit authorization_endpoint_url(:client => @client) click_on "Authorize" diff --git a/spec/support/helpers/authorization_request_helper.rb b/spec/support/helpers/authorization_request_helper.rb index b1e22ee95..51952f81e 100644 --- a/spec/support/helpers/authorization_request_helper.rb +++ b/spec/support/helpers/authorization_request_helper.rb @@ -25,7 +25,7 @@ def client_should_not_be_authorized(client) end def i_should_be_on_client_callback(client) - client.redirect_uris.should == "#{current_uri.scheme}://#{current_uri.host}#{current_uri.path}" + client.redirect_uri.should == "#{current_uri.scheme}://#{current_uri.host}#{current_uri.path}" end end diff --git a/spec/support/helpers/url_helper.rb b/spec/support/helpers/url_helper.rb index cc8910f93..4adf6d1e1 100644 --- a/spec/support/helpers/url_helper.rb +++ b/spec/support/helpers/url_helper.rb @@ -4,7 +4,7 @@ def token_endpoint_url(options = {}) :code => options[:code], :client_id => options[:client_id] || (options[:client] ? options[:client].uid : nil), :client_secret => options[:client_secret] || (options[:client] ? options[:client].secret : nil), - :redirect_uri => options[:redirect_uri] || (options[:client] ? options[:client].redirect_uris : nil), + :redirect_uri => options[:redirect_uri] || (options[:client] ? options[:client].redirect_uri : nil), :grant_type => options[:grant_type] || "authorization_code", } "/oauth/token?#{build_query(parameters)}" @@ -25,7 +25,7 @@ def password_token_endpoint_url(options = {}) def authorization_endpoint_url(options = {}) parameters = { :client_id => options[:client_id] || options[:client].uid, - :redirect_uri => options[:redirect_uri] || options[:client].redirect_uris, + :redirect_uri => options[:redirect_uri] || options[:client].redirect_uri, :response_type => options[:response_type] || "code", :scope => options[:scope], :state => options[:state], diff --git a/spec/validators/redirect_uri_validator_spec.rb b/spec/validators/redirect_uri_validator_spec.rb index b47afb12e..fe4ee9b46 100644 --- a/spec/validators/redirect_uri_validator_spec.rb +++ b/spec/validators/redirect_uri_validator_spec.rb @@ -6,42 +6,42 @@ end it 'is valid when the uri is a uri' do - subject.redirect_uris = "http://example.com/callback" + subject.redirect_uri = "http://example.com/callback" subject.should be_valid end it 'accepts test redirect uri' do - subject.redirect_uris = 'urn:ietf:wg:oauth:2.0:oob' + subject.redirect_uri = 'urn:ietf:wg:oauth:2.0:oob' subject.should be_valid end it 'rejects if test uri is disabled' do RedirectUriValidator.stub :test_redirect_uri => nil - subject.redirect_uris = "urn:some:test" + subject.redirect_uri = "urn:some:test" subject.should_not be_valid end it 'is invalid when the uri is not a uri' do - subject.redirect_uris = ']' + subject.redirect_uri = ']' subject.should_not be_valid - subject.errors[:redirect_uris].first.should == "must be a valid URI." + subject.errors[:redirect_uri].first.should == "must be a valid URI." end it 'is invalid when the uri is relative' do - subject.redirect_uris = "/abcd" + subject.redirect_uri = "/abcd" subject.should_not be_valid - subject.errors[:redirect_uris].first.should == "must be an absolute URI." + subject.errors[:redirect_uri].first.should == "must be an absolute URI." end it 'is invalid when the uri has a fragment' do - subject.redirect_uris = "http://example.com/abcd#xyz" + subject.redirect_uri = "http://example.com/abcd#xyz" subject.should_not be_valid - subject.errors[:redirect_uris].first.should == "cannot contain a fragment." + subject.errors[:redirect_uri].first.should == "cannot contain a fragment." end it 'is invalid when the uri has a query parameter' do - subject.redirect_uris = "http://example.com/abcd?xyz=123" + subject.redirect_uri = "http://example.com/abcd?xyz=123" subject.should_not be_valid - subject.errors[:redirect_uris].first.should == "cannot contain a query parameter." + subject.errors[:redirect_uri].first.should == "cannot contain a query parameter." end end