Skip to content

Commit a05b1c7

Browse files
author
Justin Bull
committed
Allow Application#redirect_uri= to handle array of URIs
1 parent 4ad9458 commit a05b1c7

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/doorkeeper/models/application_mixin.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ def by_uid(uid)
4343
end
4444
end
4545

46+
##
47+
# Set an application's valid redirect URIs.
48+
#
49+
# @param uris [String, Array] Newline-separated string or array the URI(s)
50+
#
51+
# @return [String] The redirect URI(s) seperated by newlines.
52+
def redirect_uri=(uris)
53+
super(uris.is_a?(Array) ? uris.join("\n") : uris)
54+
end
55+
4656
private
4757

4858
def has_scopes?

spec/models/doorkeeper/application_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,21 @@ module Doorkeeper
136136
end
137137
end
138138

139+
describe "#redirect_uri=" do
140+
context "when array of valid redirect_uris" do
141+
it "should join by newline" do
142+
new_application.redirect_uri = ['http://localhost/callback1', 'http://localhost/callback2']
143+
expect(new_application.redirect_uri).to eq("http://localhost/callback1\nhttp://localhost/callback2")
144+
end
145+
end
146+
context "when string of valid redirect_uris" do
147+
it "should store as-is" do
148+
new_application.redirect_uri = "http://localhost/callback1\nhttp://localhost/callback2"
149+
expect(new_application.redirect_uri).to eq("http://localhost/callback1\nhttp://localhost/callback2")
150+
end
151+
end
152+
end
153+
139154
describe :authorized_for do
140155
let(:resource_owner) { double(:resource_owner, id: 10) }
141156

0 commit comments

Comments
 (0)