Skip to content

Commit

Permalink
Refactor to split ApplicationSerializer into CredentialApplicationSer…
Browse files Browse the repository at this point in the history
…ializer for /api/v1/apps and ApplicationSerializer for /api/v1/apps/verify_credentials
  • Loading branch information
ThisIsMissEm committed May 16, 2024
1 parent 150b2fa commit 1b04819
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/v1/apps/credentials_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ class Api::V1::Apps::CredentialsController < Api::BaseController
def show
return doorkeeper_render_error unless valid_doorkeeper_token?

render json: doorkeeper_token.application, serializer: REST::ApplicationSerializer, fields: %i(name website vapid_key client_id scopes redirect_uris)
render json: doorkeeper_token.application, serializer: REST::ApplicationSerializer
end
end
2 changes: 1 addition & 1 deletion app/controllers/api/v1/apps_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Api::V1::AppsController < Api::BaseController

def create
@app = Doorkeeper::Application.create!(application_options)
render json: @app, serializer: REST::ApplicationSerializer
render json: @app, serializer: REST::CredentialApplicationSerializer
end

private
Expand Down
6 changes: 1 addition & 5 deletions app/serializers/rest/application_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class REST::ApplicationSerializer < ActiveModel::Serializer
attributes :id, :name, :website, :scopes, :redirect_uris,
:client_id, :client_secret
:client_id

# NOTE: Deprecated in 4.3.0, needs to be removed in 5.0.0
attribute :vapid_key
Expand All @@ -18,10 +18,6 @@ def client_id
object.uid
end

def client_secret
object.secret
end

def website
object.website.presence
end
Expand Down
9 changes: 9 additions & 0 deletions app/serializers/rest/credential_application_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

class REST::CredentialApplicationSerializer < REST::ApplicationSerializer
attributes :client_secret

def client_secret
object.secret
end
end
6 changes: 1 addition & 5 deletions spec/requests/api/v1/apps/credentials_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@

expect(response).to have_http_status(200)

expect(body_as_json).to_not match(
a_hash_including(
client_secret: token.application.secret
)
)
expect(body_as_json[:client_secret]).to_not be_present
end
end

Expand Down

0 comments on commit 1b04819

Please sign in to comment.