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
9 changes: 5 additions & 4 deletions app/controllers/admin/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def new
nextauth_url = ENV['NEXTAUTH_URL'].presence || request.base_url
query = {
client_id: ENV['IDENTITY_CLIENT_ID'],
redirect_uri: File.join(nextauth_url, 'admin/callback'),
redirect_uri: join_url(nextauth_url, 'admin/callback'),
response_type: 'code',
scope: 'basic_info',
state: state
Expand All @@ -31,16 +31,17 @@ def callback
code: code,
client_id: ENV['IDENTITY_CLIENT_ID'],
client_secret: ENV['IDENTITY_CLIENT_SECRET'],
redirect_uri: File.join(ENV['NEXTAUTH_URL'].presence || request.base_url, 'admin/callback'),
redirect_uri: join_url(ENV['NEXTAUTH_URL'].presence || request.base_url, 'admin/callback'),
grant_type: 'authorization_code'
}

http = Net::HTTP.new(token_uri.host, token_uri.port)
http.use_ssl = token_uri.scheme == 'https'
http.open_timeout = 3
http.read_timeout = 5
req = Net::HTTP::Post.new(token_uri, { 'Content-Type' => 'application/json' })
req.body = body.to_json
req = Net::HTTP::Post.new(token_uri)
req['Content-Type'] = 'application/x-www-form-urlencoded'
req.body = URI.encode_www_form(body)
begin
res = http.request(req)
rescue => e
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/identity_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ def callback
http.use_ssl = token_uri.scheme == 'https'
http.open_timeout = 3
http.read_timeout = 5
req = Net::HTTP::Post.new(token_uri, { 'Content-Type' => 'application/json' })
req.body = body.to_json
req = Net::HTTP::Post.new(token_uri)
req['Content-Type'] = 'application/x-www-form-urlencoded'
req.body = URI.encode_www_form(body)
begin
res = http.request(req)
rescue => e
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/popup/authorize_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,9 @@ def exchange_oauth_code_for_user_data(code)
http.use_ssl = token_uri.scheme == 'https'
http.open_timeout = 3
http.read_timeout = 5
req = Net::HTTP::Post.new(token_uri, { 'Content-Type' => 'application/json' })
req.body = body.to_json
req = Net::HTTP::Post.new(token_uri)
req['Content-Type'] = 'application/x-www-form-urlencoded'
req.body = URI.encode_www_form(body)

res = http.request(req)
raise "Token exchange failed: #{res.code}" unless res.is_a?(Net::HTTPSuccess)
Expand Down