forked from glitch-soc/mastodon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fedilinks: Add well-known protocol handler
- Loading branch information
Showing
3 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# frozen_string_literal: true | ||
|
||
module WellKnown | ||
class ProtocolHandlerController < ActionController::Base # rubocop:disable Rails/ApplicationController | ||
|
||
before_action :set_target | ||
before_action :target_acceptable? | ||
|
||
rescue_from ActionController::ParameterMissing, with: :bad_request | ||
|
||
def show | ||
redirect_to authorize_interaction_path(uri: @target.sub("web+ap", "https")) | ||
end | ||
|
||
private | ||
|
||
def set_target | ||
@target = target_param | ||
end | ||
|
||
# NOTE: supports "probing" | ||
def target_acceptable? | ||
# FIXME: this should be web+ap: but doing it this way avoids issues in | ||
# the short term... revisit this once web+ap:foo... is being used in | ||
# addition to web+ap://example/... | ||
return if @target.starts_with? "web+ap://" | ||
not_found | ||
end | ||
|
||
def target_param | ||
params.require(:target) | ||
end | ||
|
||
def bad_request | ||
expires_in(3.minutes, public: true) | ||
head 400 | ||
end | ||
|
||
def not_found | ||
expires_in(3.minutes, public: true) | ||
head 404 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters