Skip to content
Extraits de code Groupes Projets
Valider a9e40a3d rédigé par Eugen Rochko's avatar Eugen Rochko
Parcourir les fichiers

Adding OAuth access scopes, fixing OAuth authorization UI, adding rate limiting

to the API
parent 17122df8
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
class Rack::Attack class Rack::Attack
throttle('get-req/ip', limit: 300, period: 5.minutes) do |req| # Rate limits for the API
req.ip if req.get? throttle('api', limit: 150, period: 5.minutes) do |req|
req.ip if req.path.match(/\A\/api\//)
end end
throttle('post-req/ip', limit: 100, period: 5.minutes) do |req| self.throttled_response = lambda do |env|
req.ip if req.post? now = Time.now.utc
match_data = env['rack.attack.match_data']
headers = {
'X-RateLimit-Limit' => match_data[:limit].to_s,
'X-RateLimit-Remaining' => '0',
'X-RateLimit-Reset' => (now + (match_data[:period] - now.to_i % match_data[:period])).to_s
}
[429, headers, [{ error: 'Throttled' }.to_json]]
end end
end end
...@@ -15,6 +15,10 @@ en: ...@@ -15,6 +15,10 @@ en:
secured_uri: 'must be an HTTPS/SSL URI.' secured_uri: 'must be an HTTPS/SSL URI.'
doorkeeper: doorkeeper:
scopes:
read: read your account's data
write: post on your behalf
follow: follow, block, unblock and unfollow accounts
applications: applications:
confirmations: confirmations:
destroy: 'Are you sure?' destroy: 'Are you sure?'
......
...@@ -7,7 +7,9 @@ Rails.application.routes.draw do ...@@ -7,7 +7,9 @@ Rails.application.routes.draw do
mount Sidekiq::Web => '/sidekiq' mount Sidekiq::Web => '/sidekiq'
end end
use_doorkeeper use_doorkeeper do
controllers authorizations: 'oauth/authorizations'
end
get '.well-known/host-meta', to: 'xrd#host_meta', as: :host_meta get '.well-known/host-meta', to: 'xrd#host_meta', as: :host_meta
get '.well-known/webfinger', to: 'xrd#webfinger', as: :webfinger get '.well-known/webfinger', to: 'xrd#webfinger', as: :webfinger
......
web_app = Doorkeeper::Application.new(name: 'Web', superapp: true, redirect_uri: Doorkeeper.configuration.native_redirect_uri) web_app = Doorkeeper::Application.new(name: 'Web', superapp: true, redirect_uri: Doorkeeper.configuration.native_redirect_uri, scopes: 'read write follow')
web_app.save! web_app.save!
...@@ -2,9 +2,7 @@ namespace :mastodon do ...@@ -2,9 +2,7 @@ namespace :mastodon do
namespace :media do namespace :media do
desc 'Removes media attachments that have not been assigned to any status for longer than a day' desc 'Removes media attachments that have not been assigned to any status for longer than a day'
task clear: :environment do task clear: :environment do
MediaAttachment.where(status_id: nil).where('created_at < ?', 1.day.ago).find_each do |m| MediaAttachment.where(status_id: nil).where('created_at < ?', 1.day.ago).find_each(&:destroy)
m.destroy
end
end end
end end
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter