mirror of
https://github.com/manyfold3d/manyfold.git
synced 2026-10-22 03:32:18 -05:00
49 lines
1.3 KiB
Ruby
49 lines
1.3 KiB
Ruby
# Manyfold's own controller for manually managing and revoking access tokens
|
|
|
|
class DoorkeeperAccessTokensController < ApplicationController
|
|
before_action :get_application
|
|
before_action :get_token, except: [:new, :create]
|
|
|
|
def show
|
|
@plaintext_token = flash[:plaintext_token]
|
|
raise ActiveRecord::RecordNotFound unless @plaintext_token
|
|
end
|
|
|
|
def new
|
|
@token = Doorkeeper::AccessToken.build
|
|
end
|
|
|
|
def create
|
|
token_params = params.expect(doorkeeper_access_token: [:expires_in, scopes: []])
|
|
@token = @application.access_tokens.create(
|
|
expires_in: token_params[:expires_in].to_i,
|
|
resource_owner_id: @application.owner.id,
|
|
scopes: token_params[:scopes].compact_blank.join(" ")
|
|
)
|
|
if @token&.valid?
|
|
flash[:plaintext_token] = @token.plaintext_token
|
|
redirect_to [@application, @token], notice: t(".success")
|
|
else
|
|
flash.now[:alert] = t(".failed")
|
|
render :new, status: :unprocessable_content
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
@token.revoke
|
|
redirect_to @application, notice: t(".success")
|
|
end
|
|
|
|
private
|
|
|
|
def get_application
|
|
@application = policy_scope(Doorkeeper::Application).find(params[:doorkeeper_application_id])
|
|
authorize @application
|
|
end
|
|
|
|
def get_token
|
|
@token = @application.access_tokens.find(params[:id])
|
|
authorize @token
|
|
end
|
|
end
|