Skip to content

Commit

Permalink
Revert "Renamed Application#redirect_uri in redirect_uris"
Browse files Browse the repository at this point in the history
This reverts commit fa8e734.

For simpler upgrade from previous doorkeeper versions, as @corny
suggested.
  • Loading branch information
tute committed Jan 9, 2014
1 parent 2e46b91 commit bcc08cc
Show file tree
Hide file tree
Showing 25 changed files with 68 additions and 74 deletions.
4 changes: 2 additions & 2 deletions app/controllers/doorkeeper/applications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions app/views/doorkeeper/applications/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
</div>

<div class="clearfix">
<%= f.label :redirect_uris %>
<%= f.label :redirect_uri %>
<div class="input">
<%= f.text_area :redirect_uris %>
<%= errors_for application, :redirect_uris %>
<%= f.text_area :redirect_uri %>
<%= errors_for application, :redirect_uri %>
<span class="help-inline">Please use one line per URI.</span>
<% if Doorkeeper.configuration.test_redirect_uri %>
<span class="help-inline">Use <%= Doorkeeper.configuration.test_redirect_uri %> for local tests</span>
Expand Down
2 changes: 1 addition & 1 deletion app/views/doorkeeper/applications/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ input[type=submit] {
<% @applications.each do |application| %>
<tr id="application_<%= application.id %>">
<td><%= link_to application.name, [:oauth, application] %></td>
<td><%= application.redirect_uris %></td>
<td><%= application.redirect_uri %></td>
<td><%= link_to 'Edit', edit_oauth_application_path(application) %></td>
<td><%= render 'delete_form', application: application %></td>
</tr>
Expand Down
4 changes: 2 additions & 2 deletions app/views/doorkeeper/applications/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div class="span10">
<h4>Callback urls:</h4>
<p id="callback_url">
<% @application.redirect_uris.split.each do |uri| %><code><%= uri %></code> <% end %>
<% @application.redirect_uri.split.each do |uri| %><code><%= uri %></code> <% end %>
</p>

<h4>Application Id:</h4>
Expand All @@ -17,7 +17,7 @@
<p><code id="secret"><%= @application.secret %></code></p>

<h4>Link to authorization code:</h4>
<p><%= link_to 'Authorize', oauth_authorization_path(:client_id => @application.uid, :redirect_uri => @application.redirect_uris.split.first, :response_type => 'code' ) %></p>
<p><%= link_to 'Authorize', oauth_authorization_path(:client_id => @application.uid, :redirect_uri => @application.redirect_uri, :response_type => 'code' ) %></p>
</div>

<div class="span6">
Expand Down
6 changes: 3 additions & 3 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Expand All @@ -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.'
Expand All @@ -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.'
Expand Down
6 changes: 3 additions & 3 deletions lib/doorkeeper/models/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions lib/doorkeeper/models/mongo_mapper/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
2 changes: 1 addition & 1 deletion lib/doorkeeper/models/mongoid2/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/doorkeeper/models/mongoid3/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 })

Expand Down
2 changes: 1 addition & 1 deletion lib/doorkeeper/oauth/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/doorkeeper/oauth/pre_authorization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions lib/generators/doorkeeper/templates/migration.rb
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/controllers/applications_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions spec/controllers/authorizations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ 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
expect(response).to be_redirect
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
Expand All @@ -56,15 +56,15 @@ 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
expect(response).to be_redirect
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
Expand All @@ -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
Expand All @@ -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
Expand Down

This file was deleted.

16 changes: 8 additions & 8 deletions spec/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/application.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion spec/lib/oauth/authorization_code_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/oauth/pre_authorization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
6 changes: 3 additions & 3 deletions spec/models/doorkeeper/application_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/endpoints/token_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down
2 changes: 1 addition & 1 deletion spec/requests/flows/authorization_code_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion spec/support/helpers/authorization_request_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions spec/support/helpers/url_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)}"
Expand All @@ -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],
Expand Down
Loading

0 comments on commit bcc08cc

Please sign in to comment.