Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions lib/controllers/authorize_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ class AuthorizeController < BaseController

session[:state] = SecureRandom.hex(32)

redirect_uri = Authorize.construct_redirect_uri(request.referrer)
parameters = %Q(?scope=user:email&client_id=#{ENV.fetch('GITHUB_BASIC_CLIENT_ID')}&redirect_uri=#{redirect_uri}&state=#{session[:state]})

redirect URI.join(GITHUB_OAUTH_AUTHORIZE_URL, parameters)
# redirect_uri is already percent-encoded, so build the query by hand to avoid double-encoding.
query = [
"scope=user:email%20read:org",
"client_id=#{ENV.fetch('GITHUB_BASIC_CLIENT_ID')}",
"redirect_uri=#{Authorize.construct_redirect_uri(request.referrer)}",
"state=#{session[:state]}",
].join("&")

redirect URI.join(GITHUB_OAUTH_AUTHORIZE_URL, "?#{query}")
end

get '/callback*' do
Expand Down
10 changes: 10 additions & 0 deletions test/integration/app_not_logged_in_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,16 @@ def test_authorize_without_referer
assert_equal 400, last_response.status
end

def test_authorize_requests_read_org_scope
# Without read:org the membership check 302s and starkast? is always false.
ClimateControl.modify(GITHUB_BASIC_CLIENT_ID: "fake_client_id") do
header "Referer", "http://fake/referer"
get "/authorize"
end

assert_includes last_response["Location"], "read:org"
end

def test_authorize_callback
access_token = "fake_access_token"
user = "fake_user"
Expand Down
Loading