1
0

oauth_metadata_presenter.rb 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # frozen_string_literal: true
  2. class OauthMetadataPresenter < ActiveModelSerializers::Model
  3. include RoutingHelper
  4. attributes :issuer, :authorization_endpoint, :token_endpoint,
  5. :revocation_endpoint, :scopes_supported,
  6. :response_types_supported, :response_modes_supported,
  7. :grant_types_supported, :token_endpoint_auth_methods_supported,
  8. :code_challenge_methods_supported,
  9. :service_documentation, :app_registration_endpoint
  10. def issuer
  11. root_url
  12. end
  13. def service_documentation
  14. 'https://docs.joinmastodon.org/'
  15. end
  16. def authorization_endpoint
  17. oauth_authorization_url
  18. end
  19. def token_endpoint
  20. oauth_token_url
  21. end
  22. def userinfo_endpoint
  23. oauth_userinfo_url
  24. end
  25. # As the api_v1_apps route doesn't technically conform to the specification
  26. # for OAuth 2.0 Dynamic Client Registration defined in RFC 7591 we use a
  27. # non-standard property for now to indicate the mastodon specific registration
  28. # endpoint. See: https://datatracker.ietf.org/doc/html/rfc7591
  29. def app_registration_endpoint
  30. api_v1_apps_url
  31. end
  32. def revocation_endpoint
  33. oauth_revoke_url
  34. end
  35. def scopes_supported
  36. doorkeeper.scopes
  37. end
  38. def response_types_supported
  39. doorkeeper.authorization_response_types
  40. end
  41. def response_modes_supported
  42. doorkeeper.authorization_response_flows.flat_map(&:response_mode_matches).uniq
  43. end
  44. def grant_types_supported
  45. grant_types_supported = doorkeeper.grant_flows.dup
  46. grant_types_supported << 'refresh_token' if doorkeeper.refresh_token_enabled?
  47. grant_types_supported
  48. end
  49. def token_endpoint_auth_methods_supported
  50. %w(client_secret_basic client_secret_post)
  51. end
  52. def code_challenge_methods_supported
  53. %w(S256)
  54. end
  55. private
  56. def doorkeeper
  57. @doorkeeper ||= Doorkeeper.configuration
  58. end
  59. end